28 #ifndef mrpt_math_vector_ops_H
29 #define mrpt_math_vector_ops_H
40 namespace utils {
class CFileStream; }
52 template <
typename T1,
typename T2>
53 inline std::vector<T1>&
operator *=(std::vector<T1>&a,
const std::vector<T2>&b)
56 const size_t N=a.size();
57 for (
size_t i=0;i<N;i++) a[i]*=b[i];
62 template <
typename T1>
63 inline std::vector<T1>&
operator *=(std::vector<T1>&a,
const T1 b)
65 const size_t N=a.size();
66 for (
size_t i=0;i<N;i++) a[i]*=b;
71 template <
typename T1,
typename T2>
72 inline std::vector<T1>
operator *(
const std::vector<T1>&a,
const std::vector<T2>&b)
75 const size_t N=a.size();
76 std::vector<T1> ret(N);
77 for (
size_t i=0;i<N;i++) ret[i]=a[i]*b[i];
82 template <
typename T1,
typename T2>
83 inline std::vector<T1>&
operator +=(std::vector<T1>&a,
const std::vector<T2>&b)
86 const size_t N=a.size();
87 for (
size_t i=0;i<N;i++) a[i]+=b[i];
92 template <
typename T1>
93 inline std::vector<T1>&
operator +=(std::vector<T1>&a,
const T1 b)
95 const size_t N=a.size();
96 for (
size_t i=0;i<N;i++) a[i]+=b;
101 template <
typename T1,
typename T2>
102 inline std::vector<T1>
operator +(
const std::vector<T1>&a,
const std::vector<T2>&b)
105 const size_t N=a.size();
106 std::vector<T1> ret(N);
107 for (
size_t i=0;i<N;i++) ret[i]=a[i]+b[i];
111 template <
typename T1,
typename T2>
112 inline std::vector<T1>
operator -(
const std::vector<T1> &v1,
const std::vector<T2>&v2) {
114 std::vector<T1> res(v1.size());
115 for (
size_t i=0;i<v1.size();i++) res[i]=v1[i]-v2[i];
125 std::ostream& operator << (std::ostream& out, const std::vector<T> &d)
127 const std::streamsize old_pre = out.precision();
128 const std::ios_base::fmtflags old_flags = out.flags();
129 out <<
"[" << std::fixed << std::setprecision(4);
130 copy(d.begin(),d.end(), std::ostream_iterator<T>(out,
" "));
132 out.flags(old_flags);
133 out.precision(old_pre);
140 std::ostream& operator << (std::ostream& out, std::vector<T> *d)
142 const std::streamsize old_pre = out.precision();
143 const std::ios_base::fmtflags old_flags = out.flags();
144 out <<
"[" << std::fixed << std::setprecision(4);
145 copy(d->begin(),d->end(), std::ostream_iterator<T>(out,
" "));
147 out.flags(old_flags);
148 out.precision(old_pre);
153 template <
typename T,
size_t N>
156 ostrm << mrpt::utils::TTypeName< CArrayNumeric<T,N> >::get();
157 if (N) ostrm.WriteBufferFixEndianness<T>(&a[0],N);
162 template <
typename T,
size_t N>
168 ASSERTMSG_(nam==namExpect,
format(
"Error deserializing: expected '%s', got '%s'", namExpect.c_str(),nam.c_str() ) )