Blame internal/ceres/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: sameeragarwal@google.com (Sameer Agarwal)
Packit ea1746
//
Packit ea1746
// Interface definition for sparse matrices.
Packit ea1746
Packit ea1746
#ifndef CERES_INTERNAL_SPARSE_MATRIX_H_
Packit ea1746
#define CERES_INTERNAL_SPARSE_MATRIX_H_
Packit ea1746
Packit ea1746
#include <cstdio>
Packit ea1746
#include "ceres/linear_operator.h"
Packit ea1746
#include "ceres/internal/eigen.h"
Packit ea1746
#include "ceres/types.h"
Packit ea1746
Packit ea1746
namespace ceres {
Packit ea1746
namespace internal {
Packit ea1746
Packit ea1746
// This class defines the interface for storing and manipulating
Packit ea1746
// sparse matrices. The key property that differentiates different
Packit ea1746
// sparse matrices is how they are organized in memory and how the
Packit ea1746
// information about the sparsity structure of the matrix is
Packit ea1746
// stored. This has significant implications for linear solvers
Packit ea1746
// operating on these matrices.
Packit ea1746
//
Packit ea1746
// To deal with the different kinds of layouts, we will assume that a
Packit ea1746
// sparse matrix will have a two part representation. A values array
Packit ea1746
// that will be used to store the entries of the sparse matrix and
Packit ea1746
// some sort of a layout object that tells the user the sparsity
Packit ea1746
// structure and layout of the values array. For example in case of
Packit ea1746
// the TripletSparseMatrix, this information is carried in the rows
Packit ea1746
// and cols arrays and for the BlockSparseMatrix, this information is
Packit ea1746
// carried in the CompressedRowBlockStructure object.
Packit ea1746
//
Packit ea1746
// This interface deliberately does not contain any information about
Packit ea1746
// the structure of the sparse matrix as that seems to be highly
Packit ea1746
// matrix type dependent and we are at this stage unable to come up
Packit ea1746
// with an efficient high level interface that spans multiple sparse
Packit ea1746
// matrix types.
Packit ea1746
class SparseMatrix : public LinearOperator {
Packit ea1746
 public:
Packit ea1746
  virtual ~SparseMatrix();
Packit ea1746
Packit ea1746
  // y += Ax;
Packit ea1746
  virtual void RightMultiply(const double* x, double* y) const = 0;
Packit ea1746
  // y += A'x;
Packit ea1746
  virtual void LeftMultiply(const double* x, double* y) const = 0;
Packit ea1746
Packit ea1746
  // In MATLAB notation sum(A.*A, 1)
Packit ea1746
  virtual void SquaredColumnNorm(double* x) const = 0;
Packit ea1746
  // A = A * diag(scale)
Packit ea1746
  virtual void ScaleColumns(const double* scale) = 0;
Packit ea1746
Packit ea1746
  // A = 0. A->num_nonzeros() == 0 is true after this call. The
Packit ea1746
  // sparsity pattern is preserved.
Packit ea1746
  virtual void SetZero() = 0;
Packit ea1746
Packit ea1746
  // Resize and populate dense_matrix with a dense version of the
Packit ea1746
  // sparse matrix.
Packit ea1746
  virtual void ToDenseMatrix(Matrix* dense_matrix) const = 0;
Packit ea1746
Packit ea1746
  // Write out the matrix as a sequence of (i,j,s) triplets. This
Packit ea1746
  // format is useful for loading the matrix into MATLAB/octave as a
Packit ea1746
  // sparse matrix.
Packit ea1746
  virtual void ToTextFile(FILE* file) const = 0;
Packit ea1746
Packit ea1746
  // Accessors for the values array that stores the entries of the
Packit ea1746
  // sparse matrix. The exact interpreptation of the values of this
Packit ea1746
  // array depends on the particular kind of SparseMatrix being
Packit ea1746
  // accessed.
Packit ea1746
  virtual double* mutable_values() = 0;
Packit ea1746
  virtual const double* values() const = 0;
Packit ea1746
Packit ea1746
  virtual int num_rows() const = 0;
Packit ea1746
  virtual int num_cols() const = 0;
Packit ea1746
  virtual int num_nonzeros() const = 0;
Packit ea1746
};
Packit ea1746
Packit ea1746
}  // namespace internal
Packit ea1746
}  // namespace ceres
Packit ea1746
Packit ea1746
#endif  // CERES_INTERNAL_SPARSE_MATRIX_H_