-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
additional sparseJacobian
functions
#610
Changes from all commits
5c6227b
e108f5d
df69892
bc4c4fb
104e568
5299e6d
4b07417
b6e7078
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* ---------------------------------------------------------------------------- | ||
|
||
* GTSAM Copyright 2010, Georgia Tech Research Corporation, | ||
* Atlanta, Georgia 30332-0415 | ||
* All Rights Reserved | ||
* Authors: Frank Dellaert, et al. (see THANKS for the full author list) | ||
|
||
* See LICENSE for the license information | ||
|
||
* -------------------------------------------------------------------------- */ | ||
|
||
/** | ||
* @file SparseMatrix.h | ||
* @brief Interface utilities with Eigen's SparseMatrix representation | ||
* @author Gerry Chen | ||
*/ | ||
|
||
#include <gtsam/base/SparseMatrix.h> | ||
|
||
namespace gtsam { | ||
|
||
/** Returns the sparse jacobian of a factor graph as an Eigen::SparseMatrix | ||
* The standard deviations are baked into A and b | ||
*/ | ||
SparseMatrixEigen SparseMatrix::JacobianEigen(const GaussianFactorGraph& graph, | ||
const Ordering& ordering, | ||
size_t& nrows, size_t& ncols) { | ||
gttic_(Jacobian); | ||
gttic_(obtainSparseJacobian); | ||
auto entries = JacobianBoostTriplets(graph, ordering, nrows, ncols); | ||
gttoc_(obtainSparseJacobian); | ||
gttic_(convertSparseJacobian); | ||
SparseMatrixEigen Ab(nrows, ncols); | ||
Ab.reserve(entries.size()); | ||
for (auto entry : entries) { | ||
Ab.insert(entry.get<0>(), entry.get<1>()) = entry.get<2>(); | ||
} | ||
Ab.makeCompressed(); | ||
// TODO(gerry): benchmark to see if setFromTriplets is faster | ||
// Ab.setFromTriplets(entries.begin(), entries.end()); | ||
return Ab; | ||
} | ||
|
||
/* ******************************* Overloads ******************************* */ | ||
SparseMatrixEigen SparseMatrix::JacobianEigen(const GaussianFactorGraph& graph, | ||
const Ordering& ordering) { | ||
size_t dummy1, dummy2; | ||
return JacobianEigen(graph, ordering, dummy1, dummy2); | ||
} | ||
SparseMatrixEigen SparseMatrix::JacobianEigen(const GaussianFactorGraph& graph, | ||
size_t& nrows, size_t& ncols) { | ||
return JacobianEigen(graph, Ordering(graph.keys()), nrows, ncols); | ||
} | ||
SparseMatrixEigen SparseMatrix::JacobianEigen( | ||
const GaussianFactorGraph& graph) { | ||
return JacobianEigen(graph, Ordering(graph.keys())); | ||
} | ||
|
||
} // namespace gtsam |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* ---------------------------------------------------------------------------- | ||
|
||
* GTSAM Copyright 2010, Georgia Tech Research Corporation, | ||
* Atlanta, Georgia 30332-0415 | ||
* All Rights Reserved | ||
* Authors: Frank Dellaert, et al. (see THANKS for the full author list) | ||
|
||
* See LICENSE for the license information | ||
|
||
* -------------------------------------------------------------------------- */ | ||
|
||
/** | ||
* @file SparseMatrix.h | ||
* @brief Interface utilities with Eigen's SparseMatrix representation | ||
* @author Gerry Chen | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "gtsam/linear/GaussianFactorGraph.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. base cannot know about linear :-/ the directories in GTSAm form a directed graph. |
||
|
||
#include <Eigen/Sparse> | ||
|
||
namespace gtsam { | ||
|
||
/// Sparse matrix as Eigen::SparseMatrix | ||
// note: Eigen only supports signed (e.g. not size_t) StorageIndex | ||
typedef Eigen::SparseMatrix<double, Eigen::ColMajor, int> SparseMatrixEigen; | ||
|
||
class GTSAM_EXPORT SparseMatrix { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why a class? |
||
public: | ||
/** Returns the sparse augmented jacobian of a factor graph as a vector of | ||
* boost tuples (row, col, entry). Equivalent to graph.sparseJacobian(). | ||
* The standard deviations are baked into A and b | ||
*/ | ||
template <typename... Args> | ||
static SparseMatrixBoostTriplets JacobianBoostTriplets( | ||
const GaussianFactorGraph& graph, Args&&... args) { | ||
return graph.sparseJacobian(std::forward<Args>(args)...); | ||
} | ||
|
||
/** Returns the sparse augmented jacobian of a factor graph as a matlab | ||
* `sparse` -compatible 3xm matrix with each column representing an entry of | ||
* the form [row; col; entry]. graph.sparseJacobian_(). | ||
* The standard deviations are baked into A and b | ||
*/ | ||
template <typename... Args> | ||
static Matrix JacobianMatrix(const GaussianFactorGraph& graph, | ||
Args&&... args) { | ||
return graph.sparseJacobian_(std::forward<Args>(args)...); | ||
} | ||
|
||
/** Returns the sparse augmented jacobian of a factor graph as an | ||
* Eigen::SparseMatrix | ||
* The standard deviations are baked into A and b | ||
*/ | ||
static SparseMatrixEigen JacobianEigen(const GaussianFactorGraph& graph, | ||
const Ordering& ordering, | ||
size_t& nrows, size_t& ncols); | ||
|
||
// Overloads | ||
static SparseMatrixEigen JacobianEigen(const GaussianFactorGraph& graph, | ||
const Ordering& ordering); | ||
static SparseMatrixEigen JacobianEigen(const GaussianFactorGraph& graph, | ||
size_t& nrows, size_t& ncols); | ||
static SparseMatrixEigen JacobianEigen(const GaussianFactorGraph& graph); | ||
}; | ||
} // namespace gtsam |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move additions in this file to SparseMatrix.h...