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 // \callgraph
22 
23 #pragma once
24 #ifndef MKL_BLAS
25 #define MKL_BLAS MKL_DOMAIN_BLAS
26 #endif
27 
28 #include <gtsam/global_includes.h>
29 #include <Eigen/Core>
30 #include <iosfwd>
31 #include <list>
32 
33 namespace gtsam {
34 
35 // Vector is just a typedef of the Eigen dynamic vector type
36 
37 // Typedef arbitary length vector
38 typedef Eigen::VectorXd Vector;
39 
40 // Commonly used fixed size vectors
42 typedef Eigen::Vector2d Vector2;
43 typedef Eigen::Vector3d Vector3;
44 
47 
48 // Create handy typedefs and constants for vectors with N>3
49 // VectorN and Z_Nx1, for N=1..9
50 #define GTSAM_MAKE_VECTOR_DEFS(N) \
51  typedef Eigen::Matrix<double, N, 1> Vector##N; \
52  static const Eigen::MatrixBase<Vector##N>::ConstantReturnType Z_##N##x1 = Vector##N::Zero();
53 
63 
66 
72 #if defined(GTSAM_EIGEN_VERSION_WORLD)
73 static_assert(
74  GTSAM_EIGEN_VERSION_WORLD==EIGEN_WORLD_VERSION &&
75  GTSAM_EIGEN_VERSION_MAJOR==EIGEN_MAJOR_VERSION,
76  "Error: GTSAM was built against a different version of Eigen");
77 #endif
78 
95 GTSAM_EXPORT bool fpEqual(double a, double b, double tol,
96  bool check_relative_also = true);
97 
101 GTSAM_EXPORT void print(const Vector& v, const std::string& s, std::ostream& stream);
102 
106 GTSAM_EXPORT void print(const Vector& v, const std::string& s = "");
107 
111 GTSAM_EXPORT void save(const Vector& A, const std::string &s, const std::string& filename);
112 
116 GTSAM_EXPORT bool operator==(const Vector& vec1,const Vector& vec2);
117 
123 GTSAM_EXPORT bool greaterThanOrEqual(const Vector& v1, const Vector& v2);
124 
128 GTSAM_EXPORT bool equal_with_abs_tol(const Vector& vec1, const Vector& vec2, double tol=1e-9);
129 GTSAM_EXPORT bool equal_with_abs_tol(const SubVector& vec1, const SubVector& vec2, double tol=1e-9);
130 
134 inline bool equal(const Vector& vec1, const Vector& vec2, double tol) {
135  return equal_with_abs_tol(vec1, vec2, tol);
136 }
137 
141 inline bool equal(const Vector& vec1, const Vector& vec2) {
142  return equal_with_abs_tol(vec1, vec2);
143 }
144 
152 GTSAM_EXPORT bool assert_equal(const Vector& vec1, const Vector& vec2, double tol=1e-9);
153 
161 GTSAM_EXPORT bool assert_inequal(const Vector& vec1, const Vector& vec2, double tol=1e-9);
162 
170 GTSAM_EXPORT bool assert_equal(const SubVector& vec1, const SubVector& vec2, double tol=1e-9);
171 GTSAM_EXPORT bool assert_equal(const ConstSubVector& vec1, const ConstSubVector& vec2, double tol=1e-9);
172 
180 GTSAM_EXPORT bool linear_dependent(const Vector& vec1, const Vector& vec2, double tol=1e-9);
181 
188 GTSAM_EXPORT Vector ediv_(const Vector &a, const Vector &b);
189 
193 template<class V1, class V2>
194 inline double dot(const V1 &a, const V2& b) {
195  assert (b.size()==a.size());
196  return a.dot(b);
197 }
198 
200 template<class V1, class V2>
201 inline double inner_prod(const V1 &a, const V2& b) {
202  assert (b.size()==a.size());
203  return a.dot(b);
204 }
205 
210 inline void scal(double alpha, Vector& x) { x *= alpha; }
211 
216 template<class V1, class V2>
217 inline void axpy(double alpha, const V1& x, V2& y) {
218  assert (y.size()==x.size());
219  y += alpha * x;
220 }
221 inline void axpy(double alpha, const Vector& x, SubVector y) {
222  assert (y.size()==x.size());
223  y += alpha * x;
224 }
225 
231 GTSAM_EXPORT std::pair<double,Vector> house(const Vector &x);
232 
234 GTSAM_EXPORT double houseInPlace(Vector &x);
235 
246 GTSAM_EXPORT std::pair<Vector, double>
247 weightedPseudoinverse(const Vector& v, const Vector& weights);
248 
249 /*
250  * Fast version *no error checking* !
251  * Pass in initialized vector pseudo of size(weights) or will crash !
252  * @return the precision, pseudoinverse in third argument
253  */
254 GTSAM_EXPORT double weightedPseudoinverse(const Vector& a, const Vector& weights, Vector& pseudo);
255 
259 GTSAM_EXPORT Vector concatVectors(const std::list<Vector>& vs);
260 
264 GTSAM_EXPORT Vector concatVectors(size_t nrVectors, ...);
265 } // namespace gtsam
266 
267 #include <boost/serialization/nvp.hpp>
268 #include <boost/serialization/array.hpp>
269 #include <boost/serialization/split_free.hpp>
270 
271 namespace boost {
272  namespace serialization {
273 
274  // split version - copies into an STL vector for serialization
275  template<class Archive>
276  void save(Archive & ar, const gtsam::Vector & v, unsigned int /*version*/) {
277  const size_t size = v.size();
278  ar << BOOST_SERIALIZATION_NVP(size);
279  ar << make_nvp("data", make_array(v.data(), v.size()));
280  }
281 
282  template<class Archive>
283  void load(Archive & ar, gtsam::Vector & v, unsigned int /*version*/) {
284  size_t size;
285  ar >> BOOST_SERIALIZATION_NVP(size);
286  v.resize(size);
287  ar >> make_nvp("data", make_array(v.data(), v.size()));
288  }
289 
290  // split version - copies into an STL vector for serialization
291  template<class Archive, int D>
292  void save(Archive & ar, const Eigen::Matrix<double,D,1> & v, unsigned int /*version*/) {
293  ar << make_nvp("data", make_array(v.data(), v.RowsAtCompileTime));
294  }
295 
296  template<class Archive, int D>
297  void load(Archive & ar, Eigen::Matrix<double,D,1> & v, unsigned int /*version*/) {
298  ar >> make_nvp("data", make_array(v.data(), v.RowsAtCompileTime));
299  }
300 
301  } // namespace serialization
302 } // namespace boost
303 
304 BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector)
305 BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector2)
306 BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector3)
307 BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector6)
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
Generic expression of a matrix where all coefficients are defined by a functor.
Vector ediv_(const Vector &a, const Vector &b)
Definition: Vector.cpp:199
void save(const Matrix &A, const string &s, const string &filename)
Definition: Matrix.cpp:166
double weightedPseudoinverse(const Vector &a, const Vector &weights, Vector &pseudo)
Definition: Vector.cpp:246
static const Eigen::MatrixBase< Vector3 >::ConstantReturnType Z_3x1
Definition: Vector.h:46
Scalar * y
Vector v2
Eigen::Vector3d Vector3
Definition: Vector.h:43
double dot(const V1 &a, const V2 &b)
Definition: Vector.h:194
Vector v1
ArrayXcf v
Definition: Cwise_arg.cpp:1
GTSAM_MAKE_VECTOR_DEFS(4)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Included from all GTSAM files.
bool operator==(const Matrix &A, const Matrix &B)
Definition: base/Matrix.h:103
Array33i a
bool fpEqual(double a, double b, double tol, bool check_relative_also)
Definition: Vector.cpp:42
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Expression of a fixed-size or dynamic-size sub-vector.
void load(Archive &ar, Eigen::Matrix< double, D, 1 > &v, unsigned int)
Definition: Vector.h:297
Eigen::VectorXd Vector
Definition: Vector.h:38
#define EIGEN_WORLD_VERSION
Definition: Macros.h:14
RealScalar alpha
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
void axpy(double alpha, const V1 &x, V2 &y)
Definition: Vector.h:217
const G & b
Definition: Group.h:83
bool greaterThanOrEqual(const Vector &vec1, const Vector &vec2)
Definition: Vector.cpp:114
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
Definition: base/Matrix.h:84
Eigen::Matrix< double, 1, 1 > Vector1
Definition: Vector.h:41
traits
Definition: chartTesting.h:28
void scal(double alpha, Vector &x)
Definition: Vector.h:210
bool linear_dependent(const Matrix &A, const Matrix &B, double tol)
Definition: Matrix.cpp:116
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
RowVectorXd vec1(3)
Eigen::Vector2d Vector2
Definition: Vector.h:42
#define EIGEN_MAJOR_VERSION
Definition: Macros.h:15
double inner_prod(const V1 &a, const V2 &b)
Definition: Vector.h:201
bool assert_inequal(const Matrix &A, const Matrix &B, double tol)
Definition: Matrix.cpp:62
pair< double, Vector > house(const Vector &x)
Definition: Vector.cpp:237
const G double tol
Definition: Group.h:83
The matrix class, also used for vectors and row-vectors.
bool equal(const T &obj1, const T &obj2, double tol)
Definition: Testable.h:83
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 x
static const Eigen::MatrixBase< Vector2 >::ConstantReturnType Z_2x1
Definition: Vector.h:45
Vector concatVectors(const std::list< Vector > &vs)
Definition: Vector.cpp:302
double houseInPlace(Vector &v)
Definition: Vector.cpp:212
Eigen::VectorBlock< Vector > SubVector
Definition: Vector.h:64
Eigen::VectorBlock< const Vector > ConstSubVector
Definition: Vector.h:65


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:51:23