| 43 | } // namespace |
| 44 | |
| 45 | ::testing::AssertionResult test::__assert_tensor_binary_eq( |
| 46 | const char* expr0, const char* expr1, const char* expr2, const TensorND& v0, |
| 47 | const TensorND& v1, const Algorithm::Info::Desc& algo) { |
| 48 | bool shape_match = v0.layout[0] == 1; |
| 49 | for (size_t i = 1; i < v0.layout.ndim; ++i) { |
| 50 | shape_match &= v0.layout[i] == v1.layout[i]; |
| 51 | } |
| 52 | if (!shape_match) { |
| 53 | return ::testing::AssertionFailure() |
| 54 | << "Shape mismatch\n" |
| 55 | << "Value of: " << expr1 << "\n" |
| 56 | << " Actual: " << v1.layout.TensorShape::to_string() << "\n" |
| 57 | << "Expected: " << expr0 << "\n" |
| 58 | << "Which is: " << v0.layout.TensorShape::to_string() << "\n" |
| 59 | << "algo: " << algo.name << "\n"; |
| 60 | } |
| 61 | |
| 62 | if (!v0.layout.is_physical_contiguous() || !v1.layout.is_physical_contiguous()) { |
| 63 | return ::testing::AssertionFailure() |
| 64 | << "layout should be physical contiguous\n" |
| 65 | << "Value of: " << expr1 << "\n" |
| 66 | << " Actual: " << v1.layout.is_physical_contiguous() << "\n" |
| 67 | << "Expected: " << expr0 << "\n" |
| 68 | << "Which is: " << v0.layout.is_physical_contiguous() << "\n" |
| 69 | << "algo: " << algo.name << "\n"; |
| 70 | } |
| 71 | auto dtype = v0.layout.dtype; |
| 72 | if (dtype != v1.layout.dtype) { |
| 73 | return ::testing::AssertionFailure() |
| 74 | << "Data type should match\n" |
| 75 | << "Value of: " << expr1 << "\n" |
| 76 | << " Actual: " << v1.layout.dtype.name() << "\n" |
| 77 | << "Expected: " << expr0 << "\n" |
| 78 | << "Which is: " << v0.layout.dtype.name() << "\n" |
| 79 | << "algo: " << algo.name << "\n"; |
| 80 | } |
| 81 | |
| 82 | switch (dtype.enumv()) { |
| 83 | #define cb(_dt) \ |
| 84 | case DTypeTrait<_dt>::enumv: \ |
| 85 | return assert_tensor_binary_eq<DTypeTrait<_dt>::ctype>( \ |
| 86 | expr0, expr1, expr2, v0, v1, algo.name); |
| 87 | MEGDNN_FOREACH_COMPUTING_DTYPE(cb) |
| 88 | MEGDNN_FOREACH_QUANTIZED_DTYPE(cb) |
| 89 | #undef cb |
| 90 | default: |
| 91 | megdnn_trap(); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // vim: syntax=cpp.doxygen |
nothing calls this directly
no test coverage detected