-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patharrayfire.f90
More file actions
3067 lines (2694 loc) · 85.1 KB
/
Copy patharrayfire.f90
File metadata and controls
3067 lines (2694 loc) · 85.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module arrayfire
use, intrinsic :: ISO_C_Binding, only: C_ptr, C_NULL_ptr
implicit none
!> Contains the last known error in the arrayfire module
integer :: err
!> Single precision, real type
integer :: f32 = 1
!> Single precision, complex type
integer :: c32 = 2
!> Double precision, real type
integer :: f64 = 3
!> Double precision, complex type
integer :: c64 = 4
!> Boolean type
integer :: b8 = 5
!> type(array) containing information about device
type array
!> Dimensions of array
integer :: shape(4)
!> Rank of the array
integer :: rank
!> Device pointer
type(C_ptr) :: ptr = C_NULL_ptr
! not supported in gfortran 4.3
! contains
! procedure :: get => array_get
! procedure :: set => array_set
end type array
!> @defgroup basic Basics
!! @{
!> @defgroup mem Create arrays from host data
!> @{
!> Memory transfer from host to device, device to host.
!> @param[in] rhs -- Can be type array, real, double precision, complex, double complex
!> @returns lhs after assigning rhs to lhs
!> @code
!! type(array) arr
!! real, dimension(2, 2) :: a
!! a(1,1) = 1
!! a(2,2) = 1
!! ! a is now identity matrix of width 2
!! arr = a ! Data is now on device
!! arr = arr + 1.0 ! Increment arr by 1
!! a = log(arr) ! Return log(arr) to host
!! @endcode
interface assignment (=)
module procedure device1_s, device1_d, device1_c, device1_z
module procedure device2_s, device2_d, device2_c, device2_z
module procedure device3_s, device3_d, device3_c, device3_z
module procedure device4_s, device4_d, device4_c, device4_z
module procedure assign
module procedure host1_s, host1_d, host1_c, host1_z
module procedure host2_s, host2_d, host2_c, host2_z
module procedure host3_s, host3_d, host3_c, host3_z
module procedure host4_s, host4_d, host4_c, host4_z
end interface assignment (=)
interface getptr
module procedure hostp1_s, hostp1_d, hostp1_c, hostp1_z
module procedure hostp2_s, hostp2_d, hostp2_c, hostp2_z
module procedure hostp3_s, hostp3_d, hostp3_c, hostp3_z
module procedure hostp4_s, hostp4_d, hostp4_c, hostp4_z
end interface getptr
!> @}
!> @defgroup gen Generate random or constant matrices
!> Matrix generation
!> @code
!! type(array) res
!! res = randu(3, 3) ! Uniformly distributed random matrix, single precision by default
!! res = randn(3, 3) ! Normally distributed random matrix, single precision by default
!! res = constant(1,5, 5, ty = f32) ! Single precision matrix of all ones
!! res = constant(0,4, 4,ty = f64) ! Double precision matrix of all zeros
!! res = identity(2, 2) ! Identity Matrix, single precision by default
!! @endcode
!> @{
!> Generate matrices on the devices
!> @{
!> Random, uniformly distributed
!> @param[in] x1 -- The 1st dimension in the array (should be integer)
!> @param[in] x2 -- The 2nd dimension in the array (should be integer, optional, default: 1)
!> @param[in] x3 -- The 3rd dimension in the array (should be integer, optional, default: 1)
!> @param[in] x4 -- The 4th dimension in the array (should be integer, optional, default: 1)
!> @param[in] ty -- Should be one of (f32, f64, c32, c64), (optional, default: f32)
!> @returns output of size (x1, x2, x3, x4) filled with the required data type
interface randu
module procedure array_randu
end interface randu
!> @}
!> @{
!> Random, normally distributed
!> @param[in] x1 -- The 1st dimension in the array (should be integer)
!> @param[in] x2 -- The 2nd dimension in the array (should be integer, optional, default: 1)
!> @param[in] x3 -- The 3rd dimension in the array (should be integer, optional, default: 1)
!> @param[in] x4 -- The 4th dimension in the array (should be integer, optional, default: 1)
!> @param[in] ty -- Should be one of (f32, f64, c32, c64), (optional, default: f32)
!> @returns output of size (x1, x2, x3, x4) filled with the required data type
interface randn
module procedure array_randn
end interface randn
!> @}
!> @{
!> Constant value
!> @param[in] val -- constant value to constant with
!> @param[in] x1 -- The 1st dimension in the array (should be integer)
!> @param[in] x2 -- The 2nd dimension in the array (should be integer, optional, default: 1)
!> @param[in] x3 -- The 3rd dimension in the array (should be integer, optional, default: 1)
!> @param[in] x4 -- The 4th dimension in the array (should be integer, optional, default: 1)
!> @param[in] ty -- Should be one of (f32, f64, c32, c64), (optional, default: f32)
!> @returns output of size (x1, x2, x3, x4) constanted with the required data type
interface constant
module procedure array_constant
end interface constant
!> @}
!> @{
!> Constant, identity
!> @param[in] x1 -- The 1st dimension in the array (should be integer)
!> @param[in] x2 -- The 2nd dimension in the array (should be integer, optional, default: 1)
!> @param[in] ty -- Should be one of (f32, f64, c32, c64), (optional, default: f32)
!> @returns output of size (x1, x2, x3, x4) filled with the required data type
interface identity
module procedure array_identity
end interface identity
!> @}
!> @}
!> @defgroup indexing Array Indexing
!> @{
!> Setting and getting values from an array
!> @code
!> type(array) r, s, z
!> r = randu(5,5)
!> z = constant(0,5,5)
!> s = get(a, idx(2), seq(1,5,2)) !Get the second row and every other column between 1 and 5
!> call set(z, s, idx(1), seq(1,3)) !Set s as the first row and columsn 1 through 3
!> @endcode
!> @{
!> @param[in] in Input array
!> @param[in] d1 type(array) denoting indices along 1st dimension
!> @param[in] d2 type(array) denoting indices along 2nd dimension. Optional.
!> @param[in] d3 integer denoting the index of the 3rd dimension. Optional.
!> @param[in] d4 integer denoting the index of the 4th dimension. Optional.
!> @returns subarry of in referenced by d1,d2,d3,d4
interface get
module procedure array_get, array_get2, array_get_seq
end interface get
!> @}
!> @{
!> @param[in] lhs Array whos values are being set by rhs
!> @param[in] rhs The value being set
!> @param[in] d1 type(array) denoting indices along 1st dimension
!> @param[in] d2 type(array) denoting indices along 2nd dimension. Optional.
!> @param[in] d3 integer denoting the index of the 3rd dimension. Optional.
!> @param[in] d4 integer denoting the index of the 4th dimension. Optional.
interface set
module procedure array_set, array_set2, array_set_seq
end interface set
!> @}
!> @{
!> @param[in] index Can be an integer scalar or array
!> @returns type(array) holding the value of index
interface idx
module procedure idx_scalar, idx_vector
end interface idx
!> @}
!> @{
!> @param[in] first The first element of the sequence. Optional. Default: 0.
!> @param[in] last The last element of the sequence. Optional. Default: 0.
!> @param[in] setp The step size. Optional. Default: 1.
interface seq
module procedure arr_seq
end interface seq
!> @}
!> @}
!> @defgroup tile Tiling and reshaping
!> @{
!> moddims, flat, tile, etc
!> @{
!> Moddims an array
!> @param[in] A an array
!> @param[in] x1 -- The 1st dimension in the array (should be integer)
!> @param[in] x2 -- The 2nd dimension in the array (should be integer, optional, default: 1)
!> @param[in] x3 -- The 3rd dimension in the array (should be integer, optional, default: 1)
!> @param[in] x4 -- The 4th dimension in the array (should be integer, optional, default: 1)
!> @returns output of size (x1, x2, x3, x4) with the same data as input
!> @code
!! type(array) A, B
!! A = randu(2, 4) ! 2 dimensional array
!! B = moddims(A, 2, 2, 2) ! 3 dimensional array
!! @endcode
interface moddims
module procedure array_moddims
end interface moddims
!> @}
!> @{
!> Flatten an array
!> @param[in] A an array
!> @returns output of size with the same data as input, but as a column vector
!> @code
!! type(array) A, B
!! A = randu(2, 4) ! 2 dimensional array
!! B = flat(A) ! 1 dimensional array
!! @endcode
interface flat
module procedure array_flat
end interface flat
!> @}
!> @{
!> Tile an array
!> @param[in] A an array
!> @param[in] x1 -- The 1st dimension in the array (should be integer, optional, default: 1)
!> @param[in] x2 -- The 2nd dimension in the array (should be integer, optional, default: 1)
!> @param[in] x3 -- The 3rd dimension in the array (should be integer, optional, default: 1)
!> @param[in] x4 -- The 4th dimension in the array (should be integer, optional, default: 1)
!> @returns output of size (x1, x2, x3, x4) with the same data as input
!> @code
!! type(array) A, B
!! A = randu(2, 4) ! 2 dimensional array
!! B = tile(A, 1, 1, 2) ! 3 dimensional array
!! @endcode
interface tile
module procedure array_tile
end interface tile
!> @}
!> @{
!> Join two arrays
!> @param[in] d -- The dimension along which two arrays are to be joined
!> @param[in] first -- The first array
!> @param[in] second -- The second array
!> @returns output which is the combined array of first and second
!> @code
!! type(array) A, B, C
!! A = randu(2, 4) ! 2 dimensional array
!! B = randu(3, 4) ! 2 dimensional array
!! C = join(1, A, B) ! 3 dimensional array. Size: 5, 4
!! @endcode
interface join
module procedure array_join
end interface join
!> @}
!> @}
!> @defgroup manip Reorder and sorting: (transpose, reorder, sort)
!> @{
!> Functions that perform data re-ordering and sorting
!> @{
!> Matrix transpose
!> @param[in] A -- type array of size M x N
!> @returns B of size N x M which is the matrix transpose of A
!> @code
!! type(array) A, B
!! A = randu(20, 25) ! Random matrix
!! B = transpose(A) ! Matrix transpose
!! @endcode
interface transpose
module procedure array_transpose
end interface transpose
!> @}
!> @{
!> Matrix hermitian transpose
!> @param[in] A -- type array of size M x N
!> @returns B of size N x M which is the matrix transpose of A
!> @code
!! type(array) Re, Im, Cplx, Cplx2, Im2
!! Re = randu(5, 5) ! Random matrix, real part
!! Im = randu(5, 5) ! Random matrix, imaginary part
!! Cplx = complex(Re, Im) ! Create complex matrix
!! Cplx2 = htranspose(Cplx) ! Hermitian transpose
!! Im2 = imag(Cplx2) ! Extract imaginary part. same
!! call print(sum(Im + Im2)) ! Im is equal to -Im2
!! @endcode
interface htranspose
module procedure array_htranspose
end interface htranspose
!> @}
!> @{
!> Matrix reorder
!> @param[in] A -- type array of size M x N
!> @param[in] d1 -- integer, optional. 1st output dimension corresponding to an input dimension.
!> @param[in] d2 -- integer, optional. 2nd output dimension corresponding to an input dimension.
!> @param[in] d3 -- integer, optional. 3rd output dimension corresponding to an input dimension.
!> @param[in] d4 -- integer, optional. 4th output dimension corresponding to an input dimension.
!> @returns B of size N x M which is the matrix reorder of A
!> @code
!! type(array) A, B
!! A = randu(5, 2, 3, 4) ! Random matrix of size 5 x 2 x 3 x 4
!! B = reorder(A, 4, 1, 3, 2) ! reordered matrix of size 4 x 5 x 3 x 2
!! @endcode
interface reorder
module procedure array_reorder
end interface reorder
!> @}
!> @{
!> Matrix sort
!> @param[in] A - Matrix
!> @returns B whose columns are in sorted order of A
!> @code
!! type(array) A, B
!! A = randu(10, 10) ! Random matrix
!! B = sort(A) ! sort each column
!! @endcode
interface sort
module procedure array_sort
end interface sort
!> @}
!> @}
!> @defgroup extract Extraction: (lower, upper, real, imaginary)
!> @{
!> Functions that perform data re-ordering and sorting
!> @{
!> Matrix lower
!> @param[in] A - Matrix
!> @returns B the lower marix of A
!> @code
!! type(array) A, B
!! A = randu(10, 10) ! Random matrix
!! B = lower(A) ! Extract lower matrix of A
!! @endcode
interface lower
module procedure array_lower
end interface lower
!> @}
!> @{
!> Matrix upper
!> @param[in] A - Matrix
!> @returns B the upper marix of A
!> @code
!! type(array) A, B
!! A = randu(10, 10) ! Random matrix
!! B = upper(A) ! Extract upper matrix of A
!! @endcode
interface upper
module procedure array_upper
end interface upper
!> @}
!> @{
!> Matrix diag
!> @param[in] A - Matrix
!> @returns B the diag marix of A
!> @code
!! type(array) A, B
!! A = randu(10, 10) ! Random matrix
!! B = diag(A) ! Extract diag matrix of A
!! @endcode
interface diag
module procedure array_diag
end interface diag
!> @}
!> @{
!> Matrix real
!> @param[in] A - Matrix
!> @returns B the real marix of A
!> @code
!! type(array) Re, Im, Cplx, Re2, Im2
!! Re = randu(10, 10) ! Random matrix, real part
!! Im = randu(10, 10) ! Random matrix, imaginary part
!! Cplx = complex(Re, Im) ! Create complex matrix
!! Re2 = real(Cplx) ! Extract real part, Same as Re
!! Im2 = imag(Cplx) ! Extract imaginary part, Same as Im
!! @endcode
interface real
module procedure array_real
end interface real
!> @}
!> @{
!> Matrix imag
!> @param[in] A - Matrix
!> @returns B the imag marix of A
!> @code
!! type(array) Re, Im, Cplx, Re2, Im2
!! Re = randu(10, 10) ! Random matrix, real part
!! Im = randu(10, 10) ! Random matrix, imaginary part
!! Cplx = complex(Re, Im) ! Create complex matrix
!! Re2 = real(Cplx) ! Extract real part, Same as Re
!! Im2 = imag(Cplx) ! Extract imaginary part, Same as Im
!! @endcode
interface imag
module procedure array_imag
end interface imag
!> @}
!> @{
!> Matrix complex
!> @param[in] A - Matrix
!> @returns B the complex marix of A
!> @code
!! type(array) Re, Im, Cplx, Re2, Im2
!! Re = randu(10, 10) ! Random matrix, real part
!! Im = randu(10, 10) ! Random matrix, imaginary part
!! Cplx = complex(Re, Im) ! Create complex matrix
!! Re2 = real(Cplx) ! Extract real part, Same as Re
!! Im2 = imag(Cplx) ! Extract imaginary part, Same as Im
!! @endcode
interface complex
module procedure array_complex, array_complex2
end interface complex
!> @}
!> @{
!> Matrix complex conjugate
!> @param[in] A - Matrix (complex type)
!> @returns B the complex conjugate marix of A
!> @code
!! type(array) Re, Im, Cplx, Conj
!! Re = randu(10, 10) ! Random matrix, real part
!! Im = randu(10, 10) ! Random matrix, imaginary part
!! Cplx = complex(Re, Im) ! Create complex matrix
!! Conj = conjg(Cplx) ! Create complex conjugate
!! @endcode
interface conjg
module procedure array_conjg
end interface conjg
!> @}
!> @}
!> @defgroup help Helper functions (show, info, eval, sync)
!> @{
!> Functions useful for debugging.
!> @{
!> Displays the contens of type array
!> @param[in] in -- Conents of type array
!> @param[in] STR -- String to be displayed before displaying in (Optional)
!> @code
!! call print(randu(3,3))
!! call print(constant(1,3,3), "Matrix of all ones")
!! @endcode
interface print
module procedure array_print
end interface print
!> @}
!> @{
!> Displays system and arayfire information
!> @code
!! call device_info()
!! @endcode
interface device_info
module procedure device_info_
end interface device_info
!> @}
!> @{
!> Syncs all operations on the current GPU
!> @code
!! call device_sync()
!! @endcode
interface device_sync
module procedure device_sync_
end interface device_sync
!> @}
!> @{
!> Forces evaluation on the device
!> @code
!! call device_eval(A + B)
!! @endcode
interface device_eval
module procedure device_eval_
end interface device_eval
!> @}
!> @}
!> @defgroup gpu Multi-GPU and device handling
!> @{
!> Functions useful for Multi-GPU. Requires <a href=http://accelereyes.com/products/arrayfire_licensing>ArrayFire Pro</a>.
!> @{
!> Get the count of gpus available
!> @code
!! integer count = device_count
!! @endcode
interface device_count
module procedure device_count_
end interface device_count
!> @}
!> @{
!> Switch to a particular gpu
!> @code
!! call device_set(1) ! Switch to gpu 1
!! @endcode
interface device_set
module procedure device_set_
end interface device_set
!> @}
!> @{
!> Get current gpu
!> @code
!! integer current = device_get() ! 0 by default
!! @endcode
interface device_get
module procedure device_get_
end interface device_get
!> @}
!> @}
!> @defgroup time Timing code
!> @{
!> Functions useful for timing GPU code
!> @{
!> Start timer
!> @code
!! double precision elapsed
!! type(array) A, B
!! A = randu(1024, 2048)
!! call timer_start()
!! B = matmul(A, transpose(A))
!! elapsed = timer_stop()
!! @endcode
interface timer_start
module procedure timer_start_
end interface timer_start
!> @}
!> @{
!> Stop timer
!> @code
!! double precision elapsed
!! type(array) A, B
!! A = randu(1024, 2048)
!! call timer_start()
!! B = matmul(A, transpose(A))
!! elapsed = timer_stop()
!! @endcode
interface timer_stop
module procedure timer_stop_
end interface timer_stop
!> @}
!> @}
!> @}
!> @defgroup op Mathematical operations
!> @{
!> Arithmetic, relational, logical and other element wise operations
!> @defgroup arith Arithmetic operations
!> Basic arithmetic operations
!> @code
!! type(array) lhs, rhs, res
!! real scalar
!! scalar = 0.5
!! lhs = constant(1,3, 3) ! All zeros
!! rhs = constant(0,3, 3) ! All ones
!! res = lhs + rhs ! All zeros
!! res = lhs * rhs ! All ones
!! res = lhs - scalar ! All 0.5
!! res = lhs / scalar ! All 2.0
!! @endcode
!! @{
!> @{
!> Element wise addition
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- Can be type array, real or integer
!> @returns output which contains element wise operation of lhs and rhs
interface operator (+)
module procedure array_plus
module procedure array_plus_s, array_lplus_s
module procedure array_plus_d, array_lplus_d
module procedure array_plus_i, array_lplus_i
end interface operator (+)
!> @}
!> @{
!> Element wise subtraction
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- Can be type array, real or integer
!> @returns output which contains element wise operation of lhs and rhs
interface operator (-)
module procedure array_minus
module procedure array_minus_s, array_lminus_s
module procedure array_minus_d, array_lminus_d
module procedure array_minus_i, array_lminus_i
module procedure array_negate
end interface operator (-)
!> @}
!> @{
!> Element wise multiplication
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- Can be type array, real or integer
!> @returns output which contains element wise operation of lhs and rhs
interface operator (*)
module procedure array_times
module procedure array_times_s, array_ltimes_s
module procedure array_times_d, array_ltimes_d
module procedure array_times_i, array_ltimes_i
end interface operator (*)
!> @}
!> @{
!> Element wise division
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- Can be type array, real or integer
!> @returns output which contains element wise operation of lhs and rhs
interface operator (/)
module procedure array_div
module procedure array_div_s, array_ldiv_s
module procedure array_div_d, array_ldiv_d
module procedure array_div_i, array_ldiv_i
end interface operator (/)
!> @}
!> @{
!> Element wise power
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- Should be real or integer
!> @returns output which contains element wise operation of lhs and rhs
interface operator (**)
module procedure array_pow
module procedure array_pow_s, array_pow_d, array_pow_i
end interface operator (**)
!> @}
!> @}
!> @defgroup relate Relational operations (<, >, ==, /=)
!> Relational operations
!> @code
!! type(array) lhs, rhs, res
!! real scalar
!! scalar = 0.5
!! lhs = constant(1,3, 3) ! All zeros
!! rhs = constant(0,3, 3) ! All ones
!! res = lhs < rhs ! All false
!! res = lhs > rhs ! All true
!! res = lhs == scalar ! All false
!! res = lhs /= scalar ! All true
!! @endcode
!! @{
!> @{
!> Compare greater than
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- Can be type array or real
!> @returns output which contains element wise operation of lhs and rhs
interface operator (>)
module procedure array_ge
module procedure array_gt_s, array_lgt_s
module procedure array_gt_d, array_lgt_d
module procedure array_gt_i, array_lgt_i
end interface operator (>)
!> @}
!> @{
!> Compare less than
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- Can be type array or real
!> @returns output which contains element wise operation of lhs and rhs
interface operator (<)
module procedure array_le
module procedure array_lt_s, array_llt_s
module procedure array_lt_d, array_llt_d
module procedure array_lt_i, array_llt_i
end interface operator (<)
!> @}
!> @{
!> Compare greater than or equal to
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- Can be type array or real
!> @returns output which contains element wise operation of lhs and rhs
interface operator (>=)
module procedure array_ge
module procedure array_ge_s, array_lge_s
module procedure array_ge_d, array_lge_d
module procedure array_ge_i, array_lge_i
end interface operator (>=)
!> @}
!> @{
!> Compare less than or equal to
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- Can be type array or real
!> @returns output which contains element wise operation of lhs and rhs
interface operator (<=)
module procedure array_le
module procedure array_le_s, array_lle_s
module procedure array_le_d, array_lle_d
module procedure array_le_i, array_lle_i
end interface operator (<=)
!> @}
!> @{
!> Compare equal to
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- Can be type array or real
!> @returns output which contains element wise operation of lhs and rhs
interface operator (==)
module procedure array_eq
module procedure array_eq_s, array_leq_s
module procedure array_eq_d, array_leq_d
module procedure array_eq_i, array_leq_i
end interface operator (==)
!> @}
!> @{
!> Compare not equal to
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- Can be type array or real
!> @returns output which contains element wise operation of lhs and rhs
interface operator (/=)
module procedure array_ne
module procedure array_ne_s, array_lne_s
module procedure array_ne_d, array_lne_d
module procedure array_ne_i, array_lne_i
end interface operator (/=)
!> @}
!> @}
!> @defgroup logic Logical operations (.and., .or., .not.)
!> Relational operations
!> @code
!! type(array) lhs, rhs, res
!! real scalar
!! scalar = 0.5
!! lhs = randu(3, 3)
!! rhs = randu(3, 3)
!! res = lhs < rhs .and. lhs == 0.5
!! res = rhs > 0.3 .or. rhs <= 0.25
!! @endcode
!! @{
!> @{
!> Logical AND operator
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- should be type array
!> @returns output which contains element wise operation of lhs and rhs
interface operator (.and.)
module procedure array_and
end interface operator (.and.)
!> @}
!> @{
!> Logical OR operator
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- should be type array
!> @returns output which contains element wise operation of lhs and rhs
interface operator (.or.)
module procedure array_or
end interface operator (.or.)
!> @}
!> @{
!> Logical NOT operator
!> @param[in] lhs -- Should be type array
!> @param[in] rhs -- should be type array
!> @returns output which contains element wise operation of lhs and rhs
interface operator (.not.)
module procedure array_not
end interface operator (.not.)
!> @}
!> @}
!> @defgroup elem Element wise functions (sin, cos, exp, log ..)
!> @code
!! type(array) in, out
!! in = randu(3, 3) ! Random matrix
!! out = sin(in) ! similarily cos(in), tan(in)
!! out = exp(in) ! similarily log(in)
!! out = abs(in - 0.5) ! absolute values
!! @endcode
!! @{
!> @{
!> sine of an array
!> @param[in] in -- Should be type array
!> @returns output which performs the function element wise
interface sin
module procedure array_sin
end interface sin
!> @}
!> @{
!> co-sine of an array
!> @param[in] in -- Should be type array
!> @returns output which performs the function element wise
interface cos
module procedure array_cos
end interface cos
!> @}
!> @{
!> tangent of an array
interface tan
module procedure array_tan
end interface tan
!> @}
!> @{
!> logarithm of an array
!> @param[in] in -- Should be type array
!> @returns output which performs the function element wise
interface log
module procedure array_log
end interface log
!> @}
!> @{
!> exponential of an array
!> @param[in] in -- Should be type array
!> @returns output which performs the function element wise
interface exp
module procedure array_exp
end interface exp
!> @}
!> @{
!> absolute of an array
!> @param[in] in -- Should be type array
!> @returns output which performs the function element wise
interface abs
module procedure array_abs
end interface abs
!> @}
!> @}
!> @}
!> @defgroup alg Linear Algebra
!> @{
!> Linear Algebra routines
!> @defgroup blas Basic linear algebra (Matrix multiply and dot product)
!! @{
!> Matrix multiply, inner and outer products
!> @{
!> Matrix multiply
!> @param[in] A -- type array of size M x K
!> @param[in] B -- type array of size K x N
!> @returns C of size M x N which is the matrix product of A, B
!> @code
!! type(array) A, B, C
!! A = randu(20, 25) ! Random matrix
!! B = randu(25, 10) ! Random matrix
!! C = matmul(A, B) ! Matrix multiply
!! @endcode
interface matmul
module procedure array_matmul
end interface matmul
!> @}
!> @}
!> @defgroup dla Factorization: lu, qr, cholesky, singular values
!> @{
!> Dense linear algebra: Factorization routines
!> @{
!> LU decomposition
!> Double-precision or complex input requires <a href=http://accelereyes.com/products/arrayfire_licensing>ArrayFire Pro</a>.
!> (Double and
!> @param[out] L -- Optional (Contains lower triangular matrix on exit)
!> @param[out] U -- Optional (Contains upper triangular matrix on exit)
!> @param[out] p -- Optional (Contains permutation matrix on exit, such that L * U = A * p)
!> @param[in] A - Input matrix. (Contains packed LU matrices, if performed in place)
!> @code
!! type(array) A, B
!! type(array) L, U, p
!! A = randu(5,5) ! Generate random matrix
!! B = A ! Make a copy of A
!! call lu(L, U, p, A) ! Out of place LU Decomposition
!! call lu(B) ! In place decomposition
!! !B now has L below the diagonal and U above the diagonal
!! @endcode
interface lu
module procedure array_lu, array_lu_inplace
end interface lu
!> @}
!> @{
!> Cholesky decomposition
!> Double-precision or complex input requires <a href=http://accelereyes.com/products/arrayfire_licensing>ArrayFire Pro</a>.
!> (Double and
!> @param[out] R -- Optional (Contains lower triangular matrix on exit, such that A = R*transpose(R))
!> @param[in] A - Input matrix. (Contains R in the lower triangle, if performed in place)
!> @code
!! type(array) A, B
!! type(array) R
!! A = randu(5,5) ! Generate random matrix
!! B = A ! Make a copy of A
!! call cholesky(R, A) ! Out of place cholesky Decomposition
!! call cholesky(B) ! In place decomposition
!! !B now has R below the diagonal
!! @endcode
interface cholesky
module procedure array_cholesky, array_cholesky_inplace
end interface cholesky
!> @}
!> @{
!> QR decomposition
!> Double-precision or complex input requires <a href=http://accelereyes.com/products/arrayfire_licensing>ArrayFire Pro</a>.
!> (Double and
!> @param[out] Q -- Contains the orthogonal basis of input matrix
!> @param[out] R -- Contains a upper upper trianular matrix such that A = Q * R
!> @param[in] A -- Input matrix.
!> @code
!! type(array) A
!! type(array) Q, R
!! A = randu(5,5) ! Generate random matrix
!! call qr(Q, R, A)
!! @endcode
interface qr
module procedure array_qr
end interface qr
!> @}
!> @{
!> singular value decomposition
!> This function requires <a href=http://accelereyes.com/products/arrayfire_licensing>ArrayFire Pro</a>.
!> @param[out] S -- Contains the singular values of input
!> @param[out] U -- Contains the left unitary matrix
!> @param[out] V -- Contains the right unitary matrix
!> @param[in] A -- Input matrix.
!> @code
!! type(array) A
!! type(array) S, V, U
!! A = randu(5,5) ! Generate random matrix
!! call singular(S, U, V, A)
!! @endcode
interface singular
module procedure array_singular
end interface singular
!> @}
!> @}
!> @defgroup solve Solving linear systems
!> @{
!> Comprehensive options for solving linear systems
!> @{
!> Solve a system of equations
!> Double-precision or complex input requires <a href=http://accelereyes.com/products/arrayfire_licensing>ArrayFire Pro</a>.
!> @param[out] R -- Contains the solution to the system of equations
!> @param[in] A -- Co-efficient matrix
!> @param[in] B -- Observations
!> @code
!! type(array) A, B, X0, X
!! ! Generate random system
!! A = randu(5,5)
!! X0 = randu(5,1)
!! B = matmul(A, X0)
!! X = solve(A, B)
!! @endcode
interface solve
module procedure array_solve
end interface solve
!> @}
!> @}
!> @defgroup linops Other Linear algebra operations: inverse, matrix power, norm, rank
!> @{
!> Matrix inverse, power, norm and rank
!> @{
!> inverse of a matrix
!> This function requires <a href=http://accelereyes.com/products/arrayfire_licensing>ArrayFire Pro</a>.
!> @param[out] R -- Contains the inverse values of input
!> @param[in] A -- Input matrix.