comparison armadillo-2.4.4/include/armadillo_bits/op_dotext_meat.hpp @ 0:8b6102e2a9b0

Armadillo Library
author maxzanoni76 <max.zanoni@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 09:27:06 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8b6102e2a9b0
1 // Copyright (C) 2008-2010 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-2010 Conrad Sanderson
3 //
4 // This file is part of the Armadillo C++ library.
5 // It is provided without any warranty of fitness
6 // for any purpose. You can redistribute this file
7 // and/or modify it under the terms of the GNU
8 // Lesser General Public License (LGPL) as published
9 // by the Free Software Foundation, either version 3
10 // of the License or (at your option) any later version.
11 // (see http://www.opensource.org/licenses for more info)
12
13
14 //! \addtogroup op_dotext
15 //! @{
16
17
18
19 template<typename eT>
20 inline
21 eT
22 op_dotext::direct_rowvec_mat_colvec
23 (
24 const eT* A_mem,
25 const Mat<eT>& B,
26 const eT* C_mem
27 )
28 {
29 arma_extra_debug_sigprint();
30
31 const uword cost_AB = B.n_cols;
32 const uword cost_BC = B.n_rows;
33
34 if(cost_AB <= cost_BC)
35 {
36 podarray<eT> tmp(B.n_cols);
37
38 for(uword col=0; col<B.n_cols; ++col)
39 {
40 const eT* B_coldata = B.colptr(col);
41
42 eT val = eT(0);
43 for(uword i=0; i<B.n_rows; ++i)
44 {
45 val += A_mem[i] * B_coldata[i];
46 }
47
48 tmp[col] = val;
49 }
50
51 return op_dot::direct_dot(B.n_cols, tmp.mem, C_mem);
52 }
53 else
54 {
55 podarray<eT> tmp(B.n_rows);
56
57 for(uword row=0; row<B.n_rows; ++row)
58 {
59 eT val = eT(0);
60 for(uword col=0; col<B.n_cols; ++col)
61 {
62 val += B.at(row,col) * C_mem[col];
63 }
64
65 tmp[row] = val;
66 }
67
68 return op_dot::direct_dot(B.n_rows, A_mem, tmp.mem);
69 }
70
71
72 }
73
74
75
76 template<typename eT>
77 inline
78 eT
79 op_dotext::direct_rowvec_transmat_colvec
80 (
81 const eT* A_mem,
82 const Mat<eT>& B,
83 const eT* C_mem
84 )
85 {
86 arma_extra_debug_sigprint();
87
88 const uword cost_AB = B.n_rows;
89 const uword cost_BC = B.n_cols;
90
91 if(cost_AB <= cost_BC)
92 {
93 podarray<eT> tmp(B.n_rows);
94
95 for(uword row=0; row<B.n_rows; ++row)
96 {
97 eT val = eT(0);
98
99 for(uword i=0; i<B.n_cols; ++i)
100 {
101 val += A_mem[i] * B.at(row,i);
102 }
103
104 tmp[row] = val;
105 }
106
107 return op_dot::direct_dot(B.n_rows, tmp.mem, C_mem);
108 }
109 else
110 {
111 podarray<eT> tmp(B.n_cols);
112
113 for(uword col=0; col<B.n_cols; ++col)
114 {
115 const eT* B_coldata = B.colptr(col);
116
117 eT val = eT(0);
118
119 for(uword i=0; i<B.n_rows; ++i)
120 {
121 val += B_coldata[i] * C_mem[i];
122 }
123
124 tmp[col] = val;
125 }
126
127 return op_dot::direct_dot(B.n_cols, A_mem, tmp.mem);
128 }
129
130
131 }
132
133
134
135 template<typename eT>
136 inline
137 eT
138 op_dotext::direct_rowvec_diagmat_colvec
139 (
140 const eT* A_mem,
141 const Mat<eT>& B,
142 const eT* C_mem
143 )
144 {
145 arma_extra_debug_sigprint();
146
147 eT val = eT(0);
148
149 for(uword i=0; i<B.n_rows; ++i)
150 {
151 val += A_mem[i] * B.at(i,i) * C_mem[i];
152 }
153
154 return val;
155 }
156
157
158
159 template<typename eT>
160 inline
161 eT
162 op_dotext::direct_rowvec_invdiagmat_colvec
163 (
164 const eT* A_mem,
165 const Mat<eT>& B,
166 const eT* C_mem
167 )
168 {
169 arma_extra_debug_sigprint();
170
171 eT val = eT(0);
172
173 for(uword i=0; i<B.n_rows; ++i)
174 {
175 val += (A_mem[i] * C_mem[i]) / B.at(i,i);
176 }
177
178 return val;
179 }
180
181
182
183 template<typename eT>
184 inline
185 eT
186 op_dotext::direct_rowvec_invdiagvec_colvec
187 (
188 const eT* A_mem,
189 const Mat<eT>& B,
190 const eT* C_mem
191 )
192 {
193 arma_extra_debug_sigprint();
194
195 const eT* B_mem = B.mem;
196
197 eT val = eT(0);
198
199 for(uword i=0; i<B.n_elem; ++i)
200 {
201 val += (A_mem[i] * C_mem[i]) / B_mem[i];
202 }
203
204 return val;
205 }
206
207
208
209 //! @}