Blame internal/ceres/dense_sparse_matrix.h

Packit ea1746
// Ceres Solver - A fast non-linear least squares minimizer
Packit ea1746
// Copyright 2015 Google Inc. All rights reserved.
Packit ea1746
// http://ceres-solver.org/
Packit ea1746
//
Packit ea1746
// Redistribution and use in source and binary forms, with or without
Packit ea1746
// modification, are permitted provided that the following conditions are met:
Packit ea1746
//
Packit ea1746
// * Redistributions of source code must retain the above copyright notice,
Packit ea1746
//   this list of conditions and the following disclaimer.
Packit ea1746
// * Redistributions in binary form must reproduce the above copyright notice,
Packit ea1746
//   this list of conditions and the following disclaimer in the documentation
Packit ea1746
//   and/or other materials provided with the distribution.
Packit ea1746
// * Neither the name of Google Inc. nor the names of its contributors may be
Packit ea1746
//   used to endorse or promote products derived from this software without
Packit ea1746
//   specific prior written permission.
Packit ea1746
//
Packit ea1746
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit ea1746
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit ea1746
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit ea1746
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Packit ea1746
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit ea1746
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit ea1746
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit ea1746
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Packit ea1746
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit ea1746
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit ea1746
// POSSIBILITY OF SUCH DAMAGE.
Packit ea1746
//
Packit ea1746
// Author: keir@google.com (Keir Mierle)
Packit ea1746
//
Packit ea1746
// A dense matrix implemented under the SparseMatrix interface.
Packit ea1746
Packit ea1746
#ifndef CERES_INTERNAL_DENSE_SPARSE_MATRIX_H_
Packit ea1746
#define CERES_INTERNAL_DENSE_SPARSE_MATRIX_H_
Packit ea1746
Packit ea1746
#include "ceres/sparse_matrix.h"
Packit ea1746
#include "ceres/internal/eigen.h"
Packit ea1746
#include "ceres/internal/macros.h"
Packit ea1746
#include "ceres/internal/scoped_ptr.h"
Packit ea1746
#include "ceres/types.h"
Packit ea1746
Packit ea1746
namespace ceres {
Packit ea1746
namespace internal {
Packit ea1746
Packit ea1746
class TripletSparseMatrix;
Packit ea1746
Packit ea1746
class DenseSparseMatrix : public SparseMatrix {
Packit ea1746
 public:
Packit ea1746
  // Build a matrix with the same content as the TripletSparseMatrix
Packit ea1746
  // m. This assumes that m does not have any repeated entries.
Packit ea1746
  explicit DenseSparseMatrix(const TripletSparseMatrix& m);
Packit ea1746
  explicit DenseSparseMatrix(const ColMajorMatrix& m);
Packit ea1746
Packit ea1746
  DenseSparseMatrix(int num_rows, int num_cols);
Packit ea1746
  DenseSparseMatrix(int num_rows, int num_cols, bool reserve_diagonal);
Packit ea1746
Packit ea1746
  virtual ~DenseSparseMatrix() {}
Packit ea1746
Packit ea1746
  // SparseMatrix interface.
Packit ea1746
  virtual void SetZero();
Packit ea1746
  virtual void RightMultiply(const double* x, double* y) const;
Packit ea1746
  virtual void LeftMultiply(const double* x, double* y) const;
Packit ea1746
  virtual void SquaredColumnNorm(double* x) const;
Packit ea1746
  virtual void ScaleColumns(const double* scale);
Packit ea1746
  virtual void ToDenseMatrix(Matrix* dense_matrix) const;
Packit ea1746
  virtual void ToTextFile(FILE* file) const;
Packit ea1746
  virtual int num_rows() const;
Packit ea1746
  virtual int num_cols() const;
Packit ea1746
  virtual int num_nonzeros() const;
Packit ea1746
  virtual const double* values() const { return m_.data(); }
Packit ea1746
  virtual double* mutable_values() { return m_.data(); }
Packit ea1746
Packit ea1746
  ConstColMajorMatrixRef matrix() const;
Packit ea1746
  ColMajorMatrixRef mutable_matrix();
Packit ea1746
Packit ea1746
  // Only one diagonal can be appended at a time. The diagonal is appended to
Packit ea1746
  // as a new set of rows, e.g.
Packit ea1746
  //
Packit ea1746
  // Original matrix:
Packit ea1746
  //
Packit ea1746
  //   x x x
Packit ea1746
  //   x x x
Packit ea1746
  //   x x x
Packit ea1746
  //
Packit ea1746
  // After append diagonal (1, 2, 3):
Packit ea1746
  //
Packit ea1746
  //   x x x
Packit ea1746
  //   x x x
Packit ea1746
  //   x x x
Packit ea1746
  //   1 0 0
Packit ea1746
  //   0 2 0
Packit ea1746
  //   0 0 3
Packit ea1746
  //
Packit ea1746
  // Calling RemoveDiagonal removes the block. It is a fatal error to append a
Packit ea1746
  // diagonal to a matrix that already has an appended diagonal, and it is also
Packit ea1746
  // a fatal error to remove a diagonal from a matrix that has none.
Packit ea1746
  void AppendDiagonal(double *d);
Packit ea1746
  void RemoveDiagonal();
Packit ea1746
Packit ea1746
 private:
Packit ea1746
  ColMajorMatrix m_;
Packit ea1746
  bool has_diagonal_appended_;
Packit ea1746
  bool has_diagonal_reserved_;
Packit ea1746
};
Packit ea1746
Packit ea1746
}  // namespace internal
Packit ea1746
}  // namespace ceres
Packit ea1746
Packit ea1746
#endif  // CERES_INTERNAL_DENSE_SPARSE_MATRIX_H_