1 // This file is part of Eigen, a lightweight C++ template library
4 // Copyright (C) 2010-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 // computes an LU factorization of a general M-by-N matrix A using partial pivoting with row interchanges
14 EIGEN_LAPACK_FUNC(getrf
,(int *m
, int *n
, RealScalar
*pa
, int *lda
, int *ipiv
, int *info
))
18 else if(*n
<0) *info
= -2;
19 else if(*lda
<std::max(1,*m
)) *info
= -4;
23 return xerbla_(SCALAR_SUFFIX_UP
"GETRF", &e
, 6);
29 Scalar
* a
= reinterpret_cast<Scalar
*>(pa
);
30 int nb_transpositions
;
31 int ret
= int(Eigen::internal::partial_lu_impl
<Scalar
,ColMajor
,int>
32 ::blocked_lu(*m
, *n
, a
, *lda
, ipiv
, nb_transpositions
));
34 for(int i
=0; i
<std::min(*m
,*n
); ++i
)
43 //GETRS solves a system of linear equations
44 // A * X = B or A' * X = B
45 // with a general N-by-N matrix A using the LU factorization computed by GETRF
46 EIGEN_LAPACK_FUNC(getrs
,(char *trans
, int *n
, int *nrhs
, RealScalar
*pa
, int *lda
, int *ipiv
, RealScalar
*pb
, int *ldb
, int *info
))
49 if(OP(*trans
)==INVALID
) *info
= -1;
50 else if(*n
<0) *info
= -2;
51 else if(*nrhs
<0) *info
= -3;
52 else if(*lda
<std::max(1,*n
)) *info
= -5;
53 else if(*ldb
<std::max(1,*n
)) *info
= -8;
57 return xerbla_(SCALAR_SUFFIX_UP
"GETRS", &e
, 6);
60 Scalar
* a
= reinterpret_cast<Scalar
*>(pa
);
61 Scalar
* b
= reinterpret_cast<Scalar
*>(pb
);
62 MatrixType
lu(a
,*n
,*n
,*lda
);
63 MatrixType
B(b
,*n
,*nrhs
,*ldb
);
65 for(int i
=0; i
<*n
; ++i
)
69 B
= PivotsType(ipiv
,*n
) * B
;
70 lu
.triangularView
<UnitLower
>().solveInPlace(B
);
71 lu
.triangularView
<Upper
>().solveInPlace(B
);
73 else if(OP(*trans
)==TR
)
75 lu
.triangularView
<Upper
>().transpose().solveInPlace(B
);
76 lu
.triangularView
<UnitLower
>().transpose().solveInPlace(B
);
77 B
= PivotsType(ipiv
,*n
).transpose() * B
;
79 else if(OP(*trans
)==ADJ
)
81 lu
.triangularView
<Upper
>().adjoint().solveInPlace(B
);
82 lu
.triangularView
<UnitLower
>().adjoint().solveInPlace(B
);
83 B
= PivotsType(ipiv
,*n
).transpose() * B
;
85 for(int i
=0; i
<*n
; ++i
)