| 994 | // ---------------------------------------------------------------------------------------- |
| 995 | |
| 996 | void test_basic_tensor_ops() |
| 997 | { |
| 998 | using namespace dlib::tt; |
| 999 | print_spinner(); |
| 1000 | resizable_tensor dest, src(3,4), A(1,4), B(1,4); |
| 1001 | src = 2; |
| 1002 | dest.copy_size(src); |
| 1003 | affine_transform(dest, src, 2, 3); |
| 1004 | dlog << LINFO << mat(dest); |
| 1005 | matrix<float> truth1(3,4), truth2(3,4); |
| 1006 | |
| 1007 | truth1 = 2; |
| 1008 | DLIB_TEST(max(abs(truth1-mat(src))) < 1e-5); |
| 1009 | src *= 2; |
| 1010 | truth1 = 4; |
| 1011 | DLIB_TEST(max(abs(truth1-mat(src))) < 1e-5); |
| 1012 | src = 2; |
| 1013 | |
| 1014 | |
| 1015 | truth1 = 7; |
| 1016 | truth2 = 7, 10, 7, 7, |
| 1017 | 7, 10, 7, 7, |
| 1018 | 7, 10, 7, 7; |
| 1019 | DLIB_TEST(max(abs(truth1-mat(dest))) < 1e-5); |
| 1020 | |
| 1021 | A = 2; |
| 1022 | B = 3; |
| 1023 | A.host()[1] = 3; |
| 1024 | B.host()[1] = 4; |
| 1025 | dest = 0; |
| 1026 | affine_transform(dest, src, A, B); |
| 1027 | dlog << LINFO << mat(dest); |
| 1028 | DLIB_TEST(max(abs(truth2-mat(dest))) < 1e-5); |
| 1029 | |
| 1030 | A = matrix_cast<float>(gaussian_randm(3,4, 1)); |
| 1031 | B = matrix_cast<float>(gaussian_randm(3,4, 2)); |
| 1032 | affine_transform(dest, src, A, B); |
| 1033 | dlog << LINFO << mat(dest); |
| 1034 | matrix<float> truth3 = pointwise_multiply(mat(src), mat(A)) + mat(B); |
| 1035 | DLIB_TEST(max(abs(truth3-mat(dest))) < 1e-5); |
| 1036 | |
| 1037 | matrix<float> truth4 = pointwise_multiply(mat(A), mat(B)); |
| 1038 | tt::multiply(false, A, A, B); |
| 1039 | DLIB_TEST(max(abs(truth4-mat(A))) < 1e-5); |
| 1040 | truth4 = pointwise_multiply(mat(A), mat(B)) + mat(A); |
| 1041 | tt::multiply(true, A, A, B); |
| 1042 | DLIB_TEST(max(abs(truth4-mat(A))) < 1e-5); |
| 1043 | |
| 1044 | matrix<float> truth5 = mat(B) > 0.1; |
| 1045 | dlog << LINFO << truth5; |
| 1046 | threshold(B, 0.1); |
| 1047 | DLIB_TEST(max(abs(truth5-mat(B))) < 1e-5); |
| 1048 | |
| 1049 | int cnt = 0; |
| 1050 | for(auto& x : A) |
| 1051 | x = cnt++; |
| 1052 | |
| 1053 | truth1.set_size(2,2); |
no test coverage detected