lapack/lu.cpp
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2010-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
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/.
9 
10 #include "common.h"
11 #include <Eigen/LU>
12 
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))
15 {
16  *info = 0;
17  if(*m<0) *info = -1;
18  else if(*n<0) *info = -2;
19  else if(*lda<std::max(1,*m)) *info = -4;
20  if(*info!=0)
21  {
22  int e = -*info;
23  return xerbla_(SCALAR_SUFFIX_UP"GETRF", &e, 6);
24  }
25 
26  if(*m==0 || *n==0)
27  return 0;
28 
29  Scalar* a = reinterpret_cast<Scalar*>(pa);
32  ::blocked_lu(*m, *n, a, *lda, ipiv, nb_transpositions));
33 
34  for(int i=0; i<std::min(*m,*n); ++i)
35  ipiv[i]++;
36 
37  if(ret>=0)
38  *info = ret+1;
39 
40  return 0;
41 }
42 
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))
47 {
48  *info = 0;
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;
54  if(*info!=0)
55  {
56  int e = -*info;
57  return xerbla_(SCALAR_SUFFIX_UP"GETRS", &e, 6);
58  }
59 
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);
64 
65  for(int i=0; i<*n; ++i)
66  ipiv[i]--;
67  if(OP(*trans)==NOTR)
68  {
69  B = PivotsType(ipiv,*n) * B;
70  lu.triangularView<UnitLower>().solveInPlace(B);
71  lu.triangularView<Upper>().solveInPlace(B);
72  }
73  else if(OP(*trans)==TR)
74  {
75  lu.triangularView<Upper>().transpose().solveInPlace(B);
76  lu.triangularView<UnitLower>().transpose().solveInPlace(B);
77  B = PivotsType(ipiv,*n).transpose() * B;
78  }
79  else if(OP(*trans)==ADJ)
80  {
81  lu.triangularView<Upper>().adjoint().solveInPlace(B);
82  lu.triangularView<UnitLower>().adjoint().solveInPlace(B);
83  B = PivotsType(ipiv,*n).transpose() * B;
84  }
85  for(int i=0; i<*n; ++i)
86  ipiv[i]++;
87 
88  return 0;
89 }
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
ret
int ret
Definition: lapack/lu.cpp:31
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
info
if m * info
Definition: lapack/lu.cpp:17
EIGEN_LAPACK_FUNC
#define EIGEN_LAPACK_FUNC(FUNC, ARGLIST)
Definition: lapack_common.h:16
Eigen::internal::partial_lu_impl
Definition: PartialPivLU.h:335
trans
static char trans
Definition: blas_interface.hh:58
B
Definition: test_numpy_dtypes.cpp:299
Eigen::Upper
@ Upper
Definition: Constants.h:211
ADJ
#define ADJ
Definition: gtsam/3rdparty/Eigen/blas/common.h:34
PivotsType
Eigen::Map< Eigen::Transpositions< Eigen::Dynamic, Eigen::Dynamic, int > > PivotsType
Definition: lapack_common.h:20
lda
else if * lda(1, *m)) *info=-4;if(*info!=0
Definition: lapack/lu.cpp:19
n
int n
Definition: BiCGSTAB_simple.cpp:1
NOTR
#define NOTR
Definition: gtsam/3rdparty/Eigen/blas/common.h:32
TR
#define TR
Definition: gtsam/3rdparty/Eigen/blas/common.h:33
B
MatrixType B(b, *n, *nrhs, *ldb)
lu
MatrixType lu(a, *n, *n, *lda)
SCALAR_SUFFIX_UP
#define SCALAR_SUFFIX_UP
Definition: blas/complex_double.cpp:12
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:47
nb_transpositions
int nb_transpositions
Definition: lapack/lu.cpp:30
xerbla_
EIGEN_WEAK_LINKING int xerbla_(const char *msg, int *info, int)
Definition: xerbla.cpp:15
a
Scalar * a
Definition: lapack/lu.cpp:29
OP
#define OP(X)
Definition: gtsam/3rdparty/Eigen/blas/common.h:47
b
Scalar * b
Definition: lapack/lu.cpp:61
min
#define min(a, b)
Definition: datatypes.h:19
Eigen::UnitLower
@ UnitLower
Definition: Constants.h:217
max
#define max(a, b)
Definition: datatypes.h:20
INVALID
#define INVALID
Definition: gtsam/3rdparty/Eigen/blas/common.h:45
adjoint
void adjoint(const MatrixType &m)
Definition: adjoint.cpp:67
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:57