-
Notifications
You must be signed in to change notification settings - Fork 555
Expand file tree
/
Copy pathdata.h
More file actions
1006 lines (858 loc) · 36.9 KB
/
Copy pathdata.h
File metadata and controls
1006 lines (858 loc) · 36.9 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
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#pragma once
#include <af/defines.h>
#ifdef __cplusplus
#include <af/dim4.hpp>
#include <af/traits.hpp>
namespace af
{
class array;
/// C++ Interface to generate an array with elements set to a specified
/// value.
///
/// \param[in] val constant value
/// \param[in] dims dimensions of the array to be generated
/// \param[in] ty type
/// \return constant array
///
/// \ingroup data_func_constant
template<typename T>
array constant(T val, const dim4 &dims, const dtype ty=(af_dtype)dtype_traits<T>::ctype);
/// C++ Interface to generate a 1-D array with elements set to a specified
/// value.
///
/// \param[in] val constant value
/// \param[in] d0 size of the first dimension
/// \param[in] ty type
/// \return constant 1-D array
///
/// \ingroup data_func_constant
template<typename T>
array constant(T val, const dim_t d0, const af_dtype ty=(af_dtype)dtype_traits<T>::ctype);
/// C++ Interface to generate a 2-D array with elements set to a specified
/// value.
///
/// \param[in] val constant value
/// \param[in] d0 size of the first dimension
/// \param[in] d1 size of the second dimension
/// \param[in] ty type
/// \return constant 2-D array
///
/// \ingroup data_func_constant
template<typename T>
array constant(T val, const dim_t d0, const dim_t d1, const af_dtype ty=(af_dtype)dtype_traits<T>::ctype);
/// C++ Interface to generate a 3-D array with elements set to a specified
/// value.
///
/// \param[in] val constant value
/// \param[in] d0 size of the first dimension
/// \param[in] d1 size of the second dimension
/// \param[in] d2 size of the third dimension
/// \param[in] ty type
/// \return constant 3-D array
///
/// \ingroup data_func_constant
template<typename T>
array constant(T val, const dim_t d0, const dim_t d1, const dim_t d2, const af_dtype ty=(af_dtype)dtype_traits<T>::ctype);
/// C++ Interface to generate a 4-D array with elements set to a specified
/// value.
///
/// \param[in] val constant value
/// \param[in] d0 size of the first dimension
/// \param[in] d1 size of the second dimension
/// \param[in] d2 size of the third dimension
/// \param[in] d3 size of the fourth dimension
/// \param[in] ty type
/// \return constant 4-D array
///
/// \ingroup data_func_constant
template<typename T>
array constant(T val, const dim_t d0, const dim_t d1, const dim_t d2, const dim_t d3, const af_dtype ty=(af_dtype)dtype_traits<T>::ctype);
/// C++ Interface to generate an identity array.
///
/// \param[in] dims size
/// \param[in] ty type
/// \return identity array
///
/// \ingroup data_func_identity
AFAPI array identity(const dim4 &dims, const dtype ty=f32);
/// C++ Interface to generate a 1-D identity array.
///
/// \param[in] d0 size of the first dimension
/// \param[in] ty type
/// \return identity array
///
/// \ingroup data_func_identity
AFAPI array identity(const dim_t d0, const dtype ty=f32);
/// C++ Interface to generate a 2-D identity array.
///
/// \param[in] d0 size of the first dimension
/// \param[in] d1 size of the second dimension
/// \param[in] ty type
/// \return identity array
///
/// \ingroup data_func_identity
AFAPI array identity(const dim_t d0, const dim_t d1, const dtype ty=f32);
/// C++ Interface to generate a 3-D identity array.
///
/// \param[in] d0 size of the first dimension
/// \param[in] d1 size of the second dimension
/// \param[in] d2 size of the third dimension
/// \param[in] ty type
/// \return identity array
///
/// \ingroup data_func_identity
AFAPI array identity(const dim_t d0, const dim_t d1,
const dim_t d2, const dtype ty=f32);
/// C++ Interface to generate a 4-D identity array.
///
/// \param[in] d0 size of the first dimension
/// \param[in] d1 size of the second dimension
/// \param[in] d2 size of the third dimension
/// \param[in] d3 size of the fourth dimension
/// \param[in] ty type
/// \return identity array
///
/// \ingroup data_func_identity
AFAPI array identity(const dim_t d0, const dim_t d1,
const dim_t d2, const dim_t d3, const dtype ty=f32);
/// C++ Interface to generate an array with `[0, n-1]` values along the
/// `seq_dim` dimension and tiled across other dimensions of shape `dim4`.
///
/// \param[in] dims size
/// \param[in] seq_dim dimesion along which the range is created
/// \param[in] ty type
/// \return range array
///
/// \ingroup data_func_range
AFAPI array range(const dim4 &dims, const int seq_dim = -1, const dtype ty=f32);
/// C++ Interface to generate an array with `[0, n-1]` values along the
/// `seq_dim` dimension and tiled across other dimensions described by
/// dimension parameters.
///
/// \param[in] d0 size of the first dimension
/// \param[in] d1 size of the second dimension
/// \param[in] d2 size of the third dimension
/// \param[in] d3 size of the fourth dimension
/// \param[in] seq_dim dimesion along which the range is created
/// \param[in] ty type
/// \return range array
///
/// \ingroup data_func_range
AFAPI array range(const dim_t d0, const dim_t d1 = 1, const dim_t d2 = 1,
const dim_t d3 = 1, const int seq_dim = -1, const dtype ty=f32);
/// C++ Interface to generate an array with `[0, n-1]` values modified to
/// specified dimensions and tiling.
///
/// \param[in] dims size
/// \param[in] tile_dims number of tiled repetitions in each dimension
/// \param[in] ty type
/// \return iota array
///
/// \ingroup data_func_iota
AFAPI array iota(const dim4 &dims, const dim4 &tile_dims = dim4(1), const dtype ty=f32);
/// C++ Interface to extract the diagonal from an array.
///
/// \param[in] in input array
/// \param[in] num diagonal index
/// \param[in] extract if true, returns an array containing diagonal of the
/// matrix; if false, returns a diagonal matrix
/// \return diagonal array (or matrix)
///
/// \ingroup data_func_diag
AFAPI array diag(const array &in, const int num = 0, const bool extract = true);
/// C++ Interface to join 2 arrays along a dimension.
///
/// Empty arrays are ignored.
///
/// \param[in] dim dimension along which the join occurs
/// \param[in] first input array
/// \param[in] second input array
/// \return joined array
///
/// \ingroup manip_func_join
AFAPI array join(const int dim, const array &first, const array &second);
/// C++ Interface to join 3 arrays along a dimension.
///
/// Empty arrays are ignored.
///
/// \param[in] dim dimension along which the join occurs
/// \param[in] first input array
/// \param[in] second input array
/// \param[in] third input array
/// \return joined array
///
/// \ingroup manip_func_join
AFAPI array join(const int dim, const array &first, const array &second, const array &third);
/// C++ Interface to join 4 arrays along a dimension.
///
/// Empty arrays are ignored.
///
/// \param[in] dim dimension along which the join occurs
/// \param[in] first input array
/// \param[in] second input array
/// \param[in] third input array
/// \param[in] fourth input array
/// \return joined array
///
/// \ingroup manip_func_join
AFAPI array join(const int dim, const array &first, const array &second,
const array &third, const array &fourth);
/// C++ Interface to generate a tiled array.
///
/// Note, `x`, `y`, `z`, and `w` include the original in the count.
///
/// \param[in] in input array
/// \param[in] x number tiles along the first dimension
/// \param[in] y number tiles along the second dimension
/// \param[in] z number tiles along the third dimension
/// \param[in] w number tiles along the fourth dimension
/// \return tiled array
///
/// \ingroup manip_func_tile
AFAPI array tile(const array &in, const unsigned x, const unsigned y=1,
const unsigned z=1, const unsigned w=1);
/// C++ Interface to generate a tiled array.
///
/// Each component of `dims` includes the original in the count. Thus, if
/// no duplicates are needed in a certain dimension, it is left as 1, the
/// default value for just one copy.
///
/// \param[in] in input array
/// \param[in] dims number of times `in` is copied along each dimension
/// \return tiled array
///
/// \ingroup manip_func_tile
AFAPI array tile(const array &in, const dim4 &dims);
/// C++ Interface to reorder an array.
///
/// \param[in] in input array
/// \param[in] x specifies which dimension should be first
/// \param[in] y specifies which dimension should be second
/// \param[in] z specifies which dimension should be third
/// \param[in] w specifies which dimension should be fourth
/// \return reordered array
///
/// \ingroup manip_func_reorder
AFAPI array reorder(const array& in, const unsigned x,
const unsigned y=1, const unsigned z=2, const unsigned w=3);
/// C++ Interface to shift an array.
///
/// \param[in] in input array
/// \param[in] x specifies the shift along the first dimension
/// \param[in] y specifies the shift along the second dimension
/// \param[in] z specifies the shift along the third dimension
/// \param[in] w specifies the shift along the fourth dimension
/// \return shifted array
///
/// \ingroup manip_func_shift
AFAPI array shift(const array& in, const int x, const int y=0, const int z=0, const int w=0);
/// C++ Interface to modify the dimensions of an input array to a specified
/// shape.
///
/// \param[in] in input array
/// \param[in] dims new dimension sizes
/// \return modded output
///
/// \ingroup manip_func_moddims
AFAPI array moddims(const array& in, const dim4& dims);
/// C++ Interface to modify the dimensions of an input array to a specified
/// shape.
///
/// \param[in] in input array
/// \param[in] d0 new size of the first dimension
/// \param[in] d1 new size of the second dimension (optional)
/// \param[in] d2 new size of the third dimension (optional)
/// \param[in] d3 new size of the fourth dimension (optional)
/// \return modded output
///
/// \ingroup manip_func_moddims
AFAPI array moddims(const array& in, const dim_t d0, const dim_t d1=1, const dim_t d2=1, const dim_t d3=1);
/// C++ Interface to modify the dimensions of an input array to a specified
/// shape.
///
/// \param[in] in input array
/// \param[in] ndims number of dimensions
/// \param[in] dims new dimension sizes
/// \return modded output
///
/// \ingroup manip_func_moddims
AFAPI array moddims(const array& in, const unsigned ndims, const dim_t* const dims);
/// C++ Interface to flatten an array.
///
/// \param[in] in input array
/// \return flat array
///
/// \ingroup manip_func_flat
AFAPI array flat(const array &in);
/// C++ Interface to flip an array.
///
/// \param[in] in input array
/// \param[in] dim dimension to flip
/// \return flipped array
///
/// \ingroup manip_func_flip
AFAPI array flip(const array &in, const unsigned dim);
/// C++ Interface to return the lower triangle array.
///
/// \param[in] in input array
/// \param[in] is_unit_diag boolean specifying if diagonal elements are 1's
/// \return lower triangle array
///
/// \ingroup data_func_lower
AFAPI array lower(const array &in, bool is_unit_diag=false);
/// C++ Interface to return the upper triangle array.
///
/// \param[in] in input array
/// \param[in] is_unit_diag boolean specifying if diagonal elements are 1's
/// \return upper triangle matrix
///
/// \ingroup data_func_upper
AFAPI array upper(const array &in, bool is_unit_diag=false);
#if AF_API_VERSION >= 31
/// C++ Interface to select elements based on a conditional array.
///
/// \param[in] cond conditional array
/// \param[in] a when true, select array element
/// \param[in] b when false, select array element
/// \return `a` when `cond` is true, else `b`
///
/// \ingroup data_func_select
AFAPI array select(const array &cond, const array &a, const array &b);
#endif
#if AF_API_VERSION >= 31
/// C++ Interface to select elements based on a conditional array.
///
/// \param[in] cond conditional array
/// \param[in] a when true, select array element
/// \param[in] b when false, select scalar value
/// \return `a` when `cond` is true, else `b`
///
/// \ingroup data_func_select
AFAPI array select(const array &cond, const array &a, const double &b);
#endif
#if AF_API_VERSION >= 31
/// C++ Interface to select elements based on a conditional array.
///
/// \param[in] cond conditional array
/// \param[in] a when true, select scalar value
/// \param[in] b when false, select array element
/// \return `a` when `cond` is true, else `b`
///
/// \ingroup data_func_select
AFAPI array select(const array &cond, const double &a, const array &b);
#endif
#if AF_API_VERSION >= 31
/// C++ Interface to replace elements of an array with elements of another
/// array.
///
/// Elements of `a` are replaced with corresponding elements of `b` when
/// `cond` is false.
///
/// \param[inout] a input array
/// \param[in] cond conditional array
/// \param[in] b replacement array
///
/// \ingroup data_func_replace
AFAPI void replace(array &a, const array &cond, const array &b);
#endif
#if AF_API_VERSION >= 31
/// C++ Interface to replace elements of an array with a scalar value.
///
/// Elements of `a` are replaced with a scalar value when `cond` is false.
///
/// \param[inout] a input array
/// \param[in] cond conditional array
/// \param[in] b replacement scalar value
///
/// \ingroup data_func_replace
AFAPI void replace(array &a, const array &cond, const double &b);
#endif
#if AF_API_VERSION >= 37
/// C++ Interface to pad an array.
///
/// \param[in] in input array
/// \param[in] beginPadding number of elements to be padded at the start of
/// each dimension
/// \param[in] endPadding number of elements to be padded at the end of
/// each dimension
/// \param[in] padFillType values to fill into the padded region
/// \return padded array
///
/// \ingroup data_func_pad
AFAPI array pad(const array &in, const dim4 &beginPadding,
const dim4 &endPadding, const borderType padFillType);
#endif
#if AF_API_VERSION >= 39
/// C++ Interface to replace elements of an array with a scalar value.
///
/// Elements of `a` are replaced with a scalar value when `cond` is false.
///
/// \param[inout] a input array
/// \param[in] cond conditional array
/// \param[in] b replacement scalar value
///
/// \ingroup data_func_replace
AFAPI void replace(array &a, const array &cond, const long long b);
/// C++ Interface to replace elements of an array with a scalar value.
///
/// Elements of `a` are replaced with a scalar value when `cond` is false.
///
/// \param[inout] a input array
/// \param[in] cond conditional array
/// \param[in] b replacement scalar value
///
/// \ingroup data_func_replace
AFAPI void replace(array &a, const array &cond,
const unsigned long long b);
/// C++ Interface to select elements based on a conditional array.
///
/// \param[in] cond conditional array
/// \param[in] a when true, select array element
/// \param[in] b when false, select scalar value
/// \return `a` when `cond` is true, else `b`
///
/// \ingroup data_func_select
AFAPI array select(const array &cond, const array &a, const long long b);
/// C++ Interface to select elements based on a conditional array.
///
/// \param[in] cond conditional array
/// \param[in] a when true, select array element
/// \param[in] b when false, select scalar value
/// \return `a` when `cond` is true, else `b`
///
/// \ingroup data_func_select
AFAPI array select(const array &cond, const array &a,
const unsigned long long b);
/// C++ Interface to select elements based on a conditional array.
///
/// \param[in] cond conditional array
/// \param[in] a when true, select scalar value
/// \param[in] b when false, select array element
/// \return `a` when `cond` is true, else `b`
///
/// \ingroup data_func_select
AFAPI array select(const array &cond, const long long a, const array &b);
/// C++ Interface to select elements based on a conditional array.
///
/// \param[in] cond conditional array
/// \param[in] a when true, select scalar value
/// \param[in] b when false, select array element
/// \return `a` when `cond` is true, else `b`
///
/// \ingroup data_func_select
AFAPI array select(const array &cond, const unsigned long long a,
const array &b);
#endif
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
C Interface to generate an array with elements set to a specified value.
\param[out] arr constant array
\param[in] val constant value
\param[in] ndims size of the dimension array
\param[in] dims dimensions of the array to be generated
\param[in] type type
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_constant
*/
AFAPI af_err af_constant(af_array *arr, const double val, const unsigned ndims, const dim_t * const dims, const af_dtype type);
/**
C Interface to generate a complex array with elements set to a specified
value.
\param[out] arr constant complex array
\param[in] real real constant value
\param[in] imag imaginary constant value
\param[in] ndims size of the dimension array
\param[in] dims dimensions of the array to be generated
\param[in] type type, \ref c32 or \ref c64
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_constant
*/
AFAPI af_err af_constant_complex(af_array *arr, const double real, const double imag,
const unsigned ndims, const dim_t * const dims, const af_dtype type);
/**
C Interface to generate an array with elements set to a specified value.
Output type is \ref s64.
\param[out] arr constant array
\param[in] val constant value
\param[in] ndims size of the dimension array
\param[in] dims dimensions of the array to be generated
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_constant
*/
AFAPI af_err af_constant_long (af_array *arr, const long long val, const unsigned ndims, const dim_t * const dims);
/**
C Interface to generate an array with elements set to a specified value.
Output type is \ref u64.
\param[out] arr constant array
\param[in] val constant value
\param[in] ndims size of the dimension array
\param[in] dims dimensions of the array to be generated
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_constant
*/
AFAPI af_err af_constant_ulong(af_array *arr, const unsigned long long val, const unsigned ndims, const dim_t * const dims);
/**
C Interface to generate an identity array.
\param[out] out identity array
\param[in] ndims number of dimensions
\param[in] dims size
\param[in] type type
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_identity
*/
AFAPI af_err af_identity(af_array* out, const unsigned ndims, const dim_t* const dims, const af_dtype type);
/**
C Interface to generate an array with `[0, n-1]` values along the
`seq_dim` dimension and tiled across other dimensions of shape `dim4`.
\param[out] out range array
\param[in] ndims number of dimensions, specified by the size of `dims`
\param[in] dims size
\param[in] seq_dim dimension along which the range is created
\param[in] type type
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_range
*/
AFAPI af_err af_range(af_array *out, const unsigned ndims, const dim_t * const dims,
const int seq_dim, const af_dtype type);
/**
C Interface to generate an array with `[0, n-1]` values modified to
specified dimensions and tiling.
\param[out] out iota array
\param[in] ndims number of dimensions
\param[in] dims size
\param[in] t_ndims number of dimensions of tiled array
\param[in] tdims number of tiled repetitions in each dimension
\param[in] type type
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_iota
*/
AFAPI af_err af_iota(af_array *out, const unsigned ndims, const dim_t * const dims,
const unsigned t_ndims, const dim_t * const tdims, const af_dtype type);
/**
C Interface to create a diagonal matrix from an extracted diagonal
array.
See also, \ref af_diag_extract.
\param[out] out diagonal matrix
\param[in] in diagonal array
\param[in] num diagonal index
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_diag
*/
AFAPI af_err af_diag_create(af_array *out, const af_array in, const int num);
/**
C Interface to extract the diagonal from an array.
See also, \ref af_diag_create.
\param[out] out `num`-th diagonal array
\param[in] in input array
\param[in] num diagonal index
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_diag
*/
AFAPI af_err af_diag_extract(af_array *out, const af_array in, const int num);
/**
C Interface to join 2 arrays along a dimension.
Empty arrays are ignored.
\param[out] out joined array
\param[in] dim dimension along which the join occurs
\param[in] first input array
\param[in] second input array
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup manip_func_join
*/
AFAPI af_err af_join(af_array *out, const int dim, const af_array first, const af_array second);
/**
C Interface to join many arrays along a dimension.
Limited to 10 arrays. Empty arrays are ignored.
\param[out] out joined array
\param[in] dim dimension along which the join occurs
\param[in] n_arrays number of arrays to join
\param[in] inputs array of af_arrays containing handles to the
arrays to be joined
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup manip_func_join
*/
AFAPI af_err af_join_many(af_array *out, const int dim, const unsigned n_arrays, const af_array *inputs);
/**
C Interface to generate a tiled array.
Note, `x`, `y`, `z`, and `w` include the original in the count.
\param[out] out tiled array
\param[in] in input array
\param[in] x number of tiles along the first dimension
\param[in] y number of tiles along the second dimension
\param[in] z number of tiles along the third dimension
\param[in] w number of tiles along the fourth dimension
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup manip_func_tile
*/
AFAPI af_err af_tile(af_array *out, const af_array in,
const unsigned x, const unsigned y, const unsigned z, const unsigned w);
/**
C Interface to reorder an array.
\param[out] out reordered array
\param[in] in input array
\param[in] x specifies which dimension should be first
\param[in] y specifies which dimension should be second
\param[in] z specifies which dimension should be third
\param[in] w specifies which dimension should be fourth
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup manip_func_reorder
*/
AFAPI af_err af_reorder(af_array *out, const af_array in,
const unsigned x, const unsigned y, const unsigned z, const unsigned w);
/**
C Interface to shift an array.
\param[out] out shifted array
\param[in] in input array
\param[in] x specifies the shift along first dimension
\param[in] y specifies the shift along second dimension
\param[in] z specifies the shift along third dimension
\param[in] w specifies the shift along fourth dimension
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup manip_func_shift
*/
AFAPI af_err af_shift(af_array *out, const af_array in, const int x, const int y, const int z, const int w);
/**
C Interface to modify the dimensions of an input array to a specified
shape.
\param[out] out modded output
\param[in] in input array
\param[in] ndims number of dimensions
\param[in] dims new dimension sizes
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup manip_func_moddims
*/
AFAPI af_err af_moddims(af_array *out, const af_array in, const unsigned ndims, const dim_t * const dims);
/**
C Interface to flatten an array.
\param[out] out flat array
\param[in] in input array
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup manip_func_flat
*/
AFAPI af_err af_flat(af_array *out, const af_array in);
/**
C Interface to flip an array.
\param[out] out flipped array
\param[in] in input array
\param[in] dim dimension to flip
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup manip_func_flip
*/
AFAPI af_err af_flip(af_array *out, const af_array in, const unsigned dim);
/**
C Interface to return the lower triangle array.
\param[out] out lower traingle array
\param[in] in input array
\param[in] is_unit_diag boolean specifying if diagonal elements are 1's
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_lower
*/
AFAPI af_err af_lower(af_array *out, const af_array in, bool is_unit_diag);
/**
C Interface to return the upper triangle array.
\param[out] out upper triangle array
\param[in] in input array
\param[in] is_unit_diag boolean specifying if diagonal elements are 1's
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_upper
*/
AFAPI af_err af_upper(af_array *out, const af_array in, bool is_unit_diag);
#if AF_API_VERSION >= 31
/**
C Interface to select elements based on a conditional array.
\param[out] out `a` when `cond` is true, else `b`
\param[in] cond conditional array
\param[in] a when true, select array element
\param[in] b when false, select array element
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_select
*/
AFAPI af_err af_select(af_array *out, const af_array cond, const af_array a, const af_array b);
#endif
#if AF_API_VERSION >= 31
/**
C Interface to select elements based on a conditional array.
\param[out] out `a` when `cond` is true, else `b`
\param[in] cond conditional array
\param[in] a when true, select array element
\param[in] b when false, select scalar value
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_select
*/
AFAPI af_err af_select_scalar_r(af_array *out, const af_array cond, const af_array a, const double b);
#endif
#if AF_API_VERSION >= 31
/**
C Interface to select elements based on a conditional array.
\param[out] out `a` when `cond` is true, else `b`
\param[in] cond conditional array
\param[in] a when true, select scalar value
\param[in] b when false, select array element
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_select
*/
AFAPI af_err af_select_scalar_l(af_array *out, const af_array cond, const double a, const af_array b);
#endif
#if AF_API_VERSION >= 31
/**
C Interface to replace elements of an array with elements of another
array.
Elements of `a` are replaced with corresponding elements of `b` when
`cond` is false.
\param[inout] a input array
\param[in] cond conditional array
\param[in] b replacement array
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_replace
*/
AFAPI af_err af_replace(af_array a, const af_array cond, const af_array b);
#endif
#if AF_API_VERSION >= 31
/**
C Interface to replace elements of an array with a scalar value.
Elements of `a` are replaced with a scalar value when `cond` is false.
\param[inout] a input array
\param[in] cond conditional array
\param[in] b replacement scalar value
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_replace
*/
AFAPI af_err af_replace_scalar(af_array a, const af_array cond, const double b);
#endif
#if AF_API_VERSION >= 37
/**
C Interface to pad an array.
\param[out] out padded array
\param[in] in input array
\param[in] begin_ndims number of dimensions for start padding
\param[in] begin_dims number of elements to be padded at the start
of each dimension
\param[in] end_ndims number of dimensions for end padding
\param[in] end_dims number of elements to be padded at the end of
each dimension
\param[in] pad_fill_type values to fill into the padded region
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_pad
*/
AFAPI af_err af_pad(af_array *out, const af_array in,
const unsigned begin_ndims,
const dim_t *const begin_dims, const unsigned end_ndims,
const dim_t *const end_dims,
const af_border_type pad_fill_type);
#endif
#if AF_API_VERSION >= 39
/**
C Interface to replace elements of an array with a scalar value.
Elements of `a` are replaced with a scalar value when `cond` is false.
\param[inout] a input array
\param[in] cond conditional array
\param[in] b replacement scalar value
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_replace
*/
AFAPI af_err af_replace_scalar_long(af_array a, const af_array cond,
const long long b);
/**
C Interface to replace elements of an array with a scalar value.
Elements of `a` are replaced with a scalar value when `cond` is false.
\param[inout] a input array
\param[in] cond conditional array
\param[in] b replacement scalar value
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_replace
*/
AFAPI af_err af_replace_scalar_ulong(af_array a, const af_array cond,
const unsigned long long b);
/**
C Interface to select elements based on a conditional array.
\param[out] out `a` when `cond` is true, else `b`
\param[in] cond conditional array
\param[in] a when true, select array element
\param[in] b when false, select scalar value
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_select
*/
AFAPI af_err af_select_scalar_r_long(af_array *out, const af_array cond,
const af_array a, const long long b);
/**
C Interface to select elements based on a conditional array.
\param[out] out `a` when `cond` is true, else `b`
\param[in] cond conditional array
\param[in] a when true, select array element
\param[in] b when false, select scalar value
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_select
*/
AFAPI af_err af_select_scalar_r_ulong(af_array *out, const af_array cond,
const af_array a,
const unsigned long long b);
/**
C Interface to select elements based on a conditional array.
\param[out] out `a` when `cond` is true, else `b`
\param[in] cond conditional array
\param[in] a when true, select scalar value
\param[in] b when false, select array element
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_select
*/
AFAPI af_err af_select_scalar_l_long(af_array *out, const af_array cond,
const long long a, const af_array b);
/**
C Interface to select elements based on a conditional array.
\param[out] out `a` when `cond` is true, else `b`
\param[in] cond conditional array
\param[in] a when true, select scalar value
\param[in] b when false, select array element
\return \ref AF_SUCCESS, if function returns successfully, else
an \ref af_err code is given
\ingroup data_func_select
*/
AFAPI af_err af_select_scalar_l_ulong(af_array *out, const af_array cond,
const unsigned long long a,