~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to extern/libmv/third_party/ceres/internal/ceres/sparse_normal_cholesky_solver.cc

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include <cstring>
37
37
#include <ctime>
38
38
 
39
 
#ifndef CERES_NO_CXSPARSE
40
 
#include "cs.h"
41
 
#endif
42
 
 
43
39
#include "ceres/compressed_row_sparse_matrix.h"
 
40
#include "ceres/cxsparse.h"
44
41
#include "ceres/internal/eigen.h"
45
42
#include "ceres/internal/scoped_ptr.h"
46
43
#include "ceres/linear_solver.h"
54
51
 
55
52
SparseNormalCholeskySolver::SparseNormalCholeskySolver(
56
53
    const LinearSolver::Options& options)
57
 
    : options_(options) {
58
 
#ifndef CERES_NO_SUITESPARSE
59
 
  factor_ = NULL;
60
 
#endif
61
 
 
62
 
#ifndef CERES_NO_CXSPARSE
63
 
  cxsparse_factor_ = NULL;
64
 
#endif  // CERES_NO_CXSPARSE
 
54
    : factor_(NULL),
 
55
      cxsparse_factor_(NULL),
 
56
      options_(options) {
65
57
}
66
58
 
67
59
SparseNormalCholeskySolver::~SparseNormalCholeskySolver() {
85
77
    const double* b,
86
78
    const LinearSolver::PerSolveOptions& per_solve_options,
87
79
    double * x) {
88
 
  switch (options_.sparse_linear_algebra_library) {
 
80
  switch (options_.sparse_linear_algebra_library_type) {
89
81
    case SUITE_SPARSE:
90
82
      return SolveImplUsingSuiteSparse(A, b, per_solve_options, x);
91
83
    case CX_SPARSE:
92
84
      return SolveImplUsingCXSparse(A, b, per_solve_options, x);
93
85
    default:
94
86
      LOG(FATAL) << "Unknown sparse linear algebra library : "
95
 
                 << options_.sparse_linear_algebra_library;
 
87
                 << options_.sparse_linear_algebra_library_type;
96
88
  }
97
89
 
98
90
  LOG(FATAL) << "Unknown sparse linear algebra library : "
99
 
             << options_.sparse_linear_algebra_library;
 
91
             << options_.sparse_linear_algebra_library_type;
100
92
  return LinearSolver::Summary();
101
93
}
102
94
 
133
125
  // factorized. CHOLMOD/SuiteSparse on the other hand can just work
134
126
  // off of Jt to compute the Cholesky factorization of the normal
135
127
  // equations.
136
 
  cs_di* A2 = cs_transpose(&At, 1);
137
 
  cs_di* AtA = cs_multiply(&At, A2);
 
128
  cs_di* A2 = cxsparse_.TransposeMatrix(&At);
 
129
  cs_di* AtA = cxsparse_.MatrixMatrixMultiply(&At, A2);
138
130
 
139
131
  cxsparse_.Free(A2);
140
132
  if (per_solve_options.D != NULL) {
141
133
    A->DeleteRows(num_cols);
142
134
  }
143
 
 
144
135
  event_logger.AddEvent("Setup");
145
136
 
146
137
  // Compute symbolic factorization if not available.
147
138
  if (cxsparse_factor_ == NULL) {
148
 
    cxsparse_factor_ = CHECK_NOTNULL(cxsparse_.AnalyzeCholesky(AtA));
 
139
    if (options_.use_postordering) {
 
140
      cxsparse_factor_ =
 
141
          CHECK_NOTNULL(cxsparse_.BlockAnalyzeCholesky(AtA,
 
142
                                                       A->col_blocks(),
 
143
                                                       A->col_blocks()));
 
144
    } else {
 
145
      cxsparse_factor_ =
 
146
          CHECK_NOTNULL(cxsparse_.AnalyzeCholeskyWithNaturalOrdering(AtA));
 
147
    }
149
148
  }
150
 
 
151
149
  event_logger.AddEvent("Analysis");
152
150
 
153
 
 
154
151
  // Solve the linear system.
155
152
  if (cxsparse_.SolveCholesky(AtA, cxsparse_factor_, Atb.data())) {
156
153
    VectorRef(x, Atb.rows()) = Atb;
157
154
    summary.termination_type = TOLERANCE;
158
155
  }
159
 
 
160
156
  event_logger.AddEvent("Solve");
161
157
 
162
158
  cxsparse_.Free(AtA);
163
 
 
164
159
  event_logger.AddEvent("Teardown");
165
160
  return summary;
166
161
}
205
200
 
206
201
  if (factor_ == NULL) {
207
202
    if (options_.use_postordering) {
208
 
      factor_ = ss_.BlockAnalyzeCholesky(&lhs,
209
 
                                         A->col_blocks(),
210
 
                                         A->row_blocks());
 
203
      factor_ =
 
204
          CHECK_NOTNULL(ss_.BlockAnalyzeCholesky(&lhs,
 
205
                                                 A->col_blocks(),
 
206
                                                 A->row_blocks()));
211
207
    } else {
212
 
      factor_ = ss_.AnalyzeCholeskyWithNaturalOrdering(&lhs);
 
208
      factor_ =
 
209
      CHECK_NOTNULL(ss_.AnalyzeCholeskyWithNaturalOrdering(&lhs));
213
210
    }
214
211
  }
215
212