aboutsummaryrefslogtreecommitdiff
path: root/internal/ceres/compressed_row_sparse_matrix.h
diff options
context:
space:
mode:
Diffstat (limited to 'internal/ceres/compressed_row_sparse_matrix.h')
-rw-r--r--internal/ceres/compressed_row_sparse_matrix.h47
1 files changed, 25 insertions, 22 deletions
diff --git a/internal/ceres/compressed_row_sparse_matrix.h b/internal/ceres/compressed_row_sparse_matrix.h
index 10f96c0..c5721eb 100644
--- a/internal/ceres/compressed_row_sparse_matrix.h
+++ b/internal/ceres/compressed_row_sparse_matrix.h
@@ -32,13 +32,11 @@
#define CERES_INTERNAL_COMPRESSED_ROW_SPARSE_MATRIX_H_
#include <vector>
-#include <glog/logging.h>
-#include "ceres/sparse_matrix.h"
-#include "ceres/triplet_sparse_matrix.h"
-#include "ceres/internal/eigen.h"
#include "ceres/internal/macros.h"
#include "ceres/internal/port.h"
+#include "ceres/sparse_matrix.h"
#include "ceres/types.h"
+#include "glog/logging.h"
namespace ceres {
@@ -46,7 +44,7 @@ struct CRSMatrix;
namespace internal {
-class SparseMatrixProto;
+class TripletSparseMatrix;
class CompressedRowSparseMatrix : public SparseMatrix {
public:
@@ -57,9 +55,6 @@ class CompressedRowSparseMatrix : public SparseMatrix {
//
// We assume that m does not have any repeated entries.
explicit CompressedRowSparseMatrix(const TripletSparseMatrix& m);
-#ifndef CERES_NO_PROTOCOL_BUFFERS
- explicit CompressedRowSparseMatrix(const SparseMatrixProto& proto);
-#endif
// Use this constructor only if you know what you are doing. This
// creates a "blank" matrix with the appropriate amount of memory
@@ -90,15 +85,12 @@ class CompressedRowSparseMatrix : public SparseMatrix {
virtual void ScaleColumns(const double* scale);
virtual void ToDenseMatrix(Matrix* dense_matrix) const;
-#ifndef CERES_NO_PROTOCOL_BUFFERS
- virtual void ToProto(SparseMatrixProto* proto) const;
-#endif
virtual void ToTextFile(FILE* file) const;
virtual int num_rows() const { return num_rows_; }
virtual int num_cols() const { return num_cols_; }
virtual int num_nonzeros() const { return rows_[num_rows_]; }
- virtual const double* values() const { return values_.get(); }
- virtual double* mutable_values() { return values_.get(); }
+ virtual const double* values() const { return &values_[0]; }
+ virtual double* mutable_values() { return &values_[0]; }
// Delete the bottom delta_rows.
// num_rows -= delta_rows
@@ -111,11 +103,11 @@ class CompressedRowSparseMatrix : public SparseMatrix {
void ToCRSMatrix(CRSMatrix* matrix) const;
// Low level access methods that expose the structure of the matrix.
- const int* cols() const { return cols_.get(); }
- int* mutable_cols() { return cols_.get(); }
+ const int* cols() const { return &cols_[0]; }
+ int* mutable_cols() { return &cols_[0]; }
- const int* rows() const { return rows_.get(); }
- int* mutable_rows() { return rows_.get(); }
+ const int* rows() const { return &rows_[0]; }
+ int* mutable_rows() { return &rows_[0]; }
const vector<int>& row_blocks() const { return row_blocks_; }
vector<int>* mutable_row_blocks() { return &row_blocks_; }
@@ -123,14 +115,25 @@ class CompressedRowSparseMatrix : public SparseMatrix {
const vector<int>& col_blocks() const { return col_blocks_; }
vector<int>* mutable_col_blocks() { return &col_blocks_; }
- private:
- scoped_array<int> cols_;
- scoped_array<int> rows_;
- scoped_array<double> values_;
+ // Non-destructive array resizing method.
+ void set_num_rows(const int num_rows) { num_rows_ = num_rows; }
+ void set_num_cols(const int num_cols) { num_cols_ = num_cols; }
+
+ void SolveLowerTriangularInPlace(double* solution) const;
+ void SolveLowerTriangularTransposeInPlace(double* solution) const;
+ CompressedRowSparseMatrix* Transpose() const;
+
+ static CompressedRowSparseMatrix* CreateBlockDiagonalMatrix(
+ const double* diagonal,
+ const vector<int>& blocks);
+
+ private:
int num_rows_;
int num_cols_;
- int max_num_nonzeros_;
+ vector<int> rows_;
+ vector<int> cols_;
+ vector<double> values_;
// If the matrix has an underlying block structure, then it can also
// carry with it row and column block sizes. This is auxilliary and