112 typedef _SparseCholeskyDecomposition CholeskyDecomposition;
113 typedef typename CholeskyDecomposition::MatrixType SparseMatrix;
114 typedef _Scalar Scalar;
119 RowsAtCompileTime = Eigen::Dynamic
122 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> Vector;
123 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Options> DenseMatrix;
127 struct DelassusOperatorSparseTpl
128 : DelassusOperatorBase<DelassusOperatorSparseTpl<_Scalar, _Options, SparseCholeskyDecomposition>>
130 typedef DelassusOperatorSparseTpl Self;
141 typedef SparseCholeskyDecomposition CholeskyDecomposition;
142 typedef DelassusOperatorBase<Self> Base;
144 template<
typename MatrixDerived>
145 explicit DelassusOperatorSparseTpl(
const Eigen::SparseMatrixBase<MatrixDerived> & mat)
147 , delassus_matrix(mat)
148 , delassus_matrix_plus_damping(mat)
150 , damping(Vector::Zero(mat.rows()))
153 PINOCCHIO_CHECK_ARGUMENT_SIZE(mat.rows(), mat.cols());
156 template<
typename VectorLike>
157 void updateDamping(
const Eigen::MatrixBase<VectorLike> & vec)
159 for (Eigen::DenseIndex k = 0; k < size(); ++k)
161 delassus_matrix_plus_damping.coeffRef(k, k) += -damping[k] + vec[k];
164 PINOCCHIO_EIGEN_MALLOC_SAVE_STATUS();
165 PINOCCHIO_EIGEN_MALLOC_ALLOWED();
166 llt.factorize(delassus_matrix_plus_damping);
167 PINOCCHIO_EIGEN_MALLOC_RESTORE_STATUS();
170 void updateDamping(
const Scalar & mu)
172 updateDamping(Vector::Constant(size(), mu));
175 template<
typename MatrixLike>
176 void solveInPlace(
const Eigen::MatrixBase<MatrixLike> & mat)
const 178 internal::SparseSolveInPlaceMethod<CholeskyDecomposition>::run(
179 llt, mat.derived(), mat.const_cast_derived(), tmp);
182 template<
typename MatrixLike>
183 typename PINOCCHIO_EIGEN_PLAIN_TYPE(MatrixLike)
184 solve(
const Eigen::MatrixBase<MatrixLike> & mat)
const 186 typename PINOCCHIO_EIGEN_PLAIN_TYPE(MatrixLike) res(mat);
191 template<
typename MatrixDerivedIn,
typename MatrixDerivedOut>
193 const Eigen::MatrixBase<MatrixDerivedIn> & x,
194 const Eigen::MatrixBase<MatrixDerivedOut> & res)
const 196 res.const_cast_derived() = x;
197 llt._solve_impl(x, res.const_cast_derived());
200 template<
typename MatrixIn,
typename MatrixOut>
201 void applyOnTheRight(
202 const Eigen::MatrixBase<MatrixIn> & x,
const Eigen::MatrixBase<MatrixOut> & res_)
const 204 MatrixOut & res = res_.const_cast_derived();
205 res.noalias() = delassus_matrix * x;
206 res.array() += damping.array() * x.array();
209 template<
typename MatrixDerived>
210 typename PINOCCHIO_EIGEN_PLAIN_TYPE(MatrixDerived)
211 operator*(
const Eigen::MatrixBase<MatrixDerived> & x)
const 213 typedef typename PINOCCHIO_EIGEN_PLAIN_TYPE(MatrixDerived)
ReturnType;
215 PINOCCHIO_CHECK_ARGUMENT_SIZE(x.rows(), size());
217 applyOnTheRight(x, res);
221 Eigen::DenseIndex size()
const 223 return delassus_matrix.rows();
225 Eigen::DenseIndex rows()
const 227 return delassus_matrix.rows();
229 Eigen::DenseIndex cols()
const 231 return delassus_matrix.cols();
234 SparseMatrix matrix()
const 236 delassus_matrix_plus_damping = delassus_matrix;
237 delassus_matrix_plus_damping += damping.asDiagonal();
238 return delassus_matrix_plus_damping;
241 SparseMatrix inverse()
const 243 SparseMatrix identity_matrix(size(), size());
244 identity_matrix.setIdentity();
245 SparseMatrix res = llt.solve(identity_matrix);
250 SparseMatrix delassus_matrix;
251 mutable SparseMatrix delassus_matrix_plus_damping;
252 CholeskyDecomposition llt;