MCPcopy Create free account
hub / github.com/davisking/dlib / test_tril

Function test_tril

dlib/test/dnn.cpp:5186–5223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5184// ----------------------------------------------------------------------------------------
5185
5186 void test_tril()
5187 {
5188 print_spinner();
5189 using net_type = tag1<tril_mask<tag2<input<matrix<float>>>>>;
5190 net_type net;
5191
5192 // Input tensor
5193 dlib::rand rnd;
5194 const int nr = 2, nc = 3;
5195 constexpr int n_samples = 3, k = 1;
5196 std::vector<matrix<float>> x(n_samples);
5197 matrix<float> xtmp(nr, nc);
5198 for (int ii = 0; ii < n_samples; ++ii) {
5199 for (int jj = 0; jj < nr; ++jj)
5200 for (int kk = 0; kk < nc; ++kk)
5201 xtmp(jj, kk) = rnd.get_random_gaussian();
5202 x[ii] = xtmp;
5203 }
5204
5205 // Convert input matrix to tensor
5206 resizable_tensor input_tensor;
5207 net.to_tensor(&x[0], &x[0] + n_samples, input_tensor);
5208 net.forward(input_tensor);
5209
5210 // Expected output tensor (manually set for comparison)
5211 resizable_tensor expected_output;
5212 expected_output.copy_size(input_tensor);
5213 tt::copy_tensor(false, expected_output, 0, input_tensor, 0, input_tensor.k());
5214 for (int ii = 0; ii < n_samples; ++ii) {
5215 expected_output.host()[tensor_index(expected_output, ii, 0, 0, 1)] = -std::numeric_limits<float>::infinity();
5216 expected_output.host()[tensor_index(expected_output, ii, 0, 0, 2)] = -std::numeric_limits<float>::infinity();
5217 expected_output.host()[tensor_index(expected_output, ii, 0, 1, 2)] = -std::numeric_limits<float>::infinity();
5218 }
5219
5220 // Compare output tensor with expected output
5221 auto& net_output = layer<tag1>(net).get_output();
5222 DLIB_TEST(max(abs(mat(net_output) - mat(expected_output))) < 1e-5);
5223 }
5224
5225// ----------------------------------------------------------------------------------------
5226

Callers 1

run_testsMethod · 0.85

Calls 12

print_spinnerFunction · 0.85
tensor_indexFunction · 0.85
absFunction · 0.85
get_random_gaussianMethod · 0.80
copy_sizeMethod · 0.80
copy_tensorFunction · 0.50
maxFunction · 0.50
matFunction · 0.50
to_tensorMethod · 0.45
forwardMethod · 0.45
kMethod · 0.45
hostMethod · 0.45

Tested by

no test coverage detected