aboutsummaryrefslogtreecommitdiff
path: root/internal/ceres/suitesparse.h
diff options
context:
space:
mode:
Diffstat (limited to 'internal/ceres/suitesparse.h')
-rw-r--r--internal/ceres/suitesparse.h91
1 files changed, 62 insertions, 29 deletions
diff --git a/internal/ceres/suitesparse.h b/internal/ceres/suitesparse.h
index eb691c0..8a5b0a8 100644
--- a/internal/ceres/suitesparse.h
+++ b/internal/ceres/suitesparse.h
@@ -33,15 +33,30 @@
#ifndef CERES_INTERNAL_SUITESPARSE_H_
#define CERES_INTERNAL_SUITESPARSE_H_
+
#ifndef CERES_NO_SUITESPARSE
#include <cstring>
#include <string>
#include <vector>
-#include <glog/logging.h>
-#include "cholmod.h"
#include "ceres/internal/port.h"
+#include "cholmod.h"
+#include "glog/logging.h"
+
+// Before SuiteSparse version 4.2.0, cholmod_camd was only enabled
+// if SuiteSparse was compiled with Metis support. This makes
+// calling and linking into cholmod_camd problematic even though it
+// has nothing to do with Metis. This has been fixed reliably in
+// 4.2.0.
+//
+// The fix was actually committed in 4.1.0, but there is
+// some confusion about a silent update to the tar ball, so we are
+// being conservative and choosing the next minor version where
+// things are stable.
+#if (SUITESPARSE_VERSION < 4002)
+#define CERES_NO_CAMD
+#endif
namespace ceres {
namespace internal {
@@ -56,8 +71,8 @@ class TripletSparseMatrix;
// for all cholmod function calls.
class SuiteSparse {
public:
- SuiteSparse() { cholmod_start(&cc_); }
- ~SuiteSparse() { cholmod_finish(&cc_); }
+ SuiteSparse();
+ ~SuiteSparse();
// Functions for building cholmod_sparse objects from sparse
// matrices stored in triplet form. The matrix A is not
@@ -70,10 +85,8 @@ class SuiteSparse {
// Create a cholmod_sparse wrapper around the contents of A. This is
// a shallow object, which refers to the contents of A and does not
- // use the SuiteSparse machinery to allocate memory, this object
- // should be disposed off with a delete and not a call to Free as is
- // the case for objects returned by CreateSparseMatrixTranspose.
- cholmod_sparse* CreateSparseMatrixTransposeView(CompressedRowSparseMatrix* A);
+ // use the SuiteSparse machinery to allocate memory.
+ cholmod_sparse CreateSparseMatrixTransposeView(CompressedRowSparseMatrix* A);
// Given a vector x, build a cholmod_dense vector of size out_size
// with the first in_size entries copied from x. If x is NULL, then
@@ -135,6 +148,12 @@ class SuiteSparse {
cholmod_factor* AnalyzeCholeskyWithUserOrdering(cholmod_sparse* A,
const vector<int>& ordering);
+ // Perform a symbolic factorization of A without re-ordering A. No
+ // postordering of the elimination tree is performed. This ensures
+ // that the symbolic factor does not introduce an extra permutation
+ // on the matrix. See the documentation for CHOLMOD for more details.
+ cholmod_factor* AnalyzeCholeskyWithNaturalOrdering(cholmod_sparse* A);
+
// Use the symbolic factorization in L, to find the numerical
// factorization for the matrix A or AA^T. Return true if
// successful, false otherwise. L contains the numeric factorization
@@ -180,28 +199,42 @@ class SuiteSparse {
const vector<int>& col_blocks,
vector<int>* ordering);
- // Given a set of blocks and a permutation of these blocks, compute
- // the corresponding "scalar" ordering, where the scalar ordering of
- // size sum(blocks).
- static void BlockOrderingToScalarOrdering(const vector<int>& blocks,
- const vector<int>& block_ordering,
- vector<int>* scalar_ordering);
-
- // Extract the block sparsity pattern of the scalar sparse matrix
- // A and return it in compressed column form. The compressed column
- // form is stored in two vectors block_rows, and block_cols, which
- // correspond to the row and column arrays in a compressed column sparse
- // matrix.
+ // Find a fill reducing approximate minimum degree
+ // ordering. ordering is expected to be large enough to hold the
+ // ordering.
+ void ApproximateMinimumDegreeOrdering(cholmod_sparse* matrix, int* ordering);
+
+
+ // Before SuiteSparse version 4.2.0, cholmod_camd was only enabled
+ // if SuiteSparse was compiled with Metis support. This makes
+ // calling and linking into cholmod_camd problematic even though it
+ // has nothing to do with Metis. This has been fixed reliably in
+ // 4.2.0.
+ //
+ // The fix was actually committed in 4.1.0, but there is
+ // some confusion about a silent update to the tar ball, so we are
+ // being conservative and choosing the next minor version where
+ // things are stable.
+ static bool IsConstrainedApproximateMinimumDegreeOrderingAvailable() {
+ return (SUITESPARSE_VERSION>4001);
+ }
+
+ // Find a fill reducing approximate minimum degree
+ // ordering. constraints is an array which associates with each
+ // column of the matrix an elimination group. i.e., all columns in
+ // group 0 are eliminated first, all columns in group 1 are
+ // eliminated next etc. This function finds a fill reducing ordering
+ // that obeys these constraints.
+ //
+ // Calling ApproximateMinimumDegreeOrdering is equivalent to calling
+ // ConstrainedApproximateMinimumDegreeOrdering with a constraint
+ // array that puts all columns in the same elimination group.
//
- // If c_ij is the block in the matrix A corresponding to row block i
- // and column block j, then it is expected that A contains at least
- // one non-zero entry corresponding to the top left entry of c_ij,
- // as that entry is used to detect the presence of a non-zero c_ij.
- static void ScalarMatrixToBlockMatrix(const cholmod_sparse* A,
- const vector<int>& row_blocks,
- const vector<int>& col_blocks,
- vector<int>* block_rows,
- vector<int>* block_cols);
+ // If CERES_NO_CAMD is defined then calling this function will
+ // result in a crash.
+ void ConstrainedApproximateMinimumDegreeOrdering(cholmod_sparse* matrix,
+ int* constraints,
+ int* ordering);
void Free(cholmod_sparse* m) { cholmod_free_sparse(&m, &cc_); }
void Free(cholmod_dense* m) { cholmod_free_dense(&m, &cc_); }