9 #ifndef mrpt_math_vector_ops_H 10 #define mrpt_math_vector_ops_H 31 template <
typename T, std::
size_t N>
42 template <
typename T1,
typename T2>
43 inline std::vector<T1>&
operator*=(std::vector<T1>&
a,
const std::vector<T2>&
b)
46 const size_t N =
a.size();
47 for (
size_t i = 0; i < N; i++)
a[i] *=
b[i];
52 template <
typename T1>
55 const size_t N =
a.size();
56 for (
size_t i = 0; i < N; i++)
a[i] *=
b;
61 template <
typename T1,
typename T2>
63 const std::vector<T1>&
a,
const std::vector<T2>&
b)
66 const size_t N =
a.size();
67 std::vector<T1> ret(N);
68 for (
size_t i = 0; i < N; i++) ret[i] =
a[i] *
b[i];
73 template <
typename T1,
typename T2>
74 inline std::vector<T1>&
operator+=(std::vector<T1>&
a,
const std::vector<T2>&
b)
77 const size_t N =
a.size();
78 for (
size_t i = 0; i < N; i++)
a[i] +=
b[i];
83 template <
typename T1>
86 const size_t N =
a.size();
87 for (
size_t i = 0; i < N; i++)
a[i] +=
b;
92 template <
typename T1,
typename T2>
94 const std::vector<T1>&
a,
const std::vector<T2>&
b)
97 const size_t N =
a.size();
98 std::vector<T1> ret(N);
99 for (
size_t i = 0; i < N; i++) ret[i] =
a[i] +
b[i];
103 template <
typename T1,
typename T2>
105 const std::vector<T1>&
v1,
const std::vector<T2>&
v2)
108 std::vector<T1>
res(
v1.size());
109 for (
size_t i = 0; i <
v1.size(); i++)
res[i] =
v1[i] -
v2[i];
118 std::ostream& operator<<(std::ostream& out, const std::vector<T>& d)
120 const std::streamsize old_pre = out.precision();
121 const std::ios_base::fmtflags old_flags = out.flags();
122 out <<
"[" << std::fixed << std::setprecision(4);
123 std::copy(d.begin(), d.end(), std::ostream_iterator<T>(out,
" "));
125 out.flags(old_flags);
126 out.precision(old_pre);
133 std::ostream& operator<<(std::ostream& out, std::vector<T>* d)
135 const std::streamsize old_pre = out.precision();
136 const std::ios_base::fmtflags old_flags = out.flags();
137 out <<
"[" << std::fixed << std::setprecision(4);
138 copy(d->begin(), d->end(), std::ostream_iterator<T>(out,
" "));
140 out.flags(old_flags);
141 out.precision(old_pre);
146 template <
typename T,
size_t N>
150 ostrm << mrpt::utils::TTypeName<CArrayNumeric<T, N>>::get();
156 template <
typename T,
size_t N>
166 "Error deserializing: expected '%s', got '%s'",
167 namExpect.c_str(), nam.c_str()))
#define ASSERT_EQUAL_(__A, __B)
A template to obtain the type of its argument as a string at compile time.
This file implements several operations that operate element-wise on individual or pairs of container...
CArrayNumeric is an array for numeric types supporting several mathematical operations (actually...
void WriteBufferFixEndianness(const T *ptr, size_t ElementCount)
Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running arch...
std::vector< T1 > operator+(const std::vector< T1 > &a, const std::vector< T2 > &b)
a+b (element-wise sum)
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
std::ostream & operator<<(std::ostream &o, const TPoint2D &p)
std::vector< T1 > & operator+=(std::vector< T1 > &a, const std::vector< T2 > &b)
a+=b (element-wise sum)
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
GLsizei const GLchar ** string
mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, CMatrix::Ptr &pObj)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
size_t ReadBufferFixEndianness(T *ptr, size_t ElementCount)
Reads a sequence of elemental datatypes, taking care of reordering their bytes from the MRPT stream s...
GLfloat GLfloat GLfloat v2
#define ASSERTMSG_(f, __ERROR_MSG)
GLubyte GLubyte GLubyte a
TPoint3D operator-(const TPoint3D &p1)
Unary minus operator for 3D points.
std::vector< T1 > & operator*=(std::vector< T1 > &a, const std::vector< T2 > &b)
a*=b (element-wise multiplication)
std::vector< T1 > operator*(const std::vector< T1 > &a, const std::vector< T2 > &b)
a*b (element-wise multiplication)