19 :
public boost::python::def_visitor<
20 SparseQRMatrixQTransposeReturnTypeVisitor<SparseQRType>> {
21 typedef typename SparseQRType::Scalar Scalar;
22 typedef Eigen::SparseQRMatrixQTransposeReturnType<SparseQRType>
24 typedef Eigen::VectorXd VectorXd;
25 typedef Eigen::MatrixXd MatrixXd;
27 template <
class PyClass>
28 void visit(PyClass& cl)
const {
29 cl.def(bp::init<const SparseQRType&>(bp::args(
"self",
"qr")))
32 +[](QTransposeType& self,
const MatrixXd& other) -> MatrixXd {
33 return MatrixXd(self * other);
35 bp::args(
"self",
"other"))
39 +[](QTransposeType& self,
const VectorXd& other) -> VectorXd {
40 return VectorXd(self * other);
42 bp::args(
"self",
"other"));
46 static const std::string classname =
"SparseQRMatrixQTransposeReturnType_" +
47 scalar_name<Scalar>::shortname();
51 static void expose(
const std::string& name) {
52 bp::class_<QTransposeType>(
53 name.c_str(),
"Eigen SparseQRMatrixQTransposeReturnType", bp::no_init)
61 :
public boost::python::def_visitor<
62 SparseQRMatrixQReturnTypeVisitor<SparseQRType>> {
63 typedef typename SparseQRType::Scalar Scalar;
64 typedef Eigen::SparseQRMatrixQTransposeReturnType<SparseQRType>
66 typedef Eigen::SparseQRMatrixQReturnType<SparseQRType> QType;
67 typedef typename SparseQRType::QRMatrixType QRMatrixType;
68 typedef Eigen::VectorXd VectorXd;
69 typedef Eigen::MatrixXd MatrixXd;
71 template <
class PyClass>
72 void visit(PyClass& cl)
const {
73 cl.def(bp::init<const SparseQRType&>(bp::args(
"self",
"qr")))
76 +[](QType& self,
const MatrixXd& other) -> MatrixXd {
77 return MatrixXd(self * other);
79 bp::args(
"self",
"other"))
83 +[](QType& self,
const VectorXd& other) -> VectorXd {
84 return VectorXd(self * other);
86 bp::args(
"self",
"other"))
88 .def(
"rows", &QType::rows)
89 .def(
"cols", &QType::cols)
93 +[](
const QType& self) -> QTransposeType {
return self.adjoint(); })
97 +[](
const QType& self) -> QTransposeType {
98 return self.transpose();
103 +[](QType& self) -> QRMatrixType {
104 Eigen::Index m = self.rows();
105 MatrixXd I = MatrixXd::Identity(m, m);
106 MatrixXd Q_dense = self * I;
107 return Q_dense.sparseView();
110 "Convert the Q matrix to a sparse matrix representation.");
114 static const std::string classname =
115 "SparseQRMatrixQReturnType_" + scalar_name<Scalar>::shortname();
119 static void expose(
const std::string& name) {
120 bp::class_<QType>(name.c_str(),
"Eigen SparseQRMatrixQReturnType",
129 :
public boost::python::def_visitor<SparseQRVisitor<SparseQRType>> {
130 typedef typename SparseQRType::MatrixType MatrixType;
132 typedef typename MatrixType::Scalar Scalar;
133 typedef typename MatrixType::RealScalar RealScalar;
134 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, MatrixType::Options>
136 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic,
140 typedef typename SparseQRType::QRMatrixType QRMatrixType;
141 typedef Eigen::SparseQRMatrixQReturnType<SparseQRType> QType;
143 template <
class PyClass>
144 void visit(PyClass& cl)
const {
145 cl.def(bp::init<>(bp::arg(
"self"),
"Default constructor"))
146 .def(bp::init<MatrixType>(
147 bp::args(
"self",
"mat"),
148 "Construct a QR factorization of the matrix mat."))
150 .def(
"cols", &SparseQRType::cols, bp::arg(
"self"),
151 "Returns the number of columns of the represented matrix. ")
152 .def(
"rows", &SparseQRType::rows, bp::arg(
"self"),
153 "Returns the number of rows of the represented matrix. ")
155 .def(
"compute", &SparseQRType::compute, bp::args(
"self",
"matrix"),
156 "Compute the symbolic and numeric factorization of the input " 158 "The input matrix should be in column-major storage. ")
159 .def(
"analyzePattern", &SparseQRType::analyzePattern,
160 bp::args(
"self",
"mat"),
161 "Compute the column permutation to minimize the fill-in.")
162 .def(
"factorize", &SparseQRType::factorize, bp::args(
"self",
"matrix"),
163 "Performs a numeric decomposition of a given matrix.\n" 164 "The given matrix must has the same sparcity than the matrix on " 165 "which the symbolic decomposition has been performed.")
167 .def(
"colsPermutation", &SparseQRType::colsPermutation, bp::arg(
"self"),
168 "Returns a reference to the column matrix permutation PTc such " 169 "that Pr A PTc = LU.",
170 bp::return_value_policy<bp::copy_const_reference>())
172 .def(
"info", &SparseQRType::info, bp::arg(
"self"),
173 "NumericalIssue if the input contains INF or NaN values or " 174 "overflow occured. Returns Success otherwise.")
175 .def(
"lastErrorMessage", &SparseQRType::lastErrorMessage,
176 bp::arg(
"self"),
"Returns a string describing the type of error. ")
178 .def(
"rank", &SparseQRType::rank, bp::arg(
"self"),
179 "Returns the number of non linearly dependent columns as " 181 "by the pivoting threshold. ")
185 +[](
const SparseQRType& self) -> QType {
return self.matrixQ(); },
186 "Returns an expression of the matrix Q as products of sparse " 187 "Householder reflectors.")
190 +[](
const SparseQRType& self) ->
const QRMatrixType& {
191 return self.matrixR();
193 "Returns a const reference to the \b sparse upper triangular " 195 "R of the QR factorization.",
196 bp::return_value_policy<bp::copy_const_reference>())
198 .def(
"setPivotThreshold", &SparseQRType::setPivotThreshold,
199 bp::args(
"self",
"thresh"),
200 "Set the threshold used for a diagonal entry to be an acceptable " 207 static const std::string classname =
208 "SparseQR_" + scalar_name<Scalar>::shortname();
212 static void expose(
const std::string& name) {
213 bp::class_<SparseQRType, boost::noncopyable>(
215 "Sparse left-looking QR factorization with numerical column pivoting. " 216 "This class implements a left-looking QR decomposition of sparse " 218 "with numerical column pivoting. When a column has a norm less than a " 220 "tolerance it is implicitly permuted to the end. The QR factorization " 222 "obtained is given by A*P = Q*R where R is upper triangular or " 224 "P is the column permutation which is the product of the fill-reducing " 226 "numerical permutations. \n\n" 227 "Q is the orthogonal matrix represented as products of Householder " 229 "R is the sparse triangular or trapezoidal matrix. The later occurs " 230 "when A is rank-deficient. \n\n",