Skip to content

Commit 11d676f

Browse files
committed
Fix Inverse for LUFactorized
This fixes the result of `a.factorize_into()?.inv()?` when `a` is column-major.
1 parent c1a91d8 commit 11d676f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ndarray-linalg/src/solve.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,15 @@ where
323323
type Output = Array2<A>;
324324

325325
fn inv(&self) -> Result<Array2<A>> {
326+
// Preserve the existing layout. This is required to obtain the correct
327+
// result, because the result of `A::inv` is layout-dependent.
328+
let a = if self.a.is_standard_layout() {
329+
replicate(&self.a)
330+
} else {
331+
replicate(&self.a.t()).reversed_axes()
332+
};
326333
let f = LUFactorized {
327-
a: replicate(&self.a),
334+
a,
328335
ipiv: self.ipiv.clone(),
329336
};
330337
f.inv_into()

0 commit comments

Comments
 (0)