29 #include <gtsam/config.h> 31 #include <boost/format.hpp> 32 #include <boost/function.hpp> 33 #include <boost/tuple/tuple.hpp> 34 #include <boost/math/special_functions/fpclassify.hpp> 48 #define GTSAM_MAKE_MATRIX_DEFS(N) \ 49 typedef Eigen::Matrix<double, N, N> Matrix##N; \ 50 typedef Eigen::Matrix<double, 1, N> Matrix1##N; \ 51 typedef Eigen::Matrix<double, 2, N> Matrix2##N; \ 52 typedef Eigen::Matrix<double, 3, N> Matrix3##N; \ 53 typedef Eigen::Matrix<double, 4, N> Matrix4##N; \ 54 typedef Eigen::Matrix<double, 5, N> Matrix5##N; \ 55 typedef Eigen::Matrix<double, 6, N> Matrix6##N; \ 56 typedef Eigen::Matrix<double, 7, N> Matrix7##N; \ 57 typedef Eigen::Matrix<double, 8, N> Matrix8##N; \ 58 typedef Eigen::Matrix<double, 9, N> Matrix9##N; \ 59 static const Eigen::MatrixBase<Matrix##N>::IdentityReturnType I_##N##x##N = Matrix##N::Identity(); \ 60 static const Eigen::MatrixBase<Matrix##N>::ConstantReturnType Z_##N##x##N = Matrix##N::Zero(); 83 template <
class MATRIX>
86 const size_t n1 = A.cols(),
m1 = A.rows();
87 const size_t n2 = B.cols(),
m2 = B.rows();
89 if(
m1!=
m2 || n1!=n2)
return false;
91 for(
size_t i=0;
i<
m1;
i++)
92 for(
size_t j=0;
j<
n1;
j++) {
122 GTSAM_EXPORT
bool assert_inequal(
const Matrix& A,
const Matrix& B,
double tol = 1
e-9);
127 GTSAM_EXPORT
bool assert_equal(
const std::list<Matrix>& As,
const std::list<Matrix>& Bs,
double tol = 1
e-9);
146 template<
class MATRIX>
147 inline MATRIX
prod(
const MATRIX& A,
const MATRIX&B) {
155 GTSAM_EXPORT
void print(
const Matrix& A,
const std::string&
s, std::ostream&
stream);
160 GTSAM_EXPORT
void print(
const Matrix& A,
const std::string& s =
"");
165 GTSAM_EXPORT
void save(
const Matrix& A,
const std::string &s,
const std::string&
filename);
172 GTSAM_EXPORT std::istream&
operator>>(std::istream& inputStream, Matrix& destinationMatrix);
183 template<
class MATRIX>
185 size_t m=i2-i1,
n=j2-j1;
186 return A.block(i1,j1,m,n);
197 template <
typename Derived1,
typename Derived2>
199 fullMatrix.
block(i, j, subMatrix.rows(), subMatrix.cols()) = subMatrix;
205 GTSAM_EXPORT Matrix
diag(
const std::vector<Matrix>& Hs);
213 template<
class MATRIX>
224 template<
class MATRIX>
234 template<
class MATRIX>
236 const size_t m = A.rows(),
n = A.cols();
238 for (
size_t j=0;
j<k; ++
j)
239 A.col(
j).segment(
j+1, m-(
j+1)).setZero();
245 inline Matrix
trans(
const Matrix& A) {
return A.transpose(); }
248 template <
int OutM,
int OutN,
int OutOptions,
int InM,
int InN,
int InOptions>
258 template <
int M,
int InOptions>
267 template <
int M,
int N,
int InOptions>
276 template <
int M,
int N,
int InOptions>
280 return in.transpose();
284 template <
int OutM,
int OutN,
int OutOptions,
int InM,
int InN,
int InOptions>
286 BOOST_STATIC_ASSERT(InM * InN == OutM * OutN);
296 GTSAM_EXPORT std::pair<Matrix,Matrix>
qr(
const Matrix& A);
313 GTSAM_EXPORT std::list<boost::tuple<Vector, double, double> >
323 GTSAM_EXPORT
void householder_(Matrix& A,
size_t k,
bool copy_vectors=
true);
331 GTSAM_EXPORT
void householder(Matrix& A,
size_t k);
367 GTSAM_EXPORT Matrix
stack(
size_t nrMatrices, ...);
368 GTSAM_EXPORT Matrix
stack(
const std::vector<Matrix>& blocks);
380 GTSAM_EXPORT Matrix
collect(
const std::vector<const Matrix *>& matrices,
size_t m = 0,
size_t n = 0);
381 GTSAM_EXPORT Matrix
collect(
size_t nrMatrices, ...);
390 GTSAM_EXPORT Matrix
vector_scale(
const Vector& v,
const Matrix& A,
bool inf_mask =
false);
391 GTSAM_EXPORT Matrix
vector_scale(
const Matrix& A,
const Vector& v,
bool inf_mask =
false);
405 return (Matrix3() << 0.0, -wz, +wy, +wz, 0.0, -wx, -wy, +wx, 0.0).finished();
408 template <
class Derived>
431 GTSAM_EXPORT
void svd(
const Matrix& A, Matrix& U,
Vector&
S, Matrix&
V);
440 GTSAM_EXPORT boost::tuple<int, double, Vector>
441 DLT(
const Matrix& A,
double rank_tol = 1
e-9);
448 GTSAM_EXPORT Matrix
expm(
const Matrix& A,
size_t K=7);
467 const MatrixN invA = A.inverse();
468 const VectorN
c = invA *
b;
471 for (
size_t j = 0;
j <
N;
j++)
472 H1->template middleCols<N>(N *
j) = -c[
j] * invA;
484 template <
typename T,
int N>
492 typedef boost::function<VectorN(
504 phi_(a, b, boost::none, A);
505 const MatrixN invA = A.inverse();
506 const VectorN
c = invA *
b;
510 phi_(a, c, H, boost::none);
521 GTSAM_EXPORT Matrix
LLt(
const Matrix& A);
523 GTSAM_EXPORT Matrix
RtR(
const Matrix& A);
528 #include <boost/serialization/nvp.hpp> 529 #include <boost/serialization/array.hpp> 530 #include <boost/serialization/split_free.hpp> 533 namespace serialization {
550 template<
class Archive,
559 const unsigned int ) {
561 ar << BOOST_SERIALIZATION_NVP(rows);
562 ar << BOOST_SERIALIZATION_NVP(
cols);
563 ar << make_nvp(
"data", make_array(m.
data(), m.size()));
566 template<
class Archive,
575 const unsigned int ) {
577 ar >> BOOST_SERIALIZATION_NVP(rows);
578 ar >> BOOST_SERIALIZATION_NVP(cols);
580 ar >> make_nvp(
"data", make_array(m.
data(), m.size()));
584 template<
class Archive,
594 split_free(ar, m, version);
598 template <
class Archive>
600 split_free(ar, m, version);
void print(const Matrix &A, const string &s, ostream &stream)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const
std::string formatMatrixIndented(const std::string &label, const Matrix &matrix, bool makeVectorHorizontal)
void inplace_QR(Matrix &A)
boost::tuple< int, double, Vector > DLT(const Matrix &A, double rank_tol)
void zeroBelowDiagonal(MATRIX &A, size_t cols=0)
Eigen::Matrix< double, M, N, InOptions >::ConstTransposeReturnType ReshapedType
const MATRIX::ConstRowXpr row(const MATRIX &A, size_t j)
Matrix< RealScalar, Dynamic, Dynamic > M
Eigen::Matrix< double, N, N > MatrixN
MATRIX prod(const MATRIX &A, const MATRIX &B)
void save(const Matrix &A, const string &s, const string &filename)
bool operator!=(const Matrix &A, const Matrix &B)
boost::function< VectorN(const T &, const VectorN &, OptionalJacobian< N, M >, OptionalJacobian< N, N >)> Operator
const Block< const Derived, internal::traits< Derived >::RowsAtCompileTime, 1,!IsRowMajor > ConstColXpr
static ReshapedType reshape(const Eigen::Matrix< double, InM, InN, InOptions > &in)
Matrix diag(const std::vector< Matrix > &Hs)
std::string serialize(const T &input)
serializes to a string
void householder(Matrix &A, size_t k)
const Eigen::Matrix< double, M, N, InOptions > & ReshapedType
A matrix or vector expression mapping an existing array of data.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const
GTSAM_MAKE_MATRIX_DEFS(1)
void vector_scale_inplace(const Vector &v, Matrix &A, bool inf_mask)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
static ReshapedType reshape(const Eigen::Matrix< double, M, M, InOptions > &in)
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
const Eigen::Matrix< double, M, M, InOptions > & ReshapedType
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
Base class for all dense matrices, vectors, and arrays.
Vector backSubstituteLower(const Matrix &L, const Vector &b, bool unit)
T expm(const Vector &x, int K=7)
Matrix vector_scale(const Vector &v, const Matrix &A, bool inf_mask)
Matrix trans(const Matrix &A)
Matrix RtR(const Matrix &A)
VectorN operator()(const MatrixN &A, const VectorN &b, OptionalJacobian< N, N *N > H1=boost::none, OptionalJacobian< N, N > H2=boost::none) const
A.inverse() * b, with optional derivatives.
bool operator==(const Matrix &A, const Matrix &B)
Eigen::Block< const Matrix > ConstSubMatrix
bool fpEqual(double a, double b, double tol, bool check_relative_also)
EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL EIGEN_DEVICE_FUNC BlockXpr block(Index startRow, Index startCol, Index blockRows, Index blockCols)
Matrix LLt(const Matrix &A)
const Eigen::IOFormat & matlabFormat()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixRowMajor
istream & operator>>(istream &inputStream, Matrix &destinationMatrix)
MultiplyWithInverseFunction(const Operator &phi)
Construct with function as explained above.
Eigen::Matrix< double, N, 1 > VectorN
static ReshapedType reshape(const Eigen::Matrix< double, M, N, InOptions > &in)
pair< Matrix, Matrix > qr(const Matrix &A)
void householder_(Matrix &A, size_t k, bool copy_vectors)
list< boost::tuple< Vector, double, double > > weighted_eliminate(Matrix &A, Vector &b, const Vector &sigmas)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Eigen::Block< Matrix > SubMatrix
Eigen::Map< const Eigen::Matrix< double, OutM, OutN, OutOptions > > ReshapedType
const Block< const Derived, 1, internal::traits< Derived >::ColsAtCompileTime, IsRowMajor > ConstRowXpr
Vector operator^(const Matrix &A, const Vector &v)
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
typedef and functions to augment Eigen's VectorXd
bool linear_dependent(const Matrix &A, const Matrix &B, double tol)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Matrix3 skewSymmetric(double wx, double wy, double wz)
Matrix inverse_square_root(const Matrix &A)
Expression of a fixed-size or dynamic-size block.
Vector columnNormSquare(const Matrix &A)
void insertSub(Eigen::MatrixBase< Derived1 > &fullMatrix, const Eigen::MatrixBase< Derived2 > &subMatrix, size_t i, size_t j)
void svd(const Matrix &A, Matrix &U, Vector &S, Matrix &V)
Eigen::Matrix< double, N, 1 > VectorN
Vector backSubstituteUpper(const Matrix &U, const Vector &b, bool unit)
Matrix stack(size_t nrMatrices,...)
bool assert_inequal(const Matrix &A, const Matrix &B, double tol)
bool linear_independent(const Matrix &A, const Matrix &B, double tol)
Eigen::Block< const MATRIX > sub(const MATRIX &A, size_t i1, size_t i2, size_t j1, size_t j2)
static ReshapedType reshape(const Eigen::Matrix< double, M, N, InOptions > &in)
VectorN operator()(const T &a, const VectorN &b, OptionalJacobian< N, M > H1=boost::none, OptionalJacobian< N, N > H2=boost::none) const
f(a).inverse() * b, with optional derivatives
Matrix collect(const std::vector< const Matrix * > &matrices, size_t m, size_t n)
Special class for optional Jacobian arguments.
Eigen::Matrix< double, N, N > MatrixN
void load(Archive &ar, Eigen::Matrix< Scalar_, Rows_, Cols_, Ops_, MaxRows_, MaxCols_ > &m, const unsigned int)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
The matrix class, also used for vectors and row-vectors.
Matrix cholesky_inverse(const Matrix &A)
const MATRIX::ConstColXpr column(const MATRIX &A, size_t j)
Base class for all dense matrices, vectors, and expressions.