@@ -529,6 +529,16 @@ where
529
529
///# Return Values
530
530
///
531
531
/// Array with data reordered as per the new axes order
532
+ ///
533
+ ///# Examples
534
+ ///
535
+ /// ```rust
536
+ /// use arrayfire::{Array, Dim4, print, randu, reorder_v2};
537
+ /// let a = randu::<f32>(Dim4::new(&[5, 3, 1, 1]));
538
+ /// let b = reorder_v2(&a, 1, 0, None);
539
+ /// print(&a);
540
+ /// print(&b);
541
+ /// ```
532
542
pub fn reorder_v2 < T > (
533
543
input : & Array < T > ,
534
544
new_axis0 : u64 ,
@@ -538,16 +548,25 @@ pub fn reorder_v2<T>(
538
548
where
539
549
T : HasAfEnum ,
540
550
{
541
- let mut new_axes = vec ! [ new_axis0, new_axis1] ;
551
+ let mut new_axes = vec ! [ 0 , 1 , 2 , 3 ] ;
552
+ new_axes[ 0 ] = new_axis0;
553
+ new_axes[ 1 ] = new_axis1;
542
554
match next_axes {
543
- Some ( v) => {
544
- for axis in v {
545
- new_axes. push ( axis) ;
555
+ Some ( left_over_new_axes) => {
556
+ // At the moment of writing this comment, ArrayFire could
557
+ // handle only a maximum of 4 dimensions. Hence, excluding
558
+ // the two explicit axes arguments to this function, a maximum
559
+ // of only two more axes can be provided. Hence the below condition.
560
+ assert ! ( left_over_new_axes. len( ) <= 2 ) ;
561
+
562
+ for a_idx in 0 ..left_over_new_axes. len ( ) {
563
+ new_axes[ 2 + a_idx] = left_over_new_axes[ a_idx] ;
546
564
}
547
565
}
548
566
None => {
549
- new_axes. push ( 2 ) ;
550
- new_axes. push ( 3 ) ;
567
+ for a_idx in 2 ..4 {
568
+ new_axes[ a_idx] = a_idx as u64 ;
569
+ }
551
570
}
552
571
} ;
553
572
0 commit comments