@@ -9,24 +9,89 @@ use super::types::*;
9
9
10
10
pub use lapack_traits:: { Pivot , Transpose } ;
11
11
12
+ pub trait Solve < A : Scalar > {
13
+ fn solve < S : Data < Elem = A > > ( & self , a : & ArrayBase < S , Ix1 > ) -> Result < Array1 < A > > {
14
+ let mut a = replicate ( a) ;
15
+ self . solve_mut ( & mut a) ?;
16
+ Ok ( a)
17
+ }
18
+ fn solve_into < S : DataMut < Elem = A > > ( & self , mut a : ArrayBase < S , Ix1 > ) -> Result < ArrayBase < S , Ix1 > > {
19
+ self . solve_mut ( & mut a) ?;
20
+ Ok ( a)
21
+ }
22
+ fn solve_mut < ' a , S : DataMut < Elem = A > > ( & self , & ' a mut ArrayBase < S , Ix1 > ) -> Result < & ' a mut ArrayBase < S , Ix1 > > ;
23
+
24
+ fn solve_t < S : Data < Elem = A > > ( & self , a : & ArrayBase < S , Ix1 > ) -> Result < Array1 < A > > {
25
+ let mut a = replicate ( a) ;
26
+ self . solve_t_mut ( & mut a) ?;
27
+ Ok ( a)
28
+ }
29
+ fn solve_t_into < S : DataMut < Elem = A > > ( & self , mut a : ArrayBase < S , Ix1 > ) -> Result < ArrayBase < S , Ix1 > > {
30
+ self . solve_t_mut ( & mut a) ?;
31
+ Ok ( a)
32
+ }
33
+ fn solve_t_mut < ' a , S : DataMut < Elem = A > > ( & self , & ' a mut ArrayBase < S , Ix1 > ) -> Result < & ' a mut ArrayBase < S , Ix1 > > ;
34
+
35
+ fn solve_h < S : Data < Elem = A > > ( & self , a : & ArrayBase < S , Ix1 > ) -> Result < Array1 < A > > {
36
+ let mut a = replicate ( a) ;
37
+ self . solve_h_mut ( & mut a) ?;
38
+ Ok ( a)
39
+ }
40
+ fn solve_h_into < S : DataMut < Elem = A > > ( & self , mut a : ArrayBase < S , Ix1 > ) -> Result < ArrayBase < S , Ix1 > > {
41
+ self . solve_h_mut ( & mut a) ?;
42
+ Ok ( a)
43
+ }
44
+ fn solve_h_mut < ' a , S : DataMut < Elem = A > > ( & self , & ' a mut ArrayBase < S , Ix1 > ) -> Result < & ' a mut ArrayBase < S , Ix1 > > ;
45
+ }
46
+
12
47
pub struct Factorized < S : Data > {
13
48
pub a : ArrayBase < S , Ix2 > ,
14
49
pub ipiv : Pivot ,
15
50
}
16
51
17
- impl < A , S > Factorized < S >
52
+ impl < A , S > Solve < A > for Factorized < S >
18
53
where
19
54
A : Scalar ,
20
55
S : Data < Elem = A > ,
21
56
{
22
- pub fn solve < Sb > ( & self , t : Transpose , mut rhs : ArrayBase < Sb , Ix1 > ) -> Result < ArrayBase < Sb , Ix1 > >
57
+ fn solve_mut < ' a , Sb > ( & self , mut rhs : & ' a mut ArrayBase < Sb , Ix1 > ) -> Result < & ' a mut ArrayBase < Sb , Ix1 > >
58
+ where
59
+ Sb : DataMut < Elem = A > ,
60
+ {
61
+ unsafe {
62
+ A :: solve (
63
+ self . a . square_layout ( ) ?,
64
+ Transpose :: No ,
65
+ self . a . as_allocated ( ) ?,
66
+ & self . ipiv ,
67
+ rhs. as_slice_mut ( ) . unwrap ( ) ,
68
+ ) ?
69
+ } ;
70
+ Ok ( rhs)
71
+ }
72
+ fn solve_t_mut < ' a , Sb > ( & self , mut rhs : & ' a mut ArrayBase < Sb , Ix1 > ) -> Result < & ' a mut ArrayBase < Sb , Ix1 > >
73
+ where
74
+ Sb : DataMut < Elem = A > ,
75
+ {
76
+ unsafe {
77
+ A :: solve (
78
+ self . a . square_layout ( ) ?,
79
+ Transpose :: Transpose ,
80
+ self . a . as_allocated ( ) ?,
81
+ & self . ipiv ,
82
+ rhs. as_slice_mut ( ) . unwrap ( ) ,
83
+ ) ?
84
+ } ;
85
+ Ok ( rhs)
86
+ }
87
+ fn solve_h_mut < ' a , Sb > ( & self , mut rhs : & ' a mut ArrayBase < Sb , Ix1 > ) -> Result < & ' a mut ArrayBase < Sb , Ix1 > >
23
88
where
24
89
Sb : DataMut < Elem = A > ,
25
90
{
26
91
unsafe {
27
92
A :: solve (
28
93
self . a . square_layout ( ) ?,
29
- t ,
94
+ Transpose :: Hermite ,
30
95
self . a . as_allocated ( ) ?,
31
96
& self . ipiv ,
32
97
rhs. as_slice_mut ( ) . unwrap ( ) ,
@@ -36,6 +101,34 @@ where
36
101
}
37
102
}
38
103
104
+ impl < A , S > Solve < A > for ArrayBase < S , Ix2 >
105
+ where
106
+ A : Scalar ,
107
+ S : Data < Elem = A > ,
108
+ {
109
+ fn solve_mut < ' a , Sb > ( & self , mut rhs : & ' a mut ArrayBase < Sb , Ix1 > ) -> Result < & ' a mut ArrayBase < Sb , Ix1 > >
110
+ where
111
+ Sb : DataMut < Elem = A > ,
112
+ {
113
+ let f = self . factorize ( ) ?;
114
+ f. solve_mut ( rhs)
115
+ }
116
+ fn solve_t_mut < ' a , Sb > ( & self , mut rhs : & ' a mut ArrayBase < Sb , Ix1 > ) -> Result < & ' a mut ArrayBase < Sb , Ix1 > >
117
+ where
118
+ Sb : DataMut < Elem = A > ,
119
+ {
120
+ let f = self . factorize ( ) ?;
121
+ f. solve_t_mut ( rhs)
122
+ }
123
+ fn solve_h_mut < ' a , Sb > ( & self , mut rhs : & ' a mut ArrayBase < Sb , Ix1 > ) -> Result < & ' a mut ArrayBase < Sb , Ix1 > >
124
+ where
125
+ Sb : DataMut < Elem = A > ,
126
+ {
127
+ let f = self . factorize ( ) ?;
128
+ f. solve_h_mut ( rhs)
129
+ }
130
+ }
131
+
39
132
impl < A , S > Factorized < S >
40
133
where
41
134
A : Scalar ,
0 commit comments