File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 3636 /// ```
3737 pub fn triu ( & self , k : isize ) -> Array < A , D >
3838 {
39- match self . ndim ( ) > 1 && is_layout_f ( & self . dim , & self . strides ) {
39+ if self . ndim ( ) <= 1 {
40+ return self . to_owned ( ) ;
41+ }
42+ match is_layout_f ( & self . dim , & self . strides ) {
4043 true => {
4144 let n = self . ndim ( ) ;
4245 let mut x = self . view ( ) ;
7881 /// ```
7982 pub fn tril ( & self , k : isize ) -> Array < A , D >
8083 {
81- match self . ndim ( ) > 1 && is_layout_f ( & self . dim , & self . strides ) {
84+ if self . ndim ( ) <= 1 {
85+ return self . to_owned ( ) ;
86+ }
87+ match is_layout_f ( & self . dim , & self . strides ) {
8288 true => {
8389 let n = self . ndim ( ) ;
8490 let mut x = self . view ( ) ;
@@ -90,12 +96,12 @@ where
9096 }
9197 false => {
9298 let mut res = Array :: zeros ( self . raw_dim ( ) ) ;
99+ let ncols = self . len_of ( Axis ( self . ndim ( ) - 1 ) ) as isize ;
93100 Zip :: indexed ( self . rows ( ) )
94101 . and ( res. rows_mut ( ) )
95102 . for_each ( |i, src, mut dst| {
96103 // This ncols must go inside the loop to avoid panic on 1D arrays.
97104 // Statistically-neglible difference in performance vs defining ncols at top.
98- let ncols = src. len_of ( Axis ( src. ndim ( ) - 1 ) ) as isize ;
99105 let row_num = i. into_dimension ( ) . last_elem ( ) ;
100106 let upper = min ( row_num as isize + k, ncols) + 1 ;
101107 dst. slice_mut ( s ! [ ..upper] ) . assign ( & src. slice ( s ! [ ..upper] ) ) ;
You can’t perform that action at this time.
0 commit comments