19 :
public boost::python::def_visitor<
20 SparseLUMatrixLReturnTypeVisitor<MappedSupernodalType>> {
21 typedef Eigen::SparseLUMatrixLReturnType<MappedSupernodalType> LType;
22 typedef typename MappedSupernodalType::Scalar Scalar;
23 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Eigen::ColMajor> VectorXs;
24 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
27 template <
typename MatrixOrVector>
28 static void solveInPlace(
const LType& self,
29 Eigen::Ref<MatrixOrVector> mat_vec) {
30 self.solveInPlace(mat_vec);
33 template <
class PyClass>
34 void visit(PyClass& cl)
const {
35 cl.def(bp::init<MappedSupernodalType>(bp::args(
"self",
"mapL")))
37 .def(
"rows", <ype::rows)
38 .def(
"cols", <ype::cols)
40 .def(
"solveInPlace", &solveInPlace<MatrixXs>, bp::args(
"self",
"X"))
41 .def(
"solveInPlace", &solveInPlace<VectorXs>, bp::args(
"self",
"x"));
44 static void expose(
const std::string& name) {
45 bp::class_<LType>(name.c_str(),
"Eigen SparseLUMatrixLReturnType",
54 :
public boost::python::def_visitor<
55 SparseLUMatrixUReturnTypeVisitor<MatrixLType, MatrixUType>> {
56 typedef Eigen::SparseLUMatrixUReturnType<MatrixLType, MatrixUType> UType;
57 typedef typename MatrixLType::Scalar Scalar;
58 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Eigen::ColMajor> VectorXs;
59 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
62 template <
typename MatrixOrVector>
63 static void solveInPlace(
const UType& self,
64 Eigen::Ref<MatrixOrVector> mat_vec) {
65 self.solveInPlace(mat_vec);
68 template <
class PyClass>
69 void visit(PyClass& cl)
const {
70 cl.def(bp::init<MatrixLType, MatrixUType>(bp::args(
"self",
"mapL",
"mapU")))
72 .def(
"rows", &UType::rows)
73 .def(
"cols", &UType::cols)
75 .def(
"solveInPlace", &solveInPlace<MatrixXs>, bp::args(
"self",
"X"))
76 .def(
"solveInPlace", &solveInPlace<VectorXs>, bp::args(
"self",
"x"));
79 static void expose(
const std::string& name) {
80 bp::class_<UType>(name.c_str(),
"Eigen SparseLUMatrixUReturnType",
91 SparseLUVisitor<_MatrixType, _Ordering>> {
93 typedef _MatrixType MatrixType;
95 typedef Eigen::SparseLU<MatrixType> Solver;
96 typedef typename MatrixType::Scalar Scalar;
97 typedef typename MatrixType::RealScalar RealScalar;
99 typedef typename Solver::SCMatrix SCMatrix;
100 typedef typename MatrixType::StorageIndex StorageIndex;
102#if EIGEN_VERSION_AT_LEAST(3, 4, 90) 103 typedef Eigen::Map<Eigen::SparseMatrix<Scalar, Eigen::ColMajor, StorageIndex>>
106 typedef Eigen::MappedSparseMatrix<Scalar, Eigen::ColMajor, StorageIndex>
109 typedef Eigen::SparseLUMatrixLReturnType<SCMatrix> LType;
110 typedef Eigen::SparseLUMatrixUReturnType<SCMatrix, MappedSparseMatrix> UType;
112 template <
class PyClass>
113 void visit(PyClass& cl)
const {
114 cl.def(bp::init<>(bp::arg(
"self"),
"Default constructor"))
115 .def(bp::init<MatrixType>(bp::args(
"self",
"matrix"),
116 "Constructs and performs the LU " 117 "factorization from a given matrix."))
119 .def(
"determinant", &Solver::determinant, bp::arg(
"self"),
120 "Returns the determinant of the matrix.")
121 .def(
"signDeterminant", &Solver::signDeterminant, bp::arg(
"self"),
122 "A number representing the sign of the determinant. ")
123 .def(
"absDeterminant", &Solver::absDeterminant, bp::arg(
"self"),
124 "Returns the absolute value of the determinant of the matrix of " 125 "which *this is the QR decomposition.")
126 .def(
"logAbsDeterminant", &Solver::logAbsDeterminant, bp::arg(
"self"),
127 "Returns the natural log of the absolute value of the determinant " 128 "of the matrix of which *this is the QR decomposition")
130 .def(
"rows", &Solver::rows, bp::arg(
"self"),
131 "Returns the number of rows of the matrix.")
132 .def(
"cols", &Solver::cols, bp::arg(
"self"),
133 "Returns the number of cols of the matrix.")
135 .def(
"nnzL", &Solver::nnzL, bp::arg(
"self"),
136 "The number of non zero elements in L")
137 .def(
"nnzU", &Solver::nnzU, bp::arg(
"self"),
138 "The number of non zero elements in U")
142 +[](
const Solver& self) -> LType {
return self.matrixL(); },
143 "Returns an expression of the matrix L.")
146 +[](
const Solver& self) -> UType {
return self.matrixU(); },
147 "Returns an expression of the matrix U.")
149 .def(
"colsPermutation", &Solver::colsPermutation, bp::arg(
"self"),
150 "Returns a reference to the column matrix permutation PTc such " 151 "that Pr A PTc = LU.",
152 bp::return_value_policy<bp::copy_const_reference>())
153 .def(
"rowsPermutation", &Solver::rowsPermutation, bp::arg(
"self"),
154 "Returns a reference to the row matrix permutation Pr such that " 156 bp::return_value_policy<bp::copy_const_reference>())
158 .def(
"compute", &Solver::compute, bp::args(
"self",
"matrix"),
159 "Compute the symbolic and numeric factorization of the input " 161 "The input matrix should be in column-major storage. ")
163 .def(
"analyzePattern", &Solver::analyzePattern,
164 bp::args(
"self",
"matrix"),
165 "Compute the column permutation to minimize the fill-in.")
166 .def(
"factorize", &Solver::factorize, bp::args(
"self",
"matrix"),
167 "Performs a numeric decomposition of a given matrix.\n" 168 "The given matrix must has the same sparcity than the matrix on " 169 "which the symbolic decomposition has been performed.")
171 .def(
"isSymmetric", &Solver::isSymmetric, bp::args(
"self",
"sym"),
172 "Indicate that the pattern of the input matrix is symmetric. ")
174 .def(
"setPivotThreshold", &Solver::setPivotThreshold,
175 bp::args(
"self",
"thresh"),
176 "Set the threshold used for a diagonal entry to be an acceptable " 179 .def(
"info", &Solver::info, bp::arg(
"self"),
180 "NumericalIssue if the input contains INF or NaN values or " 181 "overflow occured. Returns Success otherwise.")
182 .def(
"lastErrorMessage", &Solver::lastErrorMessage, bp::arg(
"self"),
183 "Returns a string describing the type of error. ")
189 static const std::string classname =
190 "SparseLU_" + scalar_name<Scalar>::shortname();
194 static void expose(
const std::string& name) {
195 bp::class_<Solver, boost::noncopyable>(
197 "Sparse supernodal LU factorization for general matrices. \n\n" 198 "This class implements the supernodal LU factorization for general " 200 "It uses the main techniques from the sequential SuperLU package " 201 "(http://crd-legacy.lbl.gov/~xiaoye/SuperLU/). It handles " 202 "transparently real " 203 "and complex arithmetic with single and double precision, depending on " 205 "type of your input matrix. The code has been optimized to provide " 207 "during supernode-panel updates. It benefits directly from the " 208 "built-in high-performant " 209 "Eigen BLAS routines. Moreover, when the size of a supernode is very " 211 "calls are avoided to enable a better optimization from the compiler. " 212 "For best performance, " 213 "you should compile it with NDEBUG flag to avoid the numerous bounds " 214 "checking on vectors.",