39typedef Eigen::MatrixXd Matrix;
40typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> MatrixRowMajor;
43 Eigen::Ref<const Matrix, 0, Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>>;
47#define GTSAM_MAKE_MATRIX_DEFS(N) \
48using Matrix##N = Eigen::Matrix<double, N, N>; \
49using Matrix1##N = Eigen::Matrix<double, 1, N>; \
50using Matrix2##N = Eigen::Matrix<double, 2, N>; \
51using Matrix3##N = Eigen::Matrix<double, 3, N>; \
52using Matrix4##N = Eigen::Matrix<double, 4, N>; \
53using Matrix5##N = Eigen::Matrix<double, 5, N>; \
54using Matrix6##N = Eigen::Matrix<double, 6, N>; \
55using Matrix7##N = Eigen::Matrix<double, 7, N>; \
56using Matrix8##N = Eigen::Matrix<double, 8, N>; \
57using Matrix9##N = Eigen::Matrix<double, 9, N>; \
59GTSAM_MAKE_MATRIX_DEFS(1)
60GTSAM_MAKE_MATRIX_DEFS(2)
61GTSAM_MAKE_MATRIX_DEFS(3)
62GTSAM_MAKE_MATRIX_DEFS(4)
63GTSAM_MAKE_MATRIX_DEFS(5)
64GTSAM_MAKE_MATRIX_DEFS(6)
65GTSAM_MAKE_MATRIX_DEFS(7)
66GTSAM_MAKE_MATRIX_DEFS(8)
67GTSAM_MAKE_MATRIX_DEFS(9)
70typedef Eigen::Block<Matrix> SubMatrix;
71typedef Eigen::Block<const Matrix> ConstSubMatrix;
75const Eigen::IOFormat& matlabFormat();
80template <class MATRIX>
81bool equal_with_abs_tol(const Eigen::DenseBase<MATRIX>& A, const Eigen::DenseBase<MATRIX>& B,
double tol = 1e-9) {
83 const size_t n1 = A.cols(), m1 = A.rows();
84 const size_t n2 = B.cols(), m2 = B.rows();
86 if(m1!=m2 || n1!=n2)
return false;
88 for(
size_t i=0; i<m1; i++)
89 for(
size_t j=0; j<n1; j++) {
90 if(!fpEqual(A(i,j), B(i,j), tol, false)) {
114GTSAM_EXPORT
bool assert_equal(
const Matrix& A,
const Matrix& B,
double tol = 1e-9);
119GTSAM_EXPORT
bool assert_inequal(
const Matrix& A,
const Matrix& B,
double tol = 1e-9);
124GTSAM_EXPORT
bool assert_equal(
const std::list<Matrix>& As,
const std::list<Matrix>& Bs,
double tol = 1e-9);
129GTSAM_EXPORT
bool linear_independent(
const Matrix& A,
const Matrix& B,
double tol = 1e-9);
134GTSAM_EXPORT
bool linear_dependent(
const Matrix& A,
const Matrix& B,
double tol = 1e-9);
139GTSAM_EXPORT
void print(
const Matrix& A,
const std::string& s, std::ostream& stream);
144GTSAM_EXPORT
void print(
const Matrix& A,
const std::string& s =
"");
149GTSAM_EXPORT
void save(
const Matrix& A,
const std::string &s,
const std::string& filename);
156GTSAM_EXPORT std::istream& operator>>(std::istream& inputStream, Matrix& destinationMatrix);
158#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
169template <
typename Derived1,
typename Derived2>
170void insertSub(Eigen::MatrixBase<Derived1>& fullMatrix,
171 const Eigen::MatrixBase<Derived2>& subMatrix,
size_t i,
173 fullMatrix.block(i, j, subMatrix.rows(), subMatrix.cols()) = subMatrix;
180GTSAM_EXPORT Matrix
diag(
const std::vector<Matrix>& Hs);
182#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
187inline Matrix trans(
const Matrix& A) {
return A.transpose(); }
196GTSAM_EXPORT std::pair<Matrix,Matrix>
qr(
const Matrix& A);
213GTSAM_EXPORT std::list<std::tuple<Vector, double, double> >
223GTSAM_EXPORT
void householder_(Matrix& A,
size_t k,
bool copy_vectors=
true);
233#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
244GTSAM_EXPORT Vector backSubstituteUpper(
const Matrix& U,
const Vector& b,
257GTSAM_EXPORT Vector backSubstituteUpper(
const Vector& b,
const Matrix& U,
270GTSAM_EXPORT Vector backSubstituteLower(
const Matrix& L,
const Vector& b,
277template <
class RDerived,
class SDerived,
class DDerived,
class ParentsDerived>
279 const Eigen::MatrixBase<SDerived>& S,
280 const Eigen::MatrixBase<DDerived>& d,
281 const Eigen::MatrixBase<ParentsDerived>& parents,
283 result->resize(d.rows());
284 result->noalias() = d - S * parents;
285 R.derived().template triangularView<Eigen::Upper>().solveInPlace(*result);
290#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
298GTSAM_EXPORT Matrix stack(
size_t nrMatrices, ...);
300GTSAM_EXPORT Matrix stack(
const std::vector<Matrix>& blocks);
312GTSAM_EXPORT Matrix collect(
const std::vector<const Matrix*>& matrices,
313 size_t m = 0,
size_t n = 0);
314#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
316GTSAM_EXPORT Matrix collect(
size_t nrMatrices, ...);
319#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
328GTSAM_EXPORT
void vector_scale_inplace(
const Vector& v, Matrix& A,
329 bool inf_mask =
false);
339GTSAM_EXPORT Matrix vector_scale(
const Vector& v,
const Matrix& A,
340 bool inf_mask =
false);
350GTSAM_EXPORT Matrix vector_scale(
const Matrix& A,
const Vector& v,
351 bool inf_mask =
false);
366 return Matrix3{{0.0, -wz, +wy}, {+wz, 0.0, -wx}, {-wy, +wx, 0.0}};
369template <
class Derived>
370inline Matrix3 skewSymmetric(
const Eigen::MatrixBase<Derived>& w) {
371 return skewSymmetric(w(0), w(1), w(2));
377#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
383GTSAM_EXPORT Matrix cholesky_inverse(
const Matrix &A);
398GTSAM_EXPORT
void svd(
const Matrix& A, Matrix& U, Vector& S, Matrix& V);
407GTSAM_EXPORT std::tuple<int, double, Vector>
408DLT(
const Matrix& A,
double rank_tol = 1e-9);
415GTSAM_EXPORT Matrix
expm(
const Matrix& A,
size_t K=7);
417std::string formatMatrixIndented(
const std::string& label,
const Matrix& matrix,
bool makeVectorHorizontal =
false);
427 typedef Eigen::Matrix<double, N, 1> VectorN;
428 typedef Eigen::Matrix<double, N, N> MatrixN;
434 const MatrixN invA = A.inverse();
435 const VectorN c = invA * b;
438 for (
size_t j = 0; j < N; j++)
439 H1->template middleCols<N>(N * j) = -c[j] * invA;
451template <
typename T,
int N>
454 typedef Eigen::Matrix<double, N, 1> VectorN;
455 typedef Eigen::Matrix<double, N, N> MatrixN;
459 typedef std::function<VectorN(
472 const MatrixN invA = A.inverse();
473 const VectorN c = invA * b;
476 Eigen::Matrix<double, N, M> H;
488#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
490GTSAM_EXPORT Matrix LLt(
const Matrix& A);
493GTSAM_EXPORT Matrix RtR(
const Matrix& A);
499GTSAM_EXPORT Vector columnNormSquare(
const Matrix &A);
void solveUpperConditional(const Eigen::MatrixBase< RDerived > &R, const Eigen::MatrixBase< SDerived > &S, const Eigen::MatrixBase< DDerived > &d, const Eigen::MatrixBase< ParentsDerived > &parents, Vector *result)
Solve the block upper-triangular system R*x = d - S*parents.
Definition Matrix.h:278
Special class for optional Jacobian arguments.
typedef and functions to augment Eigen's VectorXd
Global functions in a separate testing namespace.
Definition chartTesting.h:28
list< std::tuple< Vector, double, double > > weighted_eliminate(Matrix &A, Vector &b, const Vector &sigmas)
Imperative algorithm for in-place full elimination with weights and constraint handling.
Definition Matrix.cpp:261
void householder(Matrix &A, size_t k)
Householder tranformation, zeros below diagonal.
Definition Matrix.cpp:342
void inplace_QR(Matrix &A)
QR factorization using Eigen's internal block QR algorithm.
Definition Matrix.cpp:636
void svd(const Matrix &A, Matrix &U, Vector &S, Matrix &V)
SVD computes economy SVD A=U*S*V'.
Definition Matrix.cpp:557
Matrix3 skewSymmetric(double wx, double wy, double wz)
skew symmetric matrix returns this: 0 -wz wy wz 0 -wx -wy wx 0
Definition Matrix.h:365
Matrix expm(const Matrix &A, size_t K)
Numerical exponential map, naive approach, not industrial strength !
Definition Matrix.cpp:587
bool operator!=(const Matrix &A, const Matrix &B)
inequality
Definition Matrix.h:107
std::tuple< int, double, Vector > DLT(const Matrix &A, double rank_tol)
Direct linear transform algorithm that calls svd to find a vector v that minimizes the algebraic erro...
Definition Matrix.cpp:565
void householder_(Matrix &A, size_t k, bool copy_vectors)
Imperative version of Householder QR factorization, Golub & Van Loan p 224 version with Householder v...
Definition Matrix.cpp:315
Eigen::Ref< const Matrix, 0, Eigen::Stride< Eigen::Dynamic, Eigen::Dynamic > > ConstMatrixView
Dynamic-stride const Matrix view for accepting NumPy arrays without copies.
Definition Matrix.h:42
pair< Matrix, Matrix > qr(const Matrix &A)
Householder QR factorization, Golub & Van Loan p 224, explicit version.
Definition Matrix.cpp:224
Matrix diag(const std::vector< Matrix > &Hs)
Create a matrix with submatrices along its diagonal.
Definition Matrix.cpp:194
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
equals with a tolerance
Definition Matrix.h:81
bool operator==(const Matrix &A, const Matrix &B)
equality is just equal_with_abs_tol 1e-9
Definition Matrix.h:100
Matrix inverse_square_root(const Matrix &A)
Use Cholesky to calculate inverse square root of a matrix.
Definition Matrix.cpp:549
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Functor that implements multiplication of a vector b with the inverse of a matrix A.
Definition Matrix.h:426
VectorN operator()(const MatrixN &A, const VectorN &b, OptionalJacobian< N, N *N > H1={}, OptionalJacobian< N, N > H2={}) const
A.inverse() * b, with optional derivatives.
Definition Matrix.h:431
VectorN operator()(const T &a, const VectorN &b, OptionalJacobian< N, M > H1={}, OptionalJacobian< N, N > H2={}) const
f(a).inverse() * b, with optional derivatives
Definition Matrix.h:467
MultiplyWithInverseFunction(const Operator &phi)
Construct with function as explained above.
Definition Matrix.h:464
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40