Skip to content

Commit f451bf4

Browse files
authored
Merge pull request #192 from doraneko94/clone_lu
Add Clone Trait to LUFactorized
2 parents c033cb9 + 358cf27 commit f451bf4

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/solve.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ pub trait Solve<A: Scalar> {
137137
}
138138

139139
/// Represents the LU factorization of a matrix `A` as `A = P*L*U`.
140-
pub struct LUFactorized<S: Data> {
140+
#[derive(Clone)]
141+
pub struct LUFactorized<S: Data + RawDataClone> {
141142
/// The factors `L` and `U`; the unit diagonal elements of `L` are not
142143
/// stored.
143144
pub a: ArrayBase<S, Ix2>,
@@ -148,7 +149,7 @@ pub struct LUFactorized<S: Data> {
148149
impl<A, S> Solve<A> for LUFactorized<S>
149150
where
150151
A: Scalar + Lapack,
151-
S: Data<Elem = A>,
152+
S: Data<Elem = A> + RawDataClone,
152153
{
153154
fn solve_inplace<'a, Sb>(&self, rhs: &'a mut ArrayBase<Sb, Ix1>) -> Result<&'a mut ArrayBase<Sb, Ix1>>
154155
where
@@ -226,14 +227,14 @@ where
226227
}
227228

228229
/// An interface for computing LU factorizations of matrix refs.
229-
pub trait Factorize<S: Data> {
230+
pub trait Factorize<S: Data + RawDataClone> {
230231
/// Computes the LU factorization `A = P*L*U`, where `P` is a permutation
231232
/// matrix.
232233
fn factorize(&self) -> Result<LUFactorized<S>>;
233234
}
234235

235236
/// An interface for computing LU factorizations of matrices.
236-
pub trait FactorizeInto<S: Data> {
237+
pub trait FactorizeInto<S: Data + RawDataClone> {
237238
/// Computes the LU factorization `A = P*L*U`, where `P` is a permutation
238239
/// matrix.
239240
fn factorize_into(self) -> Result<LUFactorized<S>>;
@@ -242,7 +243,7 @@ pub trait FactorizeInto<S: Data> {
242243
impl<A, S> FactorizeInto<S> for ArrayBase<S, Ix2>
243244
where
244245
A: Scalar + Lapack,
245-
S: DataMut<Elem = A>,
246+
S: DataMut<Elem = A> + RawDataClone,
246247
{
247248
fn factorize_into(mut self) -> Result<LUFactorized<S>> {
248249
let ipiv = unsafe { A::lu(self.layout()?, self.as_allocated_mut()?)? };
@@ -279,7 +280,7 @@ pub trait InverseInto {
279280
impl<A, S> InverseInto for LUFactorized<S>
280281
where
281282
A: Scalar + Lapack,
282-
S: DataMut<Elem = A>,
283+
S: DataMut<Elem = A> + RawDataClone,
283284
{
284285
type Output = ArrayBase<S, Ix2>;
285286

@@ -292,7 +293,7 @@ where
292293
impl<A, S> Inverse for LUFactorized<S>
293294
where
294295
A: Scalar + Lapack,
295-
S: Data<Elem = A>,
296+
S: Data<Elem = A> + RawDataClone,
296297
{
297298
type Output = Array2<A>;
298299

@@ -308,7 +309,7 @@ where
308309
impl<A, S> InverseInto for ArrayBase<S, Ix2>
309310
where
310311
A: Scalar + Lapack,
311-
S: DataMut<Elem = A>,
312+
S: DataMut<Elem = A> + RawDataClone,
312313
{
313314
type Output = Self;
314315

@@ -408,7 +409,7 @@ where
408409
impl<A, S> Determinant<A> for LUFactorized<S>
409410
where
410411
A: Scalar + Lapack,
411-
S: Data<Elem = A>,
412+
S: Data<Elem = A> + RawDataClone,
412413
{
413414
fn sln_det(&self) -> Result<(A, A::Real)> {
414415
self.a.ensure_square()?;
@@ -419,7 +420,7 @@ where
419420
impl<A, S> DeterminantInto<A> for LUFactorized<S>
420421
where
421422
A: Scalar + Lapack,
422-
S: Data<Elem = A>,
423+
S: Data<Elem = A> + RawDataClone,
423424
{
424425
fn sln_det_into(self) -> Result<(A, A::Real)> {
425426
self.a.ensure_square()?;
@@ -448,7 +449,7 @@ where
448449
impl<A, S> DeterminantInto<A> for ArrayBase<S, Ix2>
449450
where
450451
A: Scalar + Lapack,
451-
S: DataMut<Elem = A>,
452+
S: DataMut<Elem = A> + RawDataClone,
452453
{
453454
fn sln_det_into(self) -> Result<(A, A::Real)> {
454455
self.ensure_square()?;
@@ -494,7 +495,7 @@ pub trait ReciprocalConditionNumInto<A: Scalar> {
494495
impl<A, S> ReciprocalConditionNum<A> for LUFactorized<S>
495496
where
496497
A: Scalar + Lapack,
497-
S: Data<Elem = A>,
498+
S: Data<Elem = A> + RawDataClone,
498499
{
499500
fn rcond(&self) -> Result<A::Real> {
500501
unsafe { A::rcond(self.a.layout()?, self.a.as_allocated()?, self.a.opnorm_one()?) }
@@ -504,7 +505,7 @@ where
504505
impl<A, S> ReciprocalConditionNumInto<A> for LUFactorized<S>
505506
where
506507
A: Scalar + Lapack,
507-
S: Data<Elem = A>,
508+
S: Data<Elem = A> + RawDataClone,
508509
{
509510
fn rcond_into(self) -> Result<A::Real> {
510511
self.rcond()
@@ -524,7 +525,7 @@ where
524525
impl<A, S> ReciprocalConditionNumInto<A> for ArrayBase<S, Ix2>
525526
where
526527
A: Scalar + Lapack,
527-
S: DataMut<Elem = A>,
528+
S: DataMut<Elem = A> + RawDataClone,
528529
{
529530
fn rcond_into(self) -> Result<A::Real> {
530531
self.factorize_into()?.rcond_into()

0 commit comments

Comments
 (0)