9 #ifndef mrpt_math_vector_ops_H 10 #define mrpt_math_vector_ops_H 24 namespace utils {
class CFileStream; }
29 template <
typename T, std::
size_t N>
class CArrayNumeric;
39 template <
typename T1,
typename T2>
40 inline std::vector<T1>&
operator *=(std::vector<T1>&
a,
const std::vector<T2>&
b)
43 const size_t N=
a.size();
44 for (
size_t i=0;i<N;i++)
a[i]*=
b[i];
49 template <
typename T1>
52 const size_t N=
a.size();
53 for (
size_t i=0;i<N;i++)
a[i]*=
b;
58 template <
typename T1,
typename T2>
59 inline std::vector<T1>
operator *(
const std::vector<T1>&
a,
const std::vector<T2>&
b)
62 const size_t N=
a.size();
63 std::vector<T1> ret(N);
64 for (
size_t i=0;i<N;i++) ret[i]=
a[i]*
b[i];
69 template <
typename T1,
typename T2>
70 inline std::vector<T1>&
operator +=(std::vector<T1>&
a,
const std::vector<T2>&
b)
73 const size_t N=
a.size();
74 for (
size_t i=0;i<N;i++)
a[i]+=
b[i];
79 template <
typename T1>
82 const size_t N=
a.size();
83 for (
size_t i=0;i<N;i++)
a[i]+=
b;
88 template <
typename T1,
typename T2>
89 inline std::vector<T1>
operator +(
const std::vector<T1>&
a,
const std::vector<T2>&
b)
92 const size_t N=
a.size();
93 std::vector<T1> ret(N);
94 for (
size_t i=0;i<N;i++) ret[i]=
a[i]+
b[i];
98 template <
typename T1,
typename T2>
99 inline std::vector<T1>
operator -(
const std::vector<T1> &
v1,
const std::vector<T2>&
v2) {
101 std::vector<T1>
res(
v1.size());
102 for (
size_t i=0;i<
v1.size();i++)
res[i]=
v1[i]-
v2[i];
112 std::ostream& operator << (std::ostream& out, const std::vector<T> &d)
114 const std::streamsize old_pre = out.precision();
115 const std::ios_base::fmtflags old_flags = out.flags();
116 out <<
"[" << std::fixed << std::setprecision(4);
117 std::copy(d.begin(),d.end(), std::ostream_iterator<T>(out,
" "));
119 out.flags(old_flags);
120 out.precision(old_pre);
127 std::ostream& operator << (std::ostream& out, std::vector<T> *d)
129 const std::streamsize old_pre = out.precision();
130 const std::ios_base::fmtflags old_flags = out.flags();
131 out <<
"[" << std::fixed << std::setprecision(4);
132 copy(d->begin(),d->end(), std::ostream_iterator<T>(out,
" "));
134 out.flags(old_flags);
135 out.precision(old_pre);
140 template <
typename T,
size_t N>
143 ostrm << mrpt::utils::TTypeName< CArrayNumeric<T,N> >::get();
144 if (N) ostrm.WriteBufferFixEndianness<T>(&
a[0],N);
149 template <
typename T,
size_t N>
155 ASSERTMSG_(nam==namExpect,
format(
"Error deserializing: expected '%s', got '%s'", 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...
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::vector< T1 > & operator+=(std::vector< T1 > &a, const std::vector< T2 > &b)
a+=b (element-wise sum)
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
GLsizei const GLchar ** string
BASE_IMPEXP ::mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, CMatrixPtr &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)