Skip to content

Commit da0d5d1

Browse files
committed
Revise impl SolveTriangular
1 parent 4b36f97 commit da0d5d1

File tree

1 file changed

+46
-21
lines changed

1 file changed

+46
-21
lines changed

src/triangular.rs

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,74 @@ pub trait SolveTriangular<Rhs> {
1515
fn solve_triangular(&self, UPLO, Diag, Rhs) -> Result<Self::Output>;
1616
}
1717

18-
impl<A, Si, So, D> SolveTriangular<ArrayBase<So, D>> for ArrayBase<Si, Ix2>
19-
where A: LapackScalar,
18+
impl<A, Si, So> SolveTriangular<ArrayBase<So, Ix2>> for ArrayBase<Si, Ix2>
19+
where A: LapackScalar + Copy,
2020
Si: Data<Elem = A>,
21-
So: DataMut<Elem = A>,
22-
D: Dimension,
23-
ArrayBase<So, D>: AllocatedArrayMut<Elem = A>
21+
So: DataMut<Elem = A> + DataOwned
2422
{
25-
type Output = ArrayBase<So, D>;
23+
type Output = ArrayBase<So, Ix2>;
2624

27-
fn solve_triangular(&self, uplo: UPLO, diag: Diag, mut b: ArrayBase<So, D>) -> Result<Self::Output> {
25+
fn solve_triangular(&self, uplo: UPLO, diag: Diag, mut b: ArrayBase<So, Ix2>) -> Result<Self::Output> {
2826
self.solve_triangular(uplo, diag, &mut b)?;
2927
Ok(b)
3028
}
3129
}
3230

33-
impl<'a, A, Si, So, D> SolveTriangular<&'a mut ArrayBase<So, D>> for ArrayBase<Si, Ix2>
34-
where A: LapackScalar,
31+
impl<'a, A, Si, So> SolveTriangular<&'a mut ArrayBase<So, Ix2>> for ArrayBase<Si, Ix2>
32+
where A: LapackScalar + Copy,
3533
Si: Data<Elem = A>,
36-
So: DataMut<Elem = A>,
37-
D: Dimension,
38-
ArrayBase<So, D>: AllocatedArrayMut<Elem = A>
34+
So: DataMut<Elem = A> + DataOwned
3935
{
40-
type Output = &'a mut ArrayBase<So, D>;
36+
type Output = &'a mut ArrayBase<So, Ix2>;
4137

42-
fn solve_triangular(&self, uplo: UPLO, diag: Diag, mut b: &'a mut ArrayBase<So, D>) -> Result<Self::Output> {
38+
fn solve_triangular(&self, uplo: UPLO, diag: Diag, mut b: &'a mut ArrayBase<So, Ix2>) -> Result<Self::Output> {
4339
let la = self.layout()?;
44-
let lb = b.layout()?;
4540
let a_ = self.as_allocated()?;
41+
let lb = b.layout()?;
42+
if !la.same_order(&lb) {
43+
data_transpose(b)?;
44+
}
45+
let lb = b.layout()?;
4646
A::solve_triangular(la, lb, uplo, diag, a_, b.as_allocated_mut()?)?;
4747
Ok(b)
4848
}
4949
}
5050

51-
impl<'a, A, Si, So, D> SolveTriangular<&'a ArrayBase<So, D>> for ArrayBase<Si, Ix2>
51+
impl<'a, A, Si, So> SolveTriangular<&'a ArrayBase<So, Ix2>> for ArrayBase<Si, Ix2>
52+
where A: LapackScalar + Copy,
53+
Si: Data<Elem = A>,
54+
So: DataMut<Elem = A> + DataOwned
55+
{
56+
type Output = ArrayBase<So, Ix2>;
57+
58+
fn solve_triangular(&self, uplo: UPLO, diag: Diag, b: &'a ArrayBase<So, Ix2>) -> Result<Self::Output> {
59+
let b = replicate(b);
60+
self.solve_triangular(uplo, diag, b)
61+
}
62+
}
63+
64+
impl<A, Si, So> SolveTriangular<ArrayBase<So, Ix1>> for ArrayBase<Si, Ix2>
65+
where A: LapackScalar + Copy,
66+
Si: Data<Elem = A>,
67+
So: DataMut<Elem = A> + DataOwned
68+
{
69+
type Output = ArrayBase<So, Ix1>;
70+
71+
fn solve_triangular(&self, uplo: UPLO, diag: Diag, b: ArrayBase<So, Ix1>) -> Result<Self::Output> {
72+
let b = into_col_vec(b);
73+
let b = self.solve_triangular(uplo, diag, b)?;
74+
Ok(into_vec(b))
75+
}
76+
}
77+
78+
impl<'a, A, Si, So> SolveTriangular<&'a ArrayBase<So, Ix1>> for ArrayBase<Si, Ix2>
5279
where A: LapackScalar + Copy,
5380
Si: Data<Elem = A>,
54-
So: DataMut<Elem = A> + DataOwned,
55-
D: Dimension,
56-
ArrayBase<So, D>: AllocatedArrayMut<Elem = A>
81+
So: DataMut<Elem = A> + DataOwned
5782
{
58-
type Output = ArrayBase<So, D>;
83+
type Output = ArrayBase<So, Ix1>;
5984

60-
fn solve_triangular(&self, uplo: UPLO, diag: Diag, b: &'a ArrayBase<So, D>) -> Result<Self::Output> {
85+
fn solve_triangular(&self, uplo: UPLO, diag: Diag, b: &'a ArrayBase<So, Ix1>) -> Result<Self::Output> {
6186
let b = replicate(b);
6287
self.solve_triangular(uplo, diag, b)
6388
}

0 commit comments

Comments
 (0)