Petter Strandmark | 1e3cbd9 | 2012-08-29 09:39:56 -0700 | [diff] [blame] | 1 | // Ceres Solver - A fast non-linear least squares minimizer |
| 2 | // Copyright 2012 Google Inc. All rights reserved. |
| 3 | // http://code.google.com/p/ceres-solver/ |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | // this list of conditions and the following disclaimer in the documentation |
| 12 | // and/or other materials provided with the distribution. |
| 13 | // * Neither the name of Google Inc. nor the names of its contributors may be |
| 14 | // used to endorse or promote products derived from this software without |
| 15 | // specific prior written permission. |
| 16 | // |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | // POSSIBILITY OF SUCH DAMAGE. |
| 28 | // |
| 29 | // Author: strandmark@google.com (Petter Strandmark) |
| 30 | |
| 31 | #ifndef CERES_INTERNAL_CXSPARSE_H_ |
| 32 | #define CERES_INTERNAL_CXSPARSE_H_ |
| 33 | |
| 34 | #ifndef CERES_NO_CXSPARSE |
| 35 | |
| 36 | #include "cs.h" |
| 37 | |
| 38 | namespace ceres { |
| 39 | namespace internal { |
| 40 | |
| 41 | class CompressedRowSparseMatrix; |
| 42 | class TripletSparseMatrix; |
| 43 | |
| 44 | // This object provides access to solving linear systems using Cholesky |
| 45 | // factorization with a known symbolic factorization. This features does not |
| 46 | // explicity exist in CXSparse. The methods in the class are nonstatic because |
| 47 | // the class manages internal scratch space. |
| 48 | class CXSparse { |
| 49 | public: |
| 50 | CXSparse(); |
| 51 | ~CXSparse(); |
| 52 | |
| 53 | // Solves a symmetric linear system A * x = b using Cholesky factorization. |
Sameer Agarwal | 98bf14d | 2012-08-30 10:26:44 -0700 | [diff] [blame] | 54 | // A - The system matrix. |
| 55 | // symbolic_factorization - The symbolic factorization of A. This is obtained |
| 56 | // from AnalyzeCholesky. |
| 57 | // b - The right hand size of the linear equation. This |
| 58 | // array will also recieve the solution. |
Petter Strandmark | 1e3cbd9 | 2012-08-29 09:39:56 -0700 | [diff] [blame] | 59 | // Returns false if Cholesky factorization of A fails. |
Sameer Agarwal | 98bf14d | 2012-08-30 10:26:44 -0700 | [diff] [blame] | 60 | bool SolveCholesky(cs_di* A, cs_dis* symbolic_factorization, double* b); |
Petter Strandmark | 1e3cbd9 | 2012-08-29 09:39:56 -0700 | [diff] [blame] | 61 | |
| 62 | // Creates a sparse matrix from a compressed-column form. No memory is |
| 63 | // allocated or copied; the structure A is filled out with info from the |
| 64 | // argument. |
| 65 | cs_di CreateSparseMatrixTransposeView(CompressedRowSparseMatrix* A); |
| 66 | |
| 67 | // Creates a new matrix from a triplet form. Deallocate the returned matrix |
| 68 | // with Free. May return NULL if the compression or allocation fails. |
| 69 | cs_di* CreateSparseMatrix(TripletSparseMatrix* A); |
| 70 | |
| 71 | // Computes a symbolic factorization of A that can be used in SolveCholesky. |
| 72 | // The returned matrix should be deallocated with Free when not used anymore. |
| 73 | cs_dis* AnalyzeCholesky(cs_di* A); |
| 74 | |
Sameer Agarwal | 0593747 | 2013-02-11 13:57:12 -0800 | [diff] [blame] | 75 | void Free(cs_di* sparse_matrix); |
| 76 | void Free(cs_dis* symbolic_factorization); |
Petter Strandmark | 1e3cbd9 | 2012-08-29 09:39:56 -0700 | [diff] [blame] | 77 | |
| 78 | private: |
| 79 | // Cached scratch space |
| 80 | CS_ENTRY* scratch_; |
| 81 | int scratch_size_; |
| 82 | }; |
| 83 | |
| 84 | } // namespace internal |
| 85 | } // namespace ceres |
| 86 | |
| 87 | #endif // CERES_NO_CXSPARSE |
| 88 | |
| 89 | #endif // CERES_INTERNAL_CXSPARSE_H_ |