@@ -8,6 +8,7 @@ use crate::defines::AfError;
88use crate :: dim4:: Dim4 ;
99use crate :: error:: HANDLE_ERROR ;
1010use crate :: util:: { AfArray , DimT , HasAfEnum , Intl , MutAfArray , Uintl } ;
11+ use std:: option:: Option ;
1112use std:: vec:: Vec ;
1213
1314#[ allow( dead_code) ]
@@ -468,46 +469,114 @@ where
468469 temp. into ( )
469470}
470471
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_axis0` is the new first axis for output
516+ /// - `new_axis1` is the new second axis for output
517+ /// - `next_axes` is the new axes order for output
518+ ///
519+ ///# Return Values
520+ ///
521+ /// Array with data reordered as per the new axes order
522+ pub fn reorder_v2 < T > (
523+ input : & Array < T > ,
524+ new_axis0 : u64 ,
525+ new_axis1 : u64 ,
526+ next_axes : Option < Vec < u64 > > ,
527+ ) -> Array < T >
528+ where
529+ T : HasAfEnum ,
530+ {
531+ let mut new_axes = vec ! [ new_axis0, new_axis1] ;
532+ match next_axes {
533+ Some ( v) => {
534+ for axis in v {
535+ new_axes. push ( axis) ;
499536 }
500- temp. into( )
537+ }
538+ None => {
539+ new_axes. push ( 2 ) ;
540+ new_axes. push ( 3 ) ;
501541 }
502542 } ;
543+
544+ let mut temp: i64 = 0 ;
545+ unsafe {
546+ let err_val = af_reorder (
547+ & mut temp as MutAfArray ,
548+ input. get ( ) as AfArray ,
549+ new_axes[ 0 ] as c_uint ,
550+ new_axes[ 1 ] as c_uint ,
551+ new_axes[ 2 ] as c_uint ,
552+ new_axes[ 3 ] as c_uint ,
553+ ) ;
554+ HANDLE_ERROR ( AfError :: from ( err_val) ) ;
555+ }
556+ temp. into ( )
503557}
504558
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) ;
559+ /// Reorder the array in specified order
560+ ///
561+ /// The default order of axes in ArrayFire is axis with smallest distance
562+ /// between adjacent elements towards an axis with highest distance between
563+ /// adjacent elements.
564+ ///
565+ ///# Parameters
566+ ///
567+ /// - `input` is the input Array
568+ /// - `dims` is the target(output) dimensions
569+ ///
570+ ///# Return Values
571+ ///
572+ /// Array with data reordered as per the new axes order
573+ #[ deprecated( since = "3.6.3" , note = "Please use new reorder API" ) ]
574+ pub fn reorder < T > ( input : & Array < T > , dims : Dim4 ) -> Array < T >
575+ where
576+ T : HasAfEnum ,
577+ {
578+ reorder_v2 ( input, dims[ 0 ] , dims[ 1 ] , Some ( vec ! [ dims[ 2 ] , dims[ 3 ] ] ) )
579+ }
511580
512581///"Circular shift of values along specified dimension
513582///
0 commit comments