MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / assert_tensor_binary_eq

Function assert_tensor_binary_eq

dnn/test/common/accuracy_shake_checker.cpp:9–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7
8template <typename ctype>
9::testing::AssertionResult assert_tensor_binary_eq(
10 const char* expr0, const char* expr1, const char* /*expr2*/, const TensorND& v0,
11 const TensorND& v1, const std::string& algo_name) {
12 ctype* it0_orig = v0.ptr<ctype>();
13 ctype* it1 = v1.ptr<ctype>();
14 ctype* it0 = it0_orig;
15 auto nr_elem = v1.layout.total_nr_elems();
16 auto nr_elem_single_batch = v0.layout.total_nr_elems();
17 for (size_t i = 0; i < nr_elem; ++i) {
18 if (i % nr_elem_single_batch == 0) {
19 it0 = it0_orig;
20 }
21 ctype iv0 = *it0, iv1 = *it1;
22
23 if (!good_float(iv0) || !good_float(iv1) || memcmp(it0, it1, sizeof(ctype))) {
24 Index index(v1.layout, i);
25 return ::testing::AssertionFailure()
26 << "Unequal value\n"
27 << "Value of: " << expr1 << "\n"
28 << " Actual: " << (iv1 + 0) << "\n"
29 << "Expected: " << expr0 << "\n"
30 << "Which is: " << (iv0 + 0) << "\n"
31 << "At index: " << index.to_string() << "/"
32 << v1.layout.TensorShape::to_string() << "\n"
33 << " DType: " << v1.layout.dtype.name() << "\n"
34 << "algo: " << algo_name;
35 }
36
37 ++it0;
38 ++it1;
39 }
40
41 return ::testing::AssertionSuccess();
42}
43} // namespace
44
45::testing::AssertionResult test::__assert_tensor_binary_eq(

Callers

nothing calls this directly

Calls 4

good_floatFunction · 0.70
total_nr_elemsMethod · 0.45
to_stringMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected