1 // Ceres Solver - A fast non-linear least squares minimizer
2 // Copyright 2015 Google Inc. All rights reserved.
3 // http://ceres-solver.org/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
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.
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.
29 // Author: sameeragarwal@google.com (Sameer Agarwal)
31 #include "ceres/lapack.h"
33 #include "ceres/internal/port.h"
34 #include "ceres/linear_solver.h"
35 #include "glog/logging.h"
37 // C interface to the LAPACK Cholesky factorization and triangular solve.
38 extern "C" void dpotrf_(char* uplo,
44 extern "C" void dpotrs_(char* uplo,
53 extern "C" void dgels_(char* uplo,
69 LinearSolverTerminationType LAPACK::SolveInPlaceUsingCholesky(
72 double* rhs_and_solution,
73 std::string* message) {
74 #ifdef CERES_NO_LAPACK
75 LOG(FATAL) << "Ceres was built without a BLAS library.";
76 return LINEAR_SOLVER_FATAL_ERROR;
82 double* lhs = const_cast<double*>(in_lhs);
84 dpotrf_(&uplo, &n, lhs, &n, &info);
86 LOG(FATAL) << "Congratulations, you found a bug in Ceres."
87 << "Please report it."
88 << "LAPACK::dpotrf fatal error."
89 << "Argument: " << -info << " is invalid.";
90 return LINEAR_SOLVER_FATAL_ERROR;
96 "LAPACK::dpotrf numerical failure. "
97 "The leading minor of order %d is not positive definite.", info);
98 return LINEAR_SOLVER_FAILURE;
101 dpotrs_(&uplo, &n, &nrhs, lhs, &n, rhs_and_solution, &n, &info);
103 LOG(FATAL) << "Congratulations, you found a bug in Ceres."
104 << "Please report it."
105 << "LAPACK::dpotrs fatal error."
106 << "Argument: " << -info << " is invalid.";
107 return LINEAR_SOLVER_FATAL_ERROR;
110 *message = "Success";
111 return LINEAR_SOLVER_SUCCESS;
115 int LAPACK::EstimateWorkSizeForQR(int num_rows, int num_cols) {
116 #ifdef CERES_NO_LAPACK
117 LOG(FATAL) << "Ceres was built without a LAPACK library.";
138 LOG(FATAL) << "Congratulations, you found a bug in Ceres."
139 << "Please report it."
140 << "LAPACK::dgels fatal error."
141 << "Argument: " << -info << " is invalid.";
143 return static_cast<int>(work);
147 LinearSolverTerminationType LAPACK::SolveInPlaceUsingQR(
150 const double* in_lhs,
153 double* rhs_and_solution,
154 std::string* message) {
155 #ifdef CERES_NO_LAPACK
156 LOG(FATAL) << "Ceres was built without a LAPACK library.";
157 return LINEAR_SOLVER_FATAL_ERROR;
166 double* lhs = const_cast<double*>(in_lhs);
181 LOG(FATAL) << "Congratulations, you found a bug in Ceres."
182 << "Please report it."
183 << "LAPACK::dgels fatal error."
184 << "Argument: " << -info << " is invalid.";
187 *message = "Success.";
188 return LINEAR_SOLVER_SUCCESS;
192 } // namespace internal