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
21
22// \callgraph
23
24#pragma once
25#ifndef MKL_BLAS
26#define MKL_BLAS MKL_DOMAIN_BLAS
27#endif
28
30#include <Eigen/Core>
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;
45using Vector4 = Eigen::Matrix<double, 4, 1>;
46using Vector5 = Eigen::Matrix<double, 5, 1>;
47using Vector6 = Eigen::Matrix<double, 6, 1>;
48using Vector7 = Eigen::Matrix<double, 7, 1>;
49using Vector8 = Eigen::Matrix<double, 8, 1>;
50using Vector9 = Eigen::Matrix<double, 9, 1>;
51using Vector10 = Eigen::Matrix<double, 10, 1>;
52using Vector11 = Eigen::Matrix<double, 11, 1>;
53using Vector12 = Eigen::Matrix<double, 12, 1>;
54using Vector15 = Eigen::Matrix<double, 15, 1>;
55
56typedef Eigen::VectorBlock<Vector> SubVector;
57typedef Eigen::VectorBlock<const Vector> ConstSubVector;
58
64#if defined(GTSAM_EIGEN_VERSION_WORLD)
65static_assert(
66 GTSAM_EIGEN_VERSION_WORLD==EIGEN_WORLD_VERSION &&
67 GTSAM_EIGEN_VERSION_MAJOR==EIGEN_MAJOR_VERSION,
68 "Error: GTSAM was built against a different version of Eigen");
69#endif
70
87GTSAM_EXPORT bool fpEqual(double a, double b, double tol,
88 bool check_relative_also = true);
89
93GTSAM_EXPORT void print(const Vector& v, const std::string& s, std::ostream& stream);
94
98GTSAM_EXPORT void print(const Vector& v, const std::string& s = "");
99
103GTSAM_EXPORT void save(const Vector& A, const std::string &s, const std::string& filename);
104
105#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
110GTSAM_EXPORT bool operator==(const Vector& vec1, const Vector& vec2);
111
119GTSAM_EXPORT bool greaterThanOrEqual(const Vector& v1, const Vector& v2);
120#endif
121
125GTSAM_EXPORT bool equal_with_abs_tol(const Vector& vec1, const Vector& vec2, double tol=1e-9);
126GTSAM_EXPORT bool equal_with_abs_tol(const SubVector& vec1, const SubVector& vec2, double tol=1e-9);
127
131inline bool equal(const Vector& vec1, const Vector& vec2, double tol) {
132 return equal_with_abs_tol(vec1, vec2, tol);
133}
134
138inline bool equal(const Vector& vec1, const Vector& vec2) {
139 return equal_with_abs_tol(vec1, vec2);
140}
141
149GTSAM_EXPORT bool assert_equal(const Vector& vec1, const Vector& vec2, double tol=1e-9);
150
158GTSAM_EXPORT bool assert_inequal(const Vector& vec1, const Vector& vec2, double tol=1e-9);
159
167GTSAM_EXPORT bool assert_equal(const SubVector& vec1, const SubVector& vec2, double tol=1e-9);
168GTSAM_EXPORT bool assert_equal(const ConstSubVector& vec1, const ConstSubVector& vec2, double tol=1e-9);
169
177GTSAM_EXPORT bool linear_dependent(const Vector& vec1, const Vector& vec2, double tol=1e-9);
178
185GTSAM_EXPORT Vector ediv_(const Vector &a, const Vector &b);
186
190template<class V1, class V2>
191inline double dot(const V1 &a, const V2& b) {
192 return a.dot(b);
193}
194
195#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
200template<class V1, class V2>
201inline double inner_prod(const V1 &a, const V2& b) {
202 return a.dot(b);
203}
204#endif
205
211GTSAM_EXPORT std::pair<double,Vector> house(const Vector &x);
212
214GTSAM_EXPORT double houseInPlace(Vector &x);
215
226GTSAM_EXPORT std::pair<Vector, double>
227weightedPseudoinverse(const Vector& v, const Vector& weights);
228
229/*
230 * Fast version *no error checking* !
231 * Pass in initialized vector pseudo of size(weights) or will crash !
232 * @return the precision, pseudoinverse in third argument
233 */
234GTSAM_EXPORT double weightedPseudoinverse(const Vector& a, const Vector& weights, Vector& pseudo);
235
239GTSAM_EXPORT Vector concatVectors(const std::list<Vector>& vs);
240
241#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V43
246GTSAM_EXPORT Vector concatVectors(size_t nrVectors, ...);
247#endif
248} // 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:200
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:154
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
equals with an tolerance, prints out message if unequal
Definition Matrix.cpp:39
bool linear_dependent(const Matrix &A, const Matrix &B, double tol)
check whether the rows of two matrices are linear dependent
Definition Matrix.cpp:113
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
bool assert_inequal(const Matrix &A, const Matrix &B, double tol)
inequals with an tolerance, prints out message if within tolerance
Definition Matrix.cpp:59
double houseInPlace(Vector &v)
beta = house(x) computes the HouseHolder vector in place
Definition Vector.cpp:213
bool equal(const T &obj1, const T &obj2, double tol)
Call equal on the object.
Definition Testable.h:85
double dot(const V1 &a, const V2 &b)
Dot product.
Definition Vector.h:191
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:41
Vector concatVectors(const std::list< Vector > &vs)
concatenate Vectors
Definition Vector.cpp:303
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
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:238
bool operator==(const Matrix &A, const Matrix &B)
equality is just equal_with_abs_tol 1e-9
Definition Matrix.h:100