| 5756 | // ---------------------------------------------------------------------------------------- |
| 5757 | |
| 5758 | void test_tril() |
| 5759 | { |
| 5760 | print_spinner(); |
| 5761 | using net_type = tag1<tril_mask<tag2<input<matrix<float>>>>>; |
| 5762 | net_type net; |
| 5763 | |
| 5764 | // Input tensor |
| 5765 | dlib::rand rnd; |
| 5766 | const int nr = 2, nc = 3; |
| 5767 | constexpr int n_samples = 3, k = 1; |
| 5768 | std::vector<matrix<float>> x(n_samples); |
| 5769 | matrix<float> xtmp(nr, nc); |
| 5770 | for (int ii = 0; ii < n_samples; ++ii) { |
| 5771 | for (int jj = 0; jj < nr; ++jj) |
| 5772 | for (int kk = 0; kk < nc; ++kk) |
| 5773 | xtmp(jj, kk) = rnd.get_random_gaussian(); |
| 5774 | x[ii] = xtmp; |
| 5775 | } |
| 5776 | |
| 5777 | // Convert input matrix to tensor |
| 5778 | resizable_tensor input_tensor; |
| 5779 | net.to_tensor(&x[0], &x[0] + n_samples, input_tensor); |
| 5780 | net.forward(input_tensor); |
| 5781 | |
| 5782 | // Expected output tensor (manually set for comparison) |
| 5783 | resizable_tensor expected_output; |
| 5784 | expected_output.copy_size(input_tensor); |
| 5785 | tt::copy_tensor(false, expected_output, 0, input_tensor, 0, input_tensor.k()); |
| 5786 | for (int ii = 0; ii < n_samples; ++ii) { |
| 5787 | expected_output.host()[tensor_index(expected_output, ii, 0, 0, 1)] = -std::numeric_limits<float>::infinity(); |
| 5788 | expected_output.host()[tensor_index(expected_output, ii, 0, 0, 2)] = -std::numeric_limits<float>::infinity(); |
| 5789 | expected_output.host()[tensor_index(expected_output, ii, 0, 1, 2)] = -std::numeric_limits<float>::infinity(); |
| 5790 | } |
| 5791 | |
| 5792 | // Compare output tensor with expected output |
| 5793 | auto& net_output = layer<tag1>(net).get_output(); |
| 5794 | DLIB_TEST(max(abs(mat(net_output) - mat(expected_output))) < 1e-5); |
| 5795 | } |
| 5796 | |
| 5797 | // ---------------------------------------------------------------------------------------- |
| 5798 |
no test coverage detected