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

Function reorg

dlib/cuda/cpu_dlib.cpp:2391–2434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2389 // ----------------------------------------------------------------------------------------
2390
2391 void reorg(
2392 bool add_to,
2393 tensor& dest,
2394 const int row_stride,
2395 const int col_stride,
2396 const tensor& src
2397 )
2398 {
2399 DLIB_CASSERT(!is_same_object(dest, src), "Destination and source must be distinct objects.");
2400 DLIB_CASSERT(src.nr() % row_stride == 0, "The number of rows in src must be divisible by row_stride.");
2401 DLIB_CASSERT(src.nc() % col_stride == 0, "The number of columns in src must be divisible by col_stride.");
2402 DLIB_CASSERT(dest.num_samples() == src.num_samples(), "The number of samples must match.");
2403 DLIB_CASSERT(dest.k() == src.k() * row_stride * col_stride, "The number of channels must match.");
2404 DLIB_CASSERT(dest.nr() == src.nr() / row_stride, "The number of rows must match.");
2405 DLIB_CASSERT(dest.nc() == src.nc() / col_stride, "The number of columns must match.");
2406
2407 const float* s = src.host();
2408 float* d = dest.host();
2409
2410 const size_t sk = src.k(), snr = src.nr(), snc = src.nc();
2411 const size_t dk = dest.k(), dnr = dest.nr(), dnc = dest.nc(), dsize = dest.size();
2412
2413 dlib::parallel_for(0, dsize, [&](long i)
2414 {
2415 const size_t out_plane_size = dnr * dnc;
2416 const size_t out_sample_size = dk * out_plane_size;
2417
2418 const size_t n = i / out_sample_size;
2419 const size_t out_idx = i % out_sample_size;
2420 const size_t out_k = out_idx / out_plane_size;
2421 const size_t out_rc = out_idx % out_plane_size;
2422 const size_t out_r = out_rc / dnc;
2423 const size_t out_c = out_rc % dnc;
2424
2425 const size_t in_k = out_k % sk;
2426 const size_t in_r = out_r * row_stride + (out_k / sk) / col_stride;
2427 const size_t in_c = out_c * col_stride + (out_k / sk) % col_stride;
2428
2429 const size_t in_idx = ((n * sk + in_k) * snr + in_r) * snc + in_c;
2430
2431 if (add_to) d[i] += s[in_idx];
2432 else d[i] = s[in_idx];
2433 });
2434 }
2435
2436 void reorg_gradient(
2437 bool add_to,

Callers 2

test_reorgFunction · 0.50
forwardMethod · 0.50

Calls 8

parallel_forFunction · 0.85
is_same_objectFunction · 0.50
nrMethod · 0.45
ncMethod · 0.45
num_samplesMethod · 0.45
kMethod · 0.45
hostMethod · 0.45
sizeMethod · 0.45

Tested by 1

test_reorgFunction · 0.40