MCPcopy Create free account
hub / github.com/davisking/dlib / add

Function add

dlib/cuda/cpu_dlib.cpp:222–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220 // ------------------------------------------------------------------------------------
221
222 void add(
223 float beta,
224 tensor& dest,
225 float alpha,
226 const tensor& src
227 )
228 {
229 DLIB_CASSERT(
230 (have_same_dimensions(src, dest) ||
231 (src.num_samples()==1 && src.k()==dest.k() && src.nr()==1 && src.nc()==1) ||
232 (src.num_samples()==1 && src.k()==dest.k() && src.nr()==dest.nr() && src.nc()==dest.nc()) ||
233 (src.num_samples()==1 && src.k()==1 && src.nr()==dest.nr() && src.nc()==dest.nc()) ||
234 (src.num_samples()==dest.num_samples() && src.k()==1 && src.nr()==1 && src.nc()==1)) &&
235 is_same_object(src,dest) == false ,
236 "\n\t dest.num_samples(): " << dest.num_samples()
237 <<"\n\t dest.k(): " << dest.k()
238 <<"\n\t dest.nr(): " << dest.nr()
239 <<"\n\t dest.nc(): " << dest.nc()
240 <<"\n\t src.num_samples(): " << src.num_samples()
241 <<"\n\t src.k(): " << src.k()
242 <<"\n\t src.nr(): " << src.nr()
243 <<"\n\t src.nc(): " << src.nc()
244 );
245
246
247 if (beta == 0 && alpha == 0)
248 {
249 dest = 0;
250 return;
251 }
252
253 auto d = dest.host();
254 auto s = src.host();
255 for (long n = 0; n < dest.num_samples(); ++n)
256 {
257 const auto sn = src.num_samples()==1 ? 0:n;
258 for (long k = 0; k < dest.k(); ++k)
259 {
260 const auto sk = src.k()==1 ? 0:k;
261 for (long r = 0; r < dest.nr(); ++r)
262 {
263 const auto sr = src.nr()==1 ? 0:r;
264 for (long c = 0; c < dest.nc(); ++c)
265 {
266 const auto sc = src.nc()==1 ? 0:c;
267
268 const auto s_idx = ((sn*src.k() + sk)*src.nr() + sr)*src.nc() + sc;
269 *d = beta*(*d) + alpha*s[s_idx];
270 ++d;
271 }
272 }
273 }
274 }
275 }
276
277 // ----------------------------------------------------------------------------------------
278

Callers 15

averageMethod · 0.70
operator()Method · 0.70
addMethod · 0.50
crc32Method · 0.50
addMethod · 0.50
addMethod · 0.50
addMethod · 0.50
addMethod · 0.50
addMethod · 0.50
forwardMethod · 0.50
forwardMethod · 0.50
forwardMethod · 0.50

Calls 8

have_same_dimensionsFunction · 0.70
is_same_objectFunction · 0.50
num_samplesMethod · 0.45
kMethod · 0.45
nrMethod · 0.45
ncMethod · 0.45
hostMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected