Skip to content

Commit e6423ce

Browse files
committed
Merge codes for both majors
1 parent 3c508c4 commit e6423ce

File tree

2 files changed

+30
-41
lines changed

2 files changed

+30
-41
lines changed

src/matrix.rs

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -141,53 +141,39 @@ impl<A> Matrix for Array<A, (Ix, Ix)>
141141
let (n, m) = self.size();
142142
println!("n={}, m={}", n, m);
143143
let k = min(n, m);
144-
let (p, l) = ImplSolve::lu(self.layout(), n, m, self.clone().into_raw_vec())?;
145-
match self.layout() {
144+
let (p, mut a) = match self.layout() {
146145
Layout::ColumnMajor => {
147146
println!("ColumnMajor");
148-
let mut a = Array::from_vec(l).into_shape((m, n)).unwrap().reversed_axes();
149-
println!("a (after LU) = \n{:?}", &a);
150-
let mut lm = Array::zeros((n, k));
151-
for ((i, j), val) in lm.indexed_iter_mut() {
152-
if i > j {
153-
*val = a[(i, j)];
154-
} else if i == j {
155-
*val = A::one();
156-
}
157-
}
158-
for ((i, j), val) in a.indexed_iter_mut() {
159-
if i > j {
160-
*val = A::zero();
161-
}
162-
}
163-
let am = if n > k {
164-
a.slice(s![0..k as isize, ..]).to_owned()
165-
} else {
166-
a
167-
};
168-
println!("am = \n{:?}", am);
169-
Ok((p, lm, am))
147+
let (p, l) = ImplSolve::lu(self.layout(), n, m, self.clone().into_raw_vec())?;
148+
(p, Array::from_vec(l).into_shape((m, n)).unwrap().reversed_axes())
170149
}
171150
Layout::RowMajor => {
172151
println!("RowMajor");
173-
let mut lm = Array::from_vec(l).into_shape((m, n)).unwrap();
174-
println!("a (after LU) = \n{:?}", &lm);
175-
let mut um = Array::zeros((n, m));
176-
for ((i, j), val) in um.indexed_iter_mut() {
177-
if i <= j {
178-
*val = lm[(i, j)];
179-
}
180-
}
181-
for ((i, j), val) in lm.indexed_iter_mut() {
182-
if i < j {
183-
*val = A::zero();
184-
} else if i == j {
185-
*val = A::one();
186-
}
187-
}
188-
Ok((p, lm, um))
152+
let (p, l) = ImplSolve::lu(self.layout(), n, m, self.clone().into_raw_vec())?;
153+
(p, Array::from_vec(l).into_shape((n, m)).unwrap())
154+
}
155+
};
156+
println!("a (after LU) = \n{:?}", &a);
157+
let mut lm = Array::zeros((n, k));
158+
for ((i, j), val) in lm.indexed_iter_mut() {
159+
if i > j {
160+
*val = a[(i, j)];
161+
} else if i == j {
162+
*val = A::one();
189163
}
190164
}
165+
for ((i, j), val) in a.indexed_iter_mut() {
166+
if i > j {
167+
*val = A::zero();
168+
}
169+
}
170+
let am = if n > k {
171+
a.slice(s![0..k as isize, ..]).to_owned()
172+
} else {
173+
a
174+
};
175+
println!("am = \n{:?}", am);
176+
Ok((p, lm, am))
191177
}
192178
fn permutate(&mut self, ipiv: &Self::Permutator) {
193179
let (_, m) = self.size();

src/solve.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ impl ImplSolve for $scalar {
3636
let m = m as i32;
3737
let n = n as i32;
3838
let k = min(m, n);
39-
let lda = m;
39+
let lda = match layout {
40+
Layout::ColumnMajor => m,
41+
Layout::RowMajor => n,
42+
};
4043
let mut ipiv = vec![0; k as usize];
4144
let info = $getrf(layout, m, n, &mut a, lda, &mut ipiv);
4245
if info == 0 {

0 commit comments

Comments
 (0)