@@ -50,6 +50,37 @@ impl Layout {
50
50
Layout :: F ( _) => c:: Layout :: ColumnMajor ,
51
51
}
52
52
}
53
+
54
+ pub fn same_order ( & self , other : & Layout ) -> bool {
55
+ match * self {
56
+ Layout :: C ( _) => {
57
+ match * other {
58
+ Layout :: C ( _) => true ,
59
+ Layout :: F ( _) => false ,
60
+ }
61
+ }
62
+ Layout :: F ( _) => {
63
+ match * other {
64
+ Layout :: C ( _) => false ,
65
+ Layout :: F ( _) => true ,
66
+ }
67
+ }
68
+ }
69
+ }
70
+
71
+ pub fn as_shape ( & self ) -> Shape < Ix2 > {
72
+ match * self {
73
+ Layout :: C ( ( row, col) ) => ( row as usize , col as usize ) . into_shape ( ) ,
74
+ Layout :: F ( ( col, row) ) => ( row as usize , col as usize ) . f ( ) . into_shape ( ) ,
75
+ }
76
+ }
77
+
78
+ pub fn t ( & self ) -> Self {
79
+ match * self {
80
+ Layout :: C ( ( row, col) ) => Layout :: F ( ( col, row) ) ,
81
+ Layout :: F ( ( col, row) ) => Layout :: C ( ( row, col) ) ,
82
+ }
83
+ }
53
84
}
54
85
55
86
pub trait AllocatedArray {
@@ -133,10 +164,14 @@ impl<A, S> AllocatedArrayMut for ArrayBase<S, Ix1>
133
164
pub fn reconstruct < A , S > ( l : Layout , a : Vec < A > ) -> Result < ArrayBase < S , Ix2 > >
134
165
where S : DataOwned < Elem = A >
135
166
{
136
- Ok ( match l {
137
- Layout :: C ( ( row, col) ) => ArrayBase :: from_shape_vec ( ( row as usize , col as usize ) , a) ?,
138
- Layout :: F ( ( col, row) ) => ArrayBase :: from_shape_vec ( ( row as usize , col as usize ) . f ( ) , a) ?,
139
- } )
167
+ Ok ( ArrayBase :: from_shape_vec ( l. as_shape ( ) , a) ?)
168
+ }
169
+
170
+ pub fn uninitialized < A , S > ( l : Layout ) -> ArrayBase < S , Ix2 >
171
+ where A : Copy ,
172
+ S : DataOwned < Elem = A >
173
+ {
174
+ unsafe { ArrayBase :: uninitialized ( l. as_shape ( ) ) }
140
175
}
141
176
142
177
pub fn replicate < A , Sv , So , D > ( a : & ArrayBase < Sv , D > ) -> ArrayBase < So , D >
@@ -149,3 +184,13 @@ pub fn replicate<A, Sv, So, D>(a: &ArrayBase<Sv, D>) -> ArrayBase<So, D>
149
184
b. assign ( a) ;
150
185
b
151
186
}
187
+
188
+ pub fn clone_with_layout < A , Si , So > ( l : Layout , a : & ArrayBase < Si , Ix2 > ) -> ArrayBase < So , Ix2 >
189
+ where A : Copy ,
190
+ Si : Data < Elem = A > ,
191
+ So : DataOwned < Elem = A > + DataMut
192
+ {
193
+ let mut b = uninitialized ( l) ;
194
+ b. assign ( a) ;
195
+ b
196
+ }
0 commit comments