| 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 | |