Loading...
Searching...
No Matches
Vector.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
// \callgraph
#pragma once
#ifndef MKL_BLAS
#define MKL_BLAS MKL_DOMAIN_BLAS
#endif
#include <gtsam/global_includes.h>
#include <Eigen/Core>
#include <cassert>
#include <iosfwd>
#include <list>
namespace gtsam {
// Vector is just a typedef of the Eigen dynamic vector type
// Typedef arbitary length vector
typedef Eigen::VectorXd Vector;
// Commonly used fixed size vectors
typedef Eigen::Matrix<double, 1, 1> Vector1;
typedef Eigen::Vector2d Vector2;
typedef Eigen::Vector3d Vector3;
#define Z_2x1 Vector2::Constant(0.0)
#define Z_3x1 Vector3::Constant(0.0)
#define Z_4x1 Vector4::Constant(0.0)
#define Z_5x1 Vector5::Constant(0.0)
#define Z_6x1 Vector6::Constant(0.0)
#define Z_7x1 Vector7::Constant(0.0)
#define Z_8x1 Vector8::Constant(0.0)
#define Z_9x1 Vector9::Constant(0.0)
#define Z_10x1 Vector10::Constant(0.0)
#define Z_11x1 Vector11::Constant(0.0)
#define Z_12x1 Vector12::Constant(0.0)
#define Z_15x1 Vector15::Constant(0.0)
// Create handy typedefs and constants for vectors with N>3
// VectorN and Z_Nx1, for N=1..9
#define GTSAM_MAKE_VECTOR_DEFS(N) \
using Vector##N = Eigen::Matrix<double, N, 1>;
GTSAM_MAKE_VECTOR_DEFS(4)
GTSAM_MAKE_VECTOR_DEFS(5)
GTSAM_MAKE_VECTOR_DEFS(6)
GTSAM_MAKE_VECTOR_DEFS(7)
GTSAM_MAKE_VECTOR_DEFS(8)
GTSAM_MAKE_VECTOR_DEFS(9)
GTSAM_MAKE_VECTOR_DEFS(10)
GTSAM_MAKE_VECTOR_DEFS(11)
GTSAM_MAKE_VECTOR_DEFS(12)
GTSAM_MAKE_VECTOR_DEFS(15)
typedef Eigen::VectorBlock<Vector> SubVector;
typedef Eigen::VectorBlock<const Vector> ConstSubVector;
#if defined(GTSAM_EIGEN_VERSION_WORLD)
static_assert(
GTSAM_EIGEN_VERSION_WORLD==EIGEN_WORLD_VERSION &&
GTSAM_EIGEN_VERSION_MAJOR==EIGEN_MAJOR_VERSION,
"Error: GTSAM was built against a different version of Eigen");
#endif
GTSAM_EXPORT bool fpEqual(double a, double b, double tol,
bool check_relative_also = true);
GTSAM_EXPORT void print(const Vector& v, const std::string& s, std::ostream& stream);
GTSAM_EXPORT void print(const Vector& v, const std::string& s = "");
GTSAM_EXPORT void save(const Vector& A, const std::string &s, const std::string& filename);
GTSAM_EXPORT bool operator==(const Vector& vec1,const Vector& vec2);
GTSAM_EXPORT bool greaterThanOrEqual(const Vector& v1, const Vector& v2);
GTSAM_EXPORT bool equal_with_abs_tol(const Vector& vec1, const Vector& vec2, double tol=1e-9);
GTSAM_EXPORT bool equal_with_abs_tol(const SubVector& vec1, const SubVector& vec2, double tol=1e-9);
inline bool equal(const Vector& vec1, const Vector& vec2, double tol) {
return equal_with_abs_tol(vec1, vec2, tol);
}
inline bool equal(const Vector& vec1, const Vector& vec2) {
return equal_with_abs_tol(vec1, vec2);
}
GTSAM_EXPORT bool assert_equal(const Vector& vec1, const Vector& vec2, double tol=1e-9);
GTSAM_EXPORT bool assert_inequal(const Vector& vec1, const Vector& vec2, double tol=1e-9);
GTSAM_EXPORT bool assert_equal(const SubVector& vec1, const SubVector& vec2, double tol=1e-9);
GTSAM_EXPORT bool assert_equal(const ConstSubVector& vec1, const ConstSubVector& vec2, double tol=1e-9);
GTSAM_EXPORT bool linear_dependent(const Vector& vec1, const Vector& vec2, double tol=1e-9);
GTSAM_EXPORT Vector ediv_(const Vector &a, const Vector &b);
template<class V1, class V2>
inline double dot(const V1 &a, const V2& b) {
assert (b.size()==a.size());
return a.dot(b);
}
template<class V1, class V2>
inline double inner_prod(const V1 &a, const V2& b) {
assert (b.size()==a.size());
return a.dot(b);
}
#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V42
inline void GTSAM_DEPRECATED scal(double alpha, Vector& x) { x *= alpha; }
template<class V1, class V2>
inline void GTSAM_DEPRECATED axpy(double alpha, const V1& x, V2& y) {
assert (y.size()==x.size());
y += alpha * x;
}
inline void axpy(double alpha, const Vector& x, SubVector y) {
assert (y.size()==x.size());
y += alpha * x;
}
#endif
GTSAM_EXPORT std::pair<double,Vector> house(const Vector &x);
GTSAM_EXPORT double houseInPlace(Vector &x);
GTSAM_EXPORT std::pair<Vector, double>
weightedPseudoinverse(const Vector& v, const Vector& weights);
/*
* Fast version *no error checking* !
* Pass in initialized vector pseudo of size(weights) or will crash !
* @return the precision, pseudoinverse in third argument
*/
GTSAM_EXPORT double weightedPseudoinverse(const Vector& a, const Vector& weights, Vector& pseudo);
GTSAM_EXPORT Vector concatVectors(const std::list<Vector>& vs);
GTSAM_EXPORT Vector concatVectors(size_t nrVectors, ...);
} // namespace gtsam
global_includes.h
Included from all GTSAM files.
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::ediv_
Vector ediv_(const Vector &a, const Vector &b)
elementwise division, but 0/0 = 0, not inf
Definition Vector.cpp:199
gtsam::greaterThanOrEqual
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
gtsam::save
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
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
equals with an tolerance, prints out message if unequal
Definition Matrix.cpp:43
gtsam::linear_dependent
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
gtsam::inner_prod
double inner_prod(const V1 &a, const V2 &b)
compatibility version for ublas' inner_prod()
Definition Vector.h:212
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
gtsam::axpy
void axpy(double alpha, const Errors &x, Errors &y)
BLAS level 2 style AXPY, y := alpha*x + y.
Definition Errors.cpp:111
gtsam::assert_inequal
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
gtsam::houseInPlace
double houseInPlace(Vector &v)
beta = house(x) computes the HouseHolder vector in place
Definition Vector.cpp:212
gtsam::equal
bool equal(const T &obj1, const T &obj2, double tol)
Call equal on the object.
Definition Testable.h:84
gtsam::dot
double dot(const V1 &a, const V2 &b)
Dot product.
Definition Vector.h:205
gtsam::fpEqual
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
gtsam::concatVectors
Vector concatVectors(const std::list< Vector > &vs)
concatenate Vectors
Definition Vector.cpp:302
gtsam::equal_with_abs_tol
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
gtsam::house
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
gtsam::operator==
bool operator==(const Matrix &A, const Matrix &B)
equality is just equal_with_abs_tol 1e-9
Definition Matrix.h:127