@@ -8,6 +8,7 @@ use crate::defines::AfError;
8
8
use crate :: dim4:: Dim4 ;
9
9
use crate :: error:: HANDLE_ERROR ;
10
10
use crate :: util:: { AfArray , DimT , HasAfEnum , Intl , MutAfArray , Uintl } ;
11
+ use std:: option:: Option ;
11
12
use std:: vec:: Vec ;
12
13
13
14
#[ allow( dead_code) ]
@@ -468,46 +469,113 @@ where
468
469
temp. into ( )
469
470
}
470
471
471
- macro_rules! data_func_def {
472
- ( $doc_str: expr, $fn_name: ident, $ffi_name: ident) => {
473
- #[ doc=$doc_str]
474
- ///
475
- ///# Parameters
476
- ///
477
- /// - `input` is the input Array
478
- /// - `dims` is the target(output) dimensions
479
- ///
480
- ///# Return Values
481
- ///
482
- /// An Array with modified data.
483
- #[ allow( unused_mut) ]
484
- pub fn $fn_name<T >( input: & Array <T >, dims: Dim4 ) -> Array <T >
485
- where
486
- T : HasAfEnum ,
487
- {
488
- let mut temp: i64 = 0 ;
489
- unsafe {
490
- let err_val = $ffi_name(
491
- & mut temp as MutAfArray ,
492
- input. get( ) as AfArray ,
493
- dims[ 0 ] as c_uint,
494
- dims[ 1 ] as c_uint,
495
- dims[ 2 ] as c_uint,
496
- dims[ 3 ] as c_uint,
497
- ) ;
498
- HANDLE_ERROR ( AfError :: from( err_val) ) ;
472
+ /// Tile the input array along specified dimension
473
+ ///
474
+ /// Tile essentially creates copies of data along each dimension.
475
+ /// The number of copies created is provided by the user on per
476
+ /// axis basis using [Dim4](./struct.dim4.html)
477
+ ///
478
+ ///# Parameters
479
+ ///
480
+ /// - `input` is the input Array
481
+ /// - `dims` is the target(output) dimensions
482
+ ///
483
+ ///# Return Values
484
+ ///
485
+ /// Tiled input array as per the tiling dimensions provided
486
+ #[ allow( unused_mut) ]
487
+ pub fn tile < T > ( input : & Array < T > , dims : Dim4 ) -> Array < T >
488
+ where
489
+ T : HasAfEnum ,
490
+ {
491
+ let mut temp: i64 = 0 ;
492
+ unsafe {
493
+ let err_val = af_tile (
494
+ & mut temp as MutAfArray ,
495
+ input. get ( ) as AfArray ,
496
+ dims[ 0 ] as c_uint ,
497
+ dims[ 1 ] as c_uint ,
498
+ dims[ 2 ] as c_uint ,
499
+ dims[ 3 ] as c_uint ,
500
+ ) ;
501
+ HANDLE_ERROR ( AfError :: from ( err_val) ) ;
502
+ }
503
+ temp. into ( )
504
+ }
505
+
506
+ /// Reorder the array in specified order
507
+ ///
508
+ /// The default order of axes in ArrayFire is axis with smallest distance
509
+ /// between adjacent elements towards an axis with highest distance between
510
+ /// adjacent elements.
511
+ ///
512
+ ///# Parameters
513
+ ///
514
+ /// - `input` is the input Array
515
+ /// - `new_axes` is the new axeses order for output
516
+ ///
517
+ ///# Return Values
518
+ ///
519
+ /// Array with data reordered as per the new axes order
520
+ pub fn reorder_v2 < T > ( input : & Array < T > , new_axes : Option < Vec < u64 > > ) -> Array < T >
521
+ where
522
+ T : HasAfEnum ,
523
+ {
524
+ let axes = match new_axes {
525
+ Some ( v) => {
526
+ let mut vec = Vec :: new ( ) ;
527
+ for axis in v {
528
+ vec. push ( axis) ;
529
+ }
530
+ for axis in vec. len ( ) ..4 {
531
+ vec. push ( axis as u64 ) ;
499
532
}
500
- temp . into ( )
533
+ vec
501
534
}
535
+ None => vec ! [ 0 , 1 , 2 , 3 ] ,
502
536
} ;
537
+
538
+ if axes == [ 0 , 1 , 2 , 3 ] {
539
+ // Early return if the default order of axes is not changed
540
+ return input. clone ( ) ;
541
+ }
542
+
543
+ let mut temp: i64 = 0 ;
544
+ unsafe {
545
+ let err_val = af_reorder (
546
+ & mut temp as MutAfArray ,
547
+ input. get ( ) as AfArray ,
548
+ axes[ 0 ] as c_uint ,
549
+ axes[ 1 ] as c_uint ,
550
+ axes[ 2 ] as c_uint ,
551
+ axes[ 3 ] as c_uint ,
552
+ ) ;
553
+ HANDLE_ERROR ( AfError :: from ( err_val) ) ;
554
+ }
555
+ temp. into ( )
503
556
}
504
557
505
- data_func_def ! (
506
- "Tile the input array along specified dimension" ,
507
- tile,
508
- af_tile
509
- ) ;
510
- data_func_def ! ( "Reorder the array in specified order" , reorder, af_reorder) ;
558
+ /// Reorder the array in specified order
559
+ ///
560
+ /// The default order of axes in ArrayFire is axis with smallest distance
561
+ /// between adjacent elements towards an axis with highest distance between
562
+ /// adjacent elements.
563
+ ///
564
+ ///# Parameters
565
+ ///
566
+ /// - `input` is the input Array
567
+ /// - `dims` is the target(output) dimensions
568
+ ///
569
+ ///# Return Values
570
+ ///
571
+ /// Array with data reordered as per the new axes order
572
+ #[ deprecated( since = "3.6.3" , note = "Please use new reorder API" ) ]
573
+ pub fn reorder < T > ( input : & Array < T > , dims : Dim4 ) -> Array < T >
574
+ where
575
+ T : HasAfEnum ,
576
+ {
577
+ reorder_v2 ( input, Some ( vec ! [ dims[ 0 ] , dims[ 1 ] , dims[ 2 ] , dims[ 3 ] ] ) )
578
+ }
511
579
512
580
///"Circular shift of values along specified dimension
513
581
///
0 commit comments