@@ -62,7 +62,7 @@ impl Layout {
62
62
}
63
63
}
64
64
65
- pub fn t ( & self ) -> Self {
65
+ pub fn toggle_order ( & self ) -> Self {
66
66
match * self {
67
67
Layout :: C ( ( row, col) ) => Layout :: F ( ( col, row) ) ,
68
68
Layout :: F ( ( col, row) ) => Layout :: C ( ( row, col) ) ,
@@ -121,8 +121,26 @@ impl<A, S> AllocatedArrayMut for ArrayBase<S, Ix2>
121
121
}
122
122
}
123
123
124
+ pub fn into_col_vec < S > ( a : ArrayBase < S , Ix1 > ) -> ArrayBase < S , Ix2 >
125
+ where S : Data
126
+ {
127
+ let n = a. len ( ) ;
128
+ a. into_shape ( ( n, 1 ) ) . unwrap ( )
129
+ }
124
130
131
+ pub fn into_row_vec < S > ( a : ArrayBase < S , Ix1 > ) -> ArrayBase < S , Ix2 >
132
+ where S : Data
133
+ {
134
+ let n = a. len ( ) ;
135
+ a. into_shape ( ( 1 , n) ) . unwrap ( )
136
+ }
125
137
138
+ pub fn into_vec < S > ( a : ArrayBase < S , Ix2 > ) -> ArrayBase < S , Ix1 >
139
+ where S : Data
140
+ {
141
+ let n = a. len ( ) ;
142
+ a. into_shape ( ( n) ) . unwrap ( )
143
+ }
126
144
127
145
pub fn reconstruct < A , S > ( l : Layout , a : Vec < A > ) -> Result < ArrayBase < S , Ix2 > >
128
146
where S : DataOwned < Elem = A >
@@ -157,3 +175,13 @@ pub fn clone_with_layout<A, Si, So>(l: Layout, a: &ArrayBase<Si, Ix2>) -> ArrayB
157
175
b. assign ( a) ;
158
176
b
159
177
}
178
+
179
+ pub fn data_transpose < A , S > ( a : & mut ArrayBase < S , Ix2 > ) -> Result < & mut ArrayBase < S , Ix2 > >
180
+ where A : Copy ,
181
+ S : DataOwned < Elem = A > + DataMut
182
+ {
183
+ let l = a. layout ( ) ?. toggle_order ( ) ;
184
+ let new = clone_with_layout ( l, a) ;
185
+ :: std:: mem:: replace ( a, new) ;
186
+ Ok ( a)
187
+ }
0 commit comments