IT++
4.3.1
Toggle main menu visibility
itpp
base
fastmath.cpp
Go to the documentation of this file.
1
29
30
#include <
itpp/base/fastmath.h
>
31
32
33
namespace
itpp
34
{
35
36
// m=m-v*v'*m
37
void
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'
65
void
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
itpp::Mat::mat
Mat< double > mat
Default Matrix Type.
Definition
mat.h:482
itpp::Mat::rows
int rows() const
The number of rows.
Definition
mat.h:237
itpp::Mat::cols
int cols() const
The number of columns.
Definition
mat.h:235
itpp::Mat::_elem
Num_T & _elem(int r, int c)
Get element (r,c) from matrix without boundary check (not recommended to use).
Definition
mat.h:431
fastmath.h
Definitions of special operations on vectors and matricies optimized for speed.
it_assert
#define it_assert(t, s)
Abort if t is not true.
Definition
itassert.h:94
itpp
itpp namespace
Definition
itmex.h:37
itpp::sub_v_vT_m
void sub_v_vT_m(mat &m, const vec &v)
Calculates m=m-v*v'*m.
Definition
fastmath.cpp:37
itpp::sub_m_v_vT
void sub_m_v_vT(mat &m, const vec &v)
Calculates m=m-m*v*v'.
Definition
fastmath.cpp:65
Generated by
1.17.0