10 #include <cppad/cppad.hpp> 21 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
23 SparsityPattern() =
default;
25 virtual ~SparsityPattern() =
default;
35 template <
int ROWS,
int COLS>
36 void initPattern(
const Eigen::Matrix<bool, ROWS, COLS>& sparsity)
40 const size_t rows = sparsity.rows();
41 const size_t cols = sparsity.cols();
43 sparsity_.resize(rows * cols);
45 for (
size_t i = 0;
i < rows * cols;
i++)
46 sparsity_[i] = sparsity.array()(
i);
48 size_t jacEntries = sparsity.template cast<int>().sum();
50 row_.resize(jacEntries);
51 col_.resize(jacEntries);
53 for (
size_t i = 0;
i < rows;
i++)
55 for (
size_t j = 0; j < cols; j++)
71 const CppAD::vector<bool>& sparsity()
const {
return sparsity_; }
80 const CppAD::vector<size_t>& row()
const {
return row_; }
89 const CppAD::vector<size_t>& col()
const {
return col_; }
96 CppAD::sparse_jacobian_work& workJacobian() {
return workJacobian_; }
97 CppAD::sparse_hessian_work& workHessian() {
return workHessian_; }
103 workJacobian_.clear();
104 workHessian_.clear();
108 CppAD::vector<bool> sparsity_;
109 CppAD::vector<size_t> row_;
110 CppAD::vector<size_t> col_;
111 CppAD::sparse_jacobian_work workJacobian_;
112 CppAD::sparse_hessian_work workHessian_;