| 830 | // ---------------------------------------------------------------------------------------- |
| 831 | |
| 832 | void test_transpose() |
| 833 | { |
| 834 | const long num_samples = 2; |
| 835 | const long k = 3; |
| 836 | const long nr = 4; |
| 837 | const long nc = 5; |
| 838 | |
| 839 | resizable_tensor input(num_samples, k, nr, nc); |
| 840 | resizable_tensor output_cpu_a(num_samples, k, nc, nr); |
| 841 | tt::tensor_rand rnd(0); |
| 842 | rnd.fill_uniform(input); |
| 843 | resizable_tensor output_cpu_b(input); |
| 844 | |
| 845 | cpu::transpose(false, output_cpu_a, input); |
| 846 | cpu::transpose(true, output_cpu_b, output_cpu_a); |
| 847 | input *= 2; |
| 848 | DLIB_TEST(max(abs(mat(output_cpu_b) - mat(input))) < 1e-5); |
| 849 | |
| 850 | #ifdef DLIB_USE_CUDA |
| 851 | input /= 2; |
| 852 | resizable_tensor output_cuda_a, output_cuda_b(input); |
| 853 | output_cuda_a.copy_size(output_cpu_a); |
| 854 | cuda::transpose(false, output_cuda_a, input); |
| 855 | cuda::transpose(true, output_cuda_b, output_cuda_a); |
| 856 | DLIB_TEST(max(abs(mat(output_cpu_a) - mat(output_cuda_a))) < 1e-5); |
| 857 | DLIB_TEST(max(abs(mat(output_cpu_b) - mat(output_cuda_b))) < 1e-5); |
| 858 | #endif |
| 859 | } |
| 860 | |
| 861 | // ---------------------------------------------------------------------------------------- |
| 862 | |