| 1490 | // ---------------------------------------------------------------------------------------- |
| 1491 | |
| 1492 | void test_basic_tensor_ops() |
| 1493 | { |
| 1494 | using namespace dlib::tt; |
| 1495 | print_spinner(); |
| 1496 | resizable_tensor dest, src(3,4), A(1,4), B(1,4); |
| 1497 | src = 2; |
| 1498 | dest.copy_size(src); |
| 1499 | affine_transform(dest, src, 2, 3); |
| 1500 | dlog << LINFO << mat(dest); |
| 1501 | matrix<float> truth1(3,4), truth2(3,4); |
| 1502 | |
| 1503 | truth1 = 2; |
| 1504 | DLIB_TEST(max(abs(truth1-mat(src))) < 1e-5); |
| 1505 | src *= 2; |
| 1506 | truth1 = 4; |
| 1507 | DLIB_TEST(max(abs(truth1-mat(src))) < 1e-5); |
| 1508 | src = 2; |
| 1509 | |
| 1510 | |
| 1511 | truth1 = 7; |
| 1512 | truth2 = 7, 10, 7, 7, |
| 1513 | 7, 10, 7, 7, |
| 1514 | 7, 10, 7, 7; |
| 1515 | DLIB_TEST(max(abs(truth1-mat(dest))) < 1e-5); |
| 1516 | |
| 1517 | A = 2; |
| 1518 | B = 3; |
| 1519 | A.host()[1] = 3; |
| 1520 | B.host()[1] = 4; |
| 1521 | dest = 0; |
| 1522 | affine_transform(dest, src, A, B); |
| 1523 | dlog << LINFO << mat(dest); |
| 1524 | DLIB_TEST(max(abs(truth2-mat(dest))) < 1e-5); |
| 1525 | |
| 1526 | A = matrix_cast<float>(gaussian_randm(3,4, 1)); |
| 1527 | B = matrix_cast<float>(gaussian_randm(3,4, 2)); |
| 1528 | affine_transform(dest, src, A, B); |
| 1529 | dlog << LINFO << mat(dest); |
| 1530 | matrix<float> truth3 = pointwise_multiply(mat(src), mat(A)) + mat(B); |
| 1531 | DLIB_TEST(max(abs(truth3-mat(dest))) < 1e-5); |
| 1532 | |
| 1533 | matrix<float> truth4 = pointwise_multiply(mat(A), mat(B)); |
| 1534 | tt::multiply(false, A, A, B); |
| 1535 | DLIB_TEST(max(abs(truth4-mat(A))) < 1e-5); |
| 1536 | truth4 = pointwise_multiply(mat(A), mat(B)) + mat(A); |
| 1537 | tt::multiply(true, A, A, B); |
| 1538 | DLIB_TEST(max(abs(truth4-mat(A))) < 1e-5); |
| 1539 | |
| 1540 | matrix<float> truth5 = mat(B) > 0.1; |
| 1541 | dlog << LINFO << truth5; |
| 1542 | threshold(B, 0.1); |
| 1543 | DLIB_TEST(max(abs(truth5-mat(B))) < 1e-5); |
| 1544 | |
| 1545 | int cnt = 0; |
| 1546 | for(auto& x : A) |
| 1547 | x = cnt++; |
| 1548 | |
| 1549 | truth1.set_size(2,2); |
no test coverage detected