IT++ Logo

fastmath.cpp

Go to the documentation of this file.
00001 
00031 #include <itpp/base/fastmath.h>
00032 
00033 
00034 namespace itpp
00035 {
00036 
00037 // m=m-v*v'*m
00038 void sub_v_vT_m(mat &m, const vec &v)
00039 {
00040   vec v2(m.cols());
00041   double tmp, *v2p;
00042   const double *vp;
00043   int i, j;
00044 
00045   it_assert(v.size() == m.rows(), "sub_v_vT_m()");
00046 
00047   v2p = v2._data();
00048   for (j = 0; j < m.cols(); j++) {
00049     tmp = 0.0;
00050     vp = v._data();
00051     for (i = 0; i < m.rows(); i++)
00052       tmp += *(vp++) * m._elem(i, j);
00053     *(v2p++) = tmp;
00054   }
00055 
00056   vp = v._data();
00057   for (i = 0; i < m.rows(); i++) {
00058     v2p = v2._data();
00059     for (j = 0; j < m.cols(); j++)
00060       m._elem(i, j) -= *vp * *(v2p++);
00061     vp++;
00062   }
00063 }
00064 
00065 // m=m-m*v*v'
00066 void sub_m_v_vT(mat &m, const vec &v)
00067 {
00068   vec v2(m.rows());
00069   double tmp, *v2p;
00070   const double *vp;
00071   int i, j;
00072 
00073   it_assert(v.size() == m.cols(), "sub_m_v_vT()");
00074 
00075   v2p = v2._data();
00076   for (i = 0; i < m.rows(); i++) {
00077     tmp = 0.0;
00078     vp = v._data();
00079     for (j = 0; j < m.cols(); j++)
00080       tmp += *(vp++) * m._elem(i, j);
00081     *(v2p++) = tmp;
00082   }
00083 
00084   v2p = v2._data();
00085   for (i = 0; i < m.rows(); i++) {
00086     vp = v._data();
00087     for (j = 0; j < m.cols(); j++)
00088       m._elem(i, j) -= *v2p * *(vp++);
00089     v2p++;
00090   }
00091 }
00092 
00093 } // namespace itpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SourceForge Logo

Generated on Wed Mar 2 2011 22:05:03 for IT++ by Doxygen 1.7.3