Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef mrpt_math_vector_ops_H
00029 #define mrpt_math_vector_ops_H
00030
00031 #include <mrpt/utils/utils_defs.h>
00032 #include <mrpt/math/CMatrixTemplateNumeric.h>
00033 #include <mrpt/math/CVectorTemplate.h>
00034
00035
00036 #include <mrpt/math/ops_containers.h>
00037
00038
00039 namespace mrpt
00040 {
00041 namespace utils { class CFileStream; }
00042
00043 namespace math
00044 {
00045
00046
00047
00048
00049
00050
00051 template <class VECTOR1,class VECTOR2>
00052 inline RET_CONT1_ASSERT_MRPTVECTORS(VECTOR1,VECTOR2)
00053 operator *=(VECTOR1&a, const VECTOR2 &b)
00054 {
00055 ASSERT_(a.size()==b.size());
00056 typename VECTOR1::iterator ita = a.begin();
00057 typename VECTOR2::const_iterator itb = b.begin();
00058 const typename VECTOR1::iterator last=a.end();
00059 while (ita!=last) { *(ita++)*=*(itb++); }
00060 return a;
00061 }
00062
00063
00064 template <class VECTOR1,class VECTOR2>
00065 inline RET_CONT1_ASSERT_MRPTVECTORS(VECTOR1,VECTOR2)
00066 operator *(const VECTOR1 &a, const VECTOR2 &b)
00067 {
00068 VECTOR1 ret = a;
00069 ret*=b;
00070 return ret;
00071 }
00072
00073
00074 template <class VECTOR1,class VECTOR2>
00075 inline RET_CONT1_ASSERT_MRPTVECTORS(VECTOR1,VECTOR2)
00076 operator /=(VECTOR1&a, const VECTOR2 &b)
00077 {
00078 ASSERT_(a.size()==b.size());
00079 typename VECTOR1::iterator ita = a.begin();
00080 typename VECTOR2::const_iterator itb = b.begin();
00081 const typename VECTOR1::iterator last=a.end();
00082 while (ita!=last) { *(ita++)/=*(itb++); }
00083 return a;
00084 }
00085
00086
00087 template <class VECTOR1,class VECTOR2>
00088 inline RET_CONT1_ASSERT_MRPTVECTORS(VECTOR1,VECTOR2)
00089 operator /(const VECTOR1 &a, const VECTOR2 &b)
00090 {
00091 VECTOR1 ret = a;
00092 ret/=b;
00093 return ret;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 template <class T>
00103 std::ostream& operator << (std::ostream& out, const std::vector<T> &d)
00104 {
00105 out << "[" << std::fixed << std::setprecision(4);
00106 copy(d.begin(),d.end(), std::ostream_iterator<T>(out," "));
00107 out << "]";
00108 return out;
00109 }
00110
00111
00112
00113 template <class T>
00114 std::ostream& operator << (std::ostream& out, std::vector<T> *d)
00115 {
00116 out << "[";
00117 copy(d->begin(),d->end(), std::ostream_iterator<T>(out," "));
00118 out << "]";
00119 return out;
00120 }
00121
00122
00123 }
00124
00125 }
00126
00127
00128 #endif