@@ -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,112 @@ 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
+ /// - `next_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 > (
521
+ input : & Array < T > ,
522
+ new_axis0 : u64 ,
523
+ new_axis1 : u64 ,
524
+ next_axes : Option < Vec < u64 > > ,
525
+ ) -> Array < T >
526
+ where
527
+ T : HasAfEnum ,
528
+ {
529
+ let mut new_axes = vec ! [ new_axis0, new_axis1] ;
530
+ match next_axes {
531
+ Some ( v) => {
532
+ for axis in v {
533
+ new_axes. push ( axis) ;
499
534
}
500
- temp. into( )
535
+ }
536
+ None => {
537
+ new_axes. push ( 2 ) ;
538
+ new_axes. push ( 3 ) ;
501
539
}
502
540
} ;
541
+
542
+ let mut temp: i64 = 0 ;
543
+ unsafe {
544
+ let err_val = af_reorder (
545
+ & mut temp as MutAfArray ,
546
+ input. get ( ) as AfArray ,
547
+ new_axes[ 0 ] as c_uint ,
548
+ new_axes[ 1 ] as c_uint ,
549
+ new_axes[ 2 ] as c_uint ,
550
+ new_axes[ 3 ] as c_uint ,
551
+ ) ;
552
+ HANDLE_ERROR ( AfError :: from ( err_val) ) ;
553
+ }
554
+ temp. into ( )
503
555
}
504
556
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) ;
557
+ /// Reorder the array in specified order
558
+ ///
559
+ /// The default order of axes in ArrayFire is axis with smallest distance
560
+ /// between adjacent elements towards an axis with highest distance between
561
+ /// adjacent elements.
562
+ ///
563
+ ///# Parameters
564
+ ///
565
+ /// - `input` is the input Array
566
+ /// - `dims` is the target(output) dimensions
567
+ ///
568
+ ///# Return Values
569
+ ///
570
+ /// Array with data reordered as per the new axes order
571
+ #[ deprecated( since = "3.6.3" , note = "Please use new reorder API" ) ]
572
+ pub fn reorder < T > ( input : & Array < T > , dims : Dim4 ) -> Array < T >
573
+ where
574
+ T : HasAfEnum ,
575
+ {
576
+ reorder_v2 ( input, dims[ 0 ] , dims[ 1 ] , Some ( vec ! [ dims[ 2 ] , dims[ 3 ] ] ) )
577
+ }
511
578
512
579
///"Circular shift of values along specified dimension
513
580
///
0 commit comments