File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -1854,13 +1854,25 @@ where
1854
1854
} else {
1855
1855
let mut v = self . view ( ) ;
1856
1856
// put the narrowest axis at the last position
1857
- if v. ndim ( ) > 1 {
1858
- let last = v. ndim ( ) - 1 ;
1859
- let narrow_axis = v. axes ( )
1860
- . filter ( |ax| ax. len ( ) > 1 )
1861
- . min_by_key ( |ax| ax. stride ( ) . abs ( ) )
1862
- . map_or ( last, |ax| ax. axis ( ) . index ( ) ) ;
1863
- v. swap_axes ( last, narrow_axis) ;
1857
+ match v. ndim ( ) {
1858
+ 0 | 1 => { }
1859
+ 2 => {
1860
+ if self . len_of ( Axis ( 1 ) ) <= 1
1861
+ || self . len_of ( Axis ( 0 ) ) > 1
1862
+ && self . stride_of ( Axis ( 0 ) ) . abs ( ) < self . stride_of ( Axis ( 1 ) ) . abs ( )
1863
+ {
1864
+ v. swap_axes ( 0 , 1 ) ;
1865
+ }
1866
+ }
1867
+ n => {
1868
+ let last = n - 1 ;
1869
+ let narrow_axis = v
1870
+ . axes ( )
1871
+ . filter ( |ax| ax. len ( ) > 1 )
1872
+ . min_by_key ( |ax| ax. stride ( ) . abs ( ) )
1873
+ . map_or ( last, |ax| ax. axis ( ) . index ( ) ) ;
1874
+ v. swap_axes ( last, narrow_axis) ;
1875
+ }
1864
1876
}
1865
1877
v. into_elements_base ( ) . fold ( init, f)
1866
1878
}
You can’t perform that action at this time.
0 commit comments