IT++ Logo
fastmath.cpp
Go to the documentation of this file.
1
30#include <itpp/base/fastmath.h>
31
32
33namespace itpp
34{
35
36// m=m-v*v'*m
37void sub_v_vT_m(mat &m, const vec &v)
38{
39 vec v2(m.cols());
40 double tmp, *v2p;
41 const double *vp;
42 int i, j;
43
44 it_assert(v.size() == m.rows(), "sub_v_vT_m()");
45
46 v2p = v2._data();
47 for (j = 0; j < m.cols(); j++) {
48 tmp = 0.0;
49 vp = v._data();
50 for (i = 0; i < m.rows(); i++)
51 tmp += *(vp++) * m._elem(i, j);
52 *(v2p++) = tmp;
53 }
54
55 vp = v._data();
56 for (i = 0; i < m.rows(); i++) {
57 v2p = v2._data();
58 for (j = 0; j < m.cols(); j++)
59 m._elem(i, j) -= *vp * *(v2p++);
60 vp++;
61 }
62}
63
64// m=m-m*v*v'
65void sub_m_v_vT(mat &m, const vec &v)
66{
67 vec v2(m.rows());
68 double tmp, *v2p;
69 const double *vp;
70 int i, j;
71
72 it_assert(v.size() == m.cols(), "sub_m_v_vT()");
73
74 v2p = v2._data();
75 for (i = 0; i < m.rows(); i++) {
76 tmp = 0.0;
77 vp = v._data();
78 for (j = 0; j < m.cols(); j++)
79 tmp += *(vp++) * m._elem(i, j);
80 *(v2p++) = tmp;
81 }
82
83 v2p = v2._data();
84 for (i = 0; i < m.rows(); i++) {
85 vp = v._data();
86 for (j = 0; j < m.cols(); j++)
87 m._elem(i, j) -= *v2p * *(vp++);
88 v2p++;
89 }
90}
91
92} // namespace itpp
General array class.
Definition array.h:105
int size() const
Returns the number of data elements in the array object.
Definition array.h:155
Matrix Class (Templated)
Definition mat.h:202
int rows() const
The number of rows.
Definition mat.h:237
int cols() const
The number of columns.
Definition mat.h:235
Num_T & _elem(int r, int c)
Get element (r,c) from matrix without boundary check (not recommended to use)
Definition mat.h:431
Definitions of special operations on vectors and matricies optimized for speed.
#define it_assert(t, s)
Abort if t is not true.
Definition itassert.h:94
itpp namespace
Definition itmex.h:37
void sub_v_vT_m(mat &m, const vec &v)
Calculates m=m-v*v'*m.
Definition fastmath.cpp:37
void sub_m_v_vT(mat &m, const vec &v)
Calculates m=m-m*v*v'.
Definition fastmath.cpp:65

Generated on Tue Aug 17 2021 10:59:15 for IT++ by Doxygen 1.9.8