10ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// Ceres Solver - A fast non-linear least squares minimizer
21d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling// Copyright 2013 Google Inc. All rights reserved.
30ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// http://code.google.com/p/ceres-solver/
40ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong//
50ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// Redistribution and use in source and binary forms, with or without
60ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// modification, are permitted provided that the following conditions are met:
70ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong//
80ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// * Redistributions of source code must retain the above copyright notice,
90ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong//   this list of conditions and the following disclaimer.
100ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// * Redistributions in binary form must reproduce the above copyright notice,
110ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong//   this list of conditions and the following disclaimer in the documentation
120ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong//   and/or other materials provided with the distribution.
130ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// * Neither the name of Google Inc. nor the names of its contributors may be
140ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong//   used to endorse or promote products derived from this software without
150ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong//   specific prior written permission.
160ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong//
170ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
180ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
190ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
200ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
210ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
220ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
230ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
240ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
250ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
260ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
270ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// POSSIBILITY OF SUCH DAMAGE.
280ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong//
291d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling// Author: sameeragarwal@google.com (Sameer Agarwal)
301d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling
311d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#include "ceres/preconditioner.h"
321d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling#include "glog/logging.h"
331d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling
341d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberlingnamespace ceres {
351d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberlingnamespace internal {
361d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling
371d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha HaeberlingPreconditioner::~Preconditioner() {
381d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling}
391d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling
4079397c21138f54fcff6ec067b44b847f1f7e0e98Carlos HernandezPreconditionerType Preconditioner::PreconditionerForZeroEBlocks(
4179397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez    PreconditionerType preconditioner_type) {
4279397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez  if (preconditioner_type == SCHUR_JACOBI ||
4379397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez      preconditioner_type == CLUSTER_JACOBI ||
4479397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez      preconditioner_type == CLUSTER_TRIDIAGONAL) {
4579397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez    return JACOBI;
4679397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez  }
4779397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez  return preconditioner_type;
4879397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez}
4979397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez
501d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha HaeberlingSparseMatrixPreconditionerWrapper::SparseMatrixPreconditionerWrapper(
511d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling    const SparseMatrix* matrix)
521d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling    : matrix_(CHECK_NOTNULL(matrix)) {
531d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling}
541d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling
551d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha HaeberlingSparseMatrixPreconditionerWrapper::~SparseMatrixPreconditionerWrapper() {
561d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling}
571d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling
581d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberlingbool SparseMatrixPreconditionerWrapper::UpdateImpl(const SparseMatrix& A,
591d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling                                                   const double* D) {
601d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  return true;
611d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling}
620ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
631d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberlingvoid SparseMatrixPreconditionerWrapper::RightMultiply(const double* x,
641d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling                                                      double* y) const {
651d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  matrix_->RightMultiply(x, y);
661d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling}
670ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
681d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberlingint  SparseMatrixPreconditionerWrapper::num_rows() const {
691d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  return matrix_->num_rows();
701d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling}
710ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
721d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling}  // namespace internal
731d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling}  // namespace ceres
74