Skip to content

Commit 6186cb5

Browse files
committed
Bug fix for as_shape replacement
1 parent 09b6d88 commit 6186cb5

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

ndarray-linalg/src/convert.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,30 @@ pub fn into_matrix<A, S>(l: MatrixLayout, a: Vec<A>) -> Result<ArrayBase<S, Ix2>
3535
where
3636
S: DataOwned<Elem = A>,
3737
{
38-
let (row, col) = l.size();
39-
Ok(ArrayBase::from_shape_vec((row as usize, col as usize), a)?)
38+
match l {
39+
MatrixLayout::C((row, col)) => {
40+
Ok(ArrayBase::from_shape_vec((row as usize, col as usize), a)?)
41+
}
42+
MatrixLayout::F((col, row)) => Ok(ArrayBase::from_shape_vec(
43+
(row as usize, col as usize).f(),
44+
a,
45+
)?),
46+
}
4047
}
4148

4249
fn uninitialized<A, S>(l: MatrixLayout) -> ArrayBase<S, Ix2>
4350
where
4451
A: Copy,
4552
S: DataOwned<Elem = A>,
4653
{
47-
let (row, col) = l.size();
48-
unsafe { ArrayBase::uninitialized((row as usize, col as usize)) }
54+
match l {
55+
MatrixLayout::C((row, col)) => unsafe {
56+
ArrayBase::uninitialized((row as usize, col as usize))
57+
},
58+
MatrixLayout::F((col, row)) => unsafe {
59+
ArrayBase::uninitialized((row as usize, col as usize).f())
60+
},
61+
}
4962
}
5063

5164
pub fn replicate<A, Sv, So, D>(a: &ArrayBase<Sv, D>) -> ArrayBase<So, D>

0 commit comments

Comments
 (0)