10ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// Ceres Solver - A fast non-linear least squares minimizer
20ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// Copyright 2012 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//
290ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// Author: sameeragarwal@google.com (Sameer Agarwal)
300ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
310ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#ifndef CERES_PUBLIC_CRS_MATRIX_H_
320ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#define CERES_PUBLIC_CRS_MATRIX_H_
330ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
340ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include <vector>
350ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#include "ceres/internal/port.h"
3679397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez#include "ceres/internal/disable_warnings.h"
370ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
380ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kongnamespace ceres {
390ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
400ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// A compressed row sparse matrix used primarily for communicating the
410ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong// Jacobian matrix to the user.
4279397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandezstruct CERES_EXPORT CRSMatrix {
430ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong  CRSMatrix() : num_rows(0), num_cols(0) {}
440ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
450ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong  int num_rows;
460ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong  int num_cols;
470ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
481d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  // A compressed row matrix stores its contents in three arrays,
491d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  // rows, cols and values.
500ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong  //
511d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  // rows is a num_rows + 1 sized array that points into the cols and
521d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  // values array. For each row i:
530ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong  //
541d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  // cols[rows[i]] ... cols[rows[i + 1] - 1] are the indices of the
551d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  // non-zero columns of row i.
560ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong  //
571d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  // values[rows[i]] .. values[rows[i + 1] - 1] are the values of the
581d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  // corresponding entries.
590ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong  //
601d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  // cols and values contain as many entries as there are non-zeros in
611d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  // the matrix.
621d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  //
631d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  // e.g, consider the 3x4 sparse matrix
641d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  //
651d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  //  [ 0 10  0  4 ]
661d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  //  [ 0  2 -3  2 ]
671d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  //  [ 1  2  0  0 ]
681d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  //
691d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  // The three arrays will be:
701d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  //
711d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  //
721d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  //            -row0-  ---row1---  -row2-
731d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  //  rows   = [ 0,      2,          5,     7]
741d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  //  cols   = [ 1,  3,  1,  2,  3,  0,  1]
751d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling  //  values = [10,  4,  2, -3,  2,  1,  2]
761d2624a10e2c559f8ba9ef89eaa30832c0a83a96Sascha Haeberling
770ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong  vector<int> cols;
780ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong  vector<int> rows;
790ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong  vector<double> values;
800ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong};
810ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
820ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong}  // namespace ceres
830ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong
8479397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez#include "ceres/internal/reenable_warnings.h"
8579397c21138f54fcff6ec067b44b847f1f7e0e98Carlos Hernandez
860ae28bd5885b5daa526898fcf7c323dc2c3e1963Angus Kong#endif  // CERES_PUBLIC_CRS_MATRIX_H_
87