diff options
Diffstat (limited to 'internal/ceres/block_jacobi_preconditioner.cc')
-rw-r--r-- | internal/ceres/block_jacobi_preconditioner.cc | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/internal/ceres/block_jacobi_preconditioner.cc b/internal/ceres/block_jacobi_preconditioner.cc index 474c37f..749e0b6 100644 --- a/internal/ceres/block_jacobi_preconditioner.cc +++ b/internal/ceres/block_jacobi_preconditioner.cc @@ -40,10 +40,10 @@ namespace ceres { namespace internal { -BlockJacobiPreconditioner::BlockJacobiPreconditioner(const LinearOperator& A) +BlockJacobiPreconditioner::BlockJacobiPreconditioner( + const BlockSparseMatrix& A) : num_rows_(A.num_rows()), - block_structure_( - *(down_cast<const BlockSparseMatrix*>(&A)->block_structure())) { + block_structure_(*A.block_structure()) { // Calculate the amount of storage needed. int storage_needed = 0; for (int c = 0; c < block_structure_.cols.size(); ++c) { @@ -64,22 +64,21 @@ BlockJacobiPreconditioner::BlockJacobiPreconditioner(const LinearOperator& A) } } -BlockJacobiPreconditioner::~BlockJacobiPreconditioner() { -} +BlockJacobiPreconditioner::~BlockJacobiPreconditioner() {} -void BlockJacobiPreconditioner::Update(const LinearOperator& matrix, const double* D) { - const BlockSparseMatrix& A = *(down_cast<const BlockSparseMatrix*>(&matrix)); +bool BlockJacobiPreconditioner::UpdateImpl(const BlockSparseMatrix& A, + const double* D) { const CompressedRowBlockStructure* bs = A.block_structure(); // Compute the diagonal blocks by block inner products. std::fill(block_storage_.begin(), block_storage_.end(), 0.0); + const double* values = A.values(); for (int r = 0; r < bs->rows.size(); ++r) { const int row_block_size = bs->rows[r].block.size; const vector<Cell>& cells = bs->rows[r].cells; - const double* row_values = A.RowBlockValues(r); for (int c = 0; c < cells.size(); ++c) { const int col_block_size = bs->cols[cells[c].block_id].size; - ConstMatrixRef m(row_values + cells[c].position, + ConstMatrixRef m(values + cells[c].position, row_block_size, col_block_size); @@ -107,16 +106,19 @@ void BlockJacobiPreconditioner::Update(const LinearOperator& matrix, const doubl MatrixRef block(blocks_[c], size, size); if (D != NULL) { - block.diagonal() += ConstVectorRef(D + position, size).array().square().matrix(); + block.diagonal() += + ConstVectorRef(D + position, size).array().square().matrix(); } block = block.selfadjointView<Eigen::Upper>() .ldlt() .solve(Matrix::Identity(size, size)); } + return true; } -void BlockJacobiPreconditioner::RightMultiply(const double* x, double* y) const { +void BlockJacobiPreconditioner::RightMultiply(const double* x, + double* y) const { for (int c = 0; c < block_structure_.cols.size(); ++c) { const int size = block_structure_.cols[c].size; const int position = block_structure_.cols[c].position; |