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

Function test_transpose

dlib/test/dnn.cpp:1327–1354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1325// ----------------------------------------------------------------------------------------
1326
1327 void test_transpose()
1328 {
1329 const long num_samples = 2;
1330 const long k = 3;
1331 const long nr = 4;
1332 const long nc = 5;
1333
1334 resizable_tensor input(num_samples, k, nr, nc);
1335 resizable_tensor output_cpu_a(num_samples, k, nc, nr);
1336 tt::tensor_rand rnd(0);
1337 rnd.fill_uniform(input);
1338 resizable_tensor output_cpu_b(input);
1339
1340 cpu::transpose(false, output_cpu_a, input);
1341 cpu::transpose(true, output_cpu_b, output_cpu_a);
1342 input *= 2;
1343 DLIB_TEST(max(abs(mat(output_cpu_b) - mat(input))) < 1e-5);
1344
1345 IF_DLIB_USE_CUDA(
1346 input /= 2;
1347 resizable_tensor output_cuda_a, output_cuda_b(input);
1348 output_cuda_a.copy_size(output_cpu_a);
1349 cuda::transpose(false, output_cuda_a, input);
1350 cuda::transpose(true, output_cuda_b, output_cuda_a);
1351 DLIB_TEST(max(abs(mat(output_cpu_a) - mat(output_cuda_a))) < 1e-5);
1352 DLIB_TEST(max(abs(mat(output_cpu_b) - mat(output_cuda_b))) < 1e-5);
1353 )
1354 }
1355
1356// ----------------------------------------------------------------------------------------
1357

Callers 1

run_testsMethod · 0.85

Calls 5

absFunction · 0.85
copy_sizeMethod · 0.80
transposeFunction · 0.50
maxFunction · 0.50
matFunction · 0.50

Tested by

no test coverage detected