gtsam 4.2.2
gtsam
Loading...
Searching...
No Matches
Vector.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
20
21// \callgraph
22
23#pragma once
24#ifndef MKL_BLAS
25#define MKL_BLAS MKL_DOMAIN_BLAS
26#endif
27
29#include <Eigen/Core>
30#include <cassert>
31#include <iosfwd>
32#include <list>
33
34namespace gtsam {
35
36// Vector is just a typedef of the Eigen dynamic vector type
37
38// Typedef arbitary length vector
39typedef Eigen::VectorXd Vector;
40
41// Commonly used fixed size vectors
42typedef Eigen::Matrix<double, 1, 1> Vector1;
43typedef Eigen::Vector2d Vector2;
44typedef Eigen::Vector3d Vector3;
45
46#define Z_2x1 Vector2::Constant(0.0)
47#define Z_3x1 Vector3::Constant(0.0)
48#define Z_4x1 Vector4::Constant(0.0)
49#define Z_5x1 Vector5::Constant(0.0)
50#define Z_6x1 Vector6::Constant(0.0)
51#define Z_7x1 Vector7::Constant(0.0)
52#define Z_8x1 Vector8::Constant(0.0)
53#define Z_9x1 Vector9::Constant(0.0)
54#define Z_10x1 Vector10::Constant(0.0)
55#define Z_11x1 Vector11::Constant(0.0)
56#define Z_12x1 Vector12::Constant(0.0)
57#define Z_15x1 Vector15::Constant(0.0)
58
59// Create handy typedefs and constants for vectors with N>3
60// VectorN and Z_Nx1, for N=1..9
61#define GTSAM_MAKE_VECTOR_DEFS(N) \
62 using Vector##N = Eigen::Matrix<double, N, 1>;
63
64GTSAM_MAKE_VECTOR_DEFS(4)
65GTSAM_MAKE_VECTOR_DEFS(5)
66GTSAM_MAKE_VECTOR_DEFS(6)
67GTSAM_MAKE_VECTOR_DEFS(7)
68GTSAM_MAKE_VECTOR_DEFS(8)
69GTSAM_MAKE_VECTOR_DEFS(9)
70GTSAM_MAKE_VECTOR_DEFS(10)
71GTSAM_MAKE_VECTOR_DEFS(11)
72GTSAM_MAKE_VECTOR_DEFS(12)
73GTSAM_MAKE_VECTOR_DEFS(15)
74
75typedef Eigen::VectorBlock<Vector> SubVector;
76typedef Eigen::VectorBlock<const Vector> ConstSubVector;
77
83#if defined(GTSAM_EIGEN_VERSION_WORLD)
84static_assert(
85 GTSAM_EIGEN_VERSION_WORLD==EIGEN_WORLD_VERSION &&
86 GTSAM_EIGEN_VERSION_MAJOR==EIGEN_MAJOR_VERSION,
87 "Error: GTSAM was built against a different version of Eigen");
88#endif
89
106GTSAM_EXPORT bool fpEqual(double a, double b, double tol,
107 bool check_relative_also = true);
108
112GTSAM_EXPORT void print(const Vector& v, const std::string& s, std::ostream& stream);
113
117GTSAM_EXPORT void print(const Vector& v, const std::string& s = "");
118
122GTSAM_EXPORT void save(const Vector& A, const std::string &s, const std::string& filename);
123
127GTSAM_EXPORT bool operator==(const Vector& vec1,const Vector& vec2);
128
134GTSAM_EXPORT bool greaterThanOrEqual(const Vector& v1, const Vector& v2);
135
139GTSAM_EXPORT bool equal_with_abs_tol(const Vector& vec1, const Vector& vec2, double tol=1e-9);
140GTSAM_EXPORT bool equal_with_abs_tol(const SubVector& vec1, const SubVector& vec2, double tol=1e-9);
141
145inline bool equal(const Vector& vec1, const Vector& vec2, double tol) {
146 return equal_with_abs_tol(vec1, vec2, tol);
147}
148
152inline bool equal(const Vector& vec1, const Vector& vec2) {
153 return equal_with_abs_tol(vec1, vec2);
154}
155
163GTSAM_EXPORT bool assert_equal(const Vector& vec1, const Vector& vec2, double tol=1e-9);
164
172GTSAM_EXPORT bool assert_inequal(const Vector& vec1, const Vector& vec2, double tol=1e-9);
173
181GTSAM_EXPORT bool assert_equal(const SubVector& vec1, const SubVector& vec2, double tol=1e-9);
182GTSAM_EXPORT bool assert_equal(const ConstSubVector& vec1, const ConstSubVector& vec2, double tol=1e-9);
183
191GTSAM_EXPORT bool linear_dependent(const Vector& vec1, const Vector& vec2, double tol=1e-9);
192
199GTSAM_EXPORT Vector ediv_(const Vector &a, const Vector &b);
200
204template<class V1, class V2>
205inline double dot(const V1 &a, const V2& b) {
206 assert (b.size()==a.size());
207 return a.dot(b);
208}
209
211template<class V1, class V2>
212inline double inner_prod(const V1 &a, const V2& b) {
213 assert (b.size()==a.size());
214 return a.dot(b);
215}
216
217#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V42
222inline void GTSAM_DEPRECATED scal(double alpha, Vector& x) { x *= alpha; }
223
228template<class V1, class V2>
229inline void GTSAM_DEPRECATED axpy(double alpha, const V1& x, V2& y) {
230 assert (y.size()==x.size());
231 y += alpha * x;
232}
233inline void axpy(double alpha, const Vector& x, SubVector y) {
234 assert (y.size()==x.size());
235 y += alpha * x;
236}
237#endif
238
244GTSAM_EXPORT std::pair<double,Vector> house(const Vector &x);
245
247GTSAM_EXPORT double houseInPlace(Vector &x);
248
259GTSAM_EXPORT std::pair<Vector, double>
260weightedPseudoinverse(const Vector& v, const Vector& weights);
261
262/*
263 * Fast version *no error checking* !
264 * Pass in initialized vector pseudo of size(weights) or will crash !
265 * @return the precision, pseudoinverse in third argument
266 */
267GTSAM_EXPORT double weightedPseudoinverse(const Vector& a, const Vector& weights, Vector& pseudo);
268
272GTSAM_EXPORT Vector concatVectors(const std::list<Vector>& vs);
273
277GTSAM_EXPORT Vector concatVectors(size_t nrVectors, ...);
278} // namespace gtsam
Included from all GTSAM files.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Vector ediv_(const Vector &a, const Vector &b)
elementwise division, but 0/0 = 0, not inf
Definition Vector.cpp:199
bool greaterThanOrEqual(const Vector &vec1, const Vector &vec2)
Greater than or equal to operation returns true if all elements in v1 are greater than corresponding ...
Definition Vector.cpp:114
void save(const Matrix &A, const string &s, const string &filename)
save a matrix to file, which can be loaded by matlab
Definition Matrix.cpp:167
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
equals with an tolerance, prints out message if unequal
Definition Matrix.cpp:43
bool linear_dependent(const Matrix &A, const Matrix &B, double tol)
check whether the rows of two matrices are linear dependent
Definition Matrix.cpp:117
double inner_prod(const V1 &a, const V2 &b)
compatibility version for ublas' inner_prod()
Definition Vector.h:212
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
void axpy(double alpha, const Errors &x, Errors &y)
BLAS level 2 style AXPY, y := alpha*x + y.
Definition Errors.cpp:111
bool assert_inequal(const Matrix &A, const Matrix &B, double tol)
inequals with an tolerance, prints out message if within tolerance
Definition Matrix.cpp:63
double houseInPlace(Vector &v)
beta = house(x) computes the HouseHolder vector in place
Definition Vector.cpp:212
bool equal(const T &obj1, const T &obj2, double tol)
Call equal on the object.
Definition Testable.h:84
double dot(const V1 &a, const V2 &b)
Dot product.
Definition Vector.h:205
bool fpEqual(double a, double b, double tol, bool check_relative_also)
Ensure we are not including a different version of Eigen in user code than while compiling gtsam,...
Definition Vector.cpp:42
Vector concatVectors(const std::list< Vector > &vs)
concatenate Vectors
Definition Vector.cpp:302
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:108
pair< double, Vector > house(const Vector &x)
house(x,j) computes HouseHolder vector v and scaling factor beta from x, such that the corresponding ...
Definition Vector.cpp:237
bool operator==(const Matrix &A, const Matrix &B)
equality is just equal_with_abs_tol 1e-9
Definition Matrix.h:127