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;
101 typedef Eigen::MappedSparseMatrix<Scalar, Eigen::ColMajor, StorageIndex>
103 typedef Eigen::SparseLUMatrixLReturnType<SCMatrix> LType;
104 typedef Eigen::SparseLUMatrixUReturnType<SCMatrix, MappedSparseMatrix> UType;
106 template <
class PyClass>
107 void visit(PyClass &cl)
const {
108 cl.def(bp::init<>(bp::arg(
"self"),
"Default constructor"))
109 .def(bp::init<MatrixType>(bp::args(
"self",
"matrix"),
110 "Constructs and performs the LU " 111 "factorization from a given matrix."))
113 .def(
"determinant", &Solver::determinant, bp::arg(
"self"),
114 "Returns the determinant of the matrix.")
115 .def(
"signDeterminant", &Solver::signDeterminant, bp::arg(
"self"),
116 "A number representing the sign of the determinant. ")
117 .def(
"absDeterminant", &Solver::absDeterminant, bp::arg(
"self"),
118 "Returns the absolute value of the determinant of the matrix of " 119 "which *this is the QR decomposition.")
120 .def(
"logAbsDeterminant", &Solver::logAbsDeterminant, bp::arg(
"self"),
121 "Returns the natural log of the absolute value of the determinant " 122 "of the matrix of which *this is the QR decomposition")
124 .def(
"rows", &Solver::rows, bp::arg(
"self"),
125 "Returns the number of rows of the matrix.")
126 .def(
"cols", &Solver::cols, bp::arg(
"self"),
127 "Returns the number of cols of the matrix.")
129 .def(
"nnzL", &Solver::nnzL, bp::arg(
"self"),
130 "The number of non zero elements in L")
131 .def(
"nnzU", &Solver::nnzU, bp::arg(
"self"),
132 "The number of non zero elements in U")
136 +[](
const Solver &self) -> LType {
return self.matrixL(); },
137 "Returns an expression of the matrix L.")
140 +[](
const Solver &self) -> UType {
return self.matrixU(); },
141 "Returns an expression of the matrix U.")
143 .def(
"colsPermutation", &Solver::colsPermutation, bp::arg(
"self"),
144 "Returns a reference to the column matrix permutation PTc such " 145 "that Pr A PTc = LU.",
146 bp::return_value_policy<bp::copy_const_reference>())
147 .def(
"rowsPermutation", &Solver::rowsPermutation, bp::arg(
"self"),
148 "Returns a reference to the row matrix permutation Pr such that " 150 bp::return_value_policy<bp::copy_const_reference>())
152 .def(
"compute", &Solver::compute, bp::args(
"self",
"matrix"),
153 "Compute the symbolic and numeric factorization of the input " 155 "The input matrix should be in column-major storage. ")
157 .def(
"analyzePattern", &Solver::analyzePattern,
158 bp::args(
"self",
"matrix"),
159 "Compute the column permutation to minimize the fill-in.")
160 .def(
"factorize", &Solver::factorize, bp::args(
"self",
"matrix"),
161 "Performs a numeric decomposition of a given matrix.\n" 162 "The given matrix must has the same sparcity than the matrix on " 163 "which the symbolic decomposition has been performed.")
165 .def(
"isSymmetric", &Solver::isSymmetric, bp::args(
"self",
"sym"),
166 "Indicate that the pattern of the input matrix is symmetric. ")
168 .def(
"setPivotThreshold", &Solver::setPivotThreshold,
169 bp::args(
"self",
"thresh"),
170 "Set the threshold used for a diagonal entry to be an acceptable " 173 .def(
"info", &Solver::info, bp::arg(
"self"),
174 "NumericalIssue if the input contains INF or NaN values or " 175 "overflow occured. Returns Success otherwise.")
176 .def(
"lastErrorMessage", &Solver::lastErrorMessage, bp::arg(
"self"),
177 "Returns a string describing the type of error. ")
183 static const std::string classname =
184 "SparseLU_" + scalar_name<Scalar>::shortname();
188 static void expose(
const std::string &name) {
189 bp::class_<Solver, boost::noncopyable>(
191 "Sparse supernodal LU factorization for general matrices. \n\n" 192 "This class implements the supernodal LU factorization for general " 194 "It uses the main techniques from the sequential SuperLU package " 195 "(http://crd-legacy.lbl.gov/~xiaoye/SuperLU/). It handles " 196 "transparently real " 197 "and complex arithmetic with single and double precision, depending on " 199 "type of your input matrix. The code has been optimized to provide " 201 "during supernode-panel updates. It benefits directly from the " 202 "built-in high-performant " 203 "Eigen BLAS routines. Moreover, when the size of a supernode is very " 205 "calls are avoided to enable a better optimization from the compiler. " 206 "For best performance, " 207 "you should compile it with NDEBUG flag to avoid the numerous bounds " 208 "checking on vectors.",