1
1
2
- use ndarray:: { Data , Ix1 , Ix2 , Array , RcArray , NdFloat , ArrayBase , DataMut } ;
2
+ use ndarray:: { Ix1 , Ix2 , Array , RcArray , NdFloat , ArrayBase , DataMut } ;
3
3
4
4
use matrix:: { Matrix , MFloat } ;
5
5
use square:: SquareMatrix ;
@@ -9,49 +9,39 @@ use solve::ImplSolve;
9
9
pub trait TriangularMatrix < Rhs > : Matrix + SquareMatrix {
10
10
type Output ;
11
11
/// solve a triangular system with upper triangular matrix
12
- fn solve_upper ( & self , & Rhs ) -> Result < Self :: Output , LinalgError > ;
12
+ fn solve_upper ( & self , Rhs ) -> Result < Self :: Output , LinalgError > ;
13
13
/// solve a triangular system with lower triangular matrix
14
- fn solve_lower ( & self , & Rhs ) -> Result < Self :: Output , LinalgError > ;
14
+ fn solve_lower ( & self , Rhs ) -> Result < Self :: Output , LinalgError > ;
15
15
}
16
16
17
- impl < A , S > TriangularMatrix < ArrayBase < S , Ix1 > > for Array < A , Ix2 >
18
- where A : MFloat ,
19
- S : Data < Elem = A >
20
- {
17
+ impl < A : MFloat > TriangularMatrix < Array < A , Ix1 > > for Array < A , Ix2 > {
21
18
type Output = Array < A , Ix1 > ;
22
-
23
- fn solve_upper ( & self , b : & ArrayBase < S , Ix1 > ) -> Result < Self :: Output , LinalgError > {
24
- self . check_square ( ) ?;
25
- let ( n, _) = self . size ( ) ;
19
+ fn solve_upper ( & self , b : Array < A , Ix1 > ) -> Result < Self :: Output , LinalgError > {
20
+ let n = self . square_size ( ) ?;
26
21
let layout = self . layout ( ) ?;
27
22
let a = self . as_slice_memory_order ( ) . unwrap ( ) ;
28
- let x = ImplSolve :: solve_triangle ( layout, 'U' as u8 , n, a, b. to_owned ( ) . into_raw_vec ( ) , 1 ) ?;
23
+ let x = ImplSolve :: solve_triangle ( layout, 'U' as u8 , n, a, b. into_raw_vec ( ) , 1 ) ?;
29
24
Ok ( Array :: from_vec ( x) )
30
25
}
31
- fn solve_lower ( & self , b : & ArrayBase < S , Ix1 > ) -> Result < Self :: Output , LinalgError > {
32
- self . check_square ( ) ?;
33
- let ( n, _) = self . size ( ) ;
26
+ fn solve_lower ( & self , b : Array < A , Ix1 > ) -> Result < Self :: Output , LinalgError > {
27
+ let n = self . square_size ( ) ?;
34
28
let layout = self . layout ( ) ?;
35
29
let a = self . as_slice_memory_order ( ) . unwrap ( ) ;
36
- let x = ImplSolve :: solve_triangle ( layout, 'L' as u8 , n, a, b. to_owned ( ) . into_raw_vec ( ) , 1 ) ?;
30
+ let x = ImplSolve :: solve_triangle ( layout, 'L' as u8 , n, a, b. into_raw_vec ( ) , 1 ) ?;
37
31
Ok ( Array :: from_vec ( x) )
38
32
}
39
33
}
40
34
41
- impl < A , S > TriangularMatrix < ArrayBase < S , Ix1 > > for RcArray < A , Ix2 >
42
- where A : MFloat ,
43
- S : Data < Elem = A >
44
- {
35
+ impl < A : MFloat > TriangularMatrix < RcArray < A , Ix1 > > for RcArray < A , Ix2 > {
45
36
type Output = RcArray < A , Ix1 > ;
46
-
47
- fn solve_upper ( & self , b : & ArrayBase < S , Ix1 > ) -> Result < Self :: Output , LinalgError > {
37
+ fn solve_upper ( & self , b : RcArray < A , Ix1 > ) -> Result < Self :: Output , LinalgError > {
48
38
// XXX unnecessary clone
49
- let x = self . to_owned ( ) . solve_upper ( & b ) ?;
39
+ let x = self . to_owned ( ) . solve_upper ( b . into_owned ( ) ) ?;
50
40
Ok ( x. into_shared ( ) )
51
41
}
52
- fn solve_lower ( & self , b : & ArrayBase < S , Ix1 > ) -> Result < Self :: Output , LinalgError > {
42
+ fn solve_lower ( & self , b : RcArray < A , Ix1 > ) -> Result < Self :: Output , LinalgError > {
53
43
// XXX unnecessary clone
54
- let x = self . to_owned ( ) . solve_lower ( & b ) ?;
44
+ let x = self . to_owned ( ) . solve_lower ( b . into_owned ( ) ) ?;
55
45
Ok ( x. into_shared ( ) )
56
46
}
57
47
}
0 commit comments