MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / MatchAndExplain

Method MatchAndExplain

tensorflow/compiler/xla/service/hlo_matchers.cc:25–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23namespace testing {
24
25bool HloMatcher::MatchAndExplain(
26 const HloInstruction* instruction,
27 ::testing::MatchResultListener* listener) const {
28 // These cases are self-explanatory from the printed value.
29 if (!instruction) {
30 return false;
31 }
32 *listener << "(" << instruction->ToString() << ")";
33 if (instruction->opcode() != opcode_) {
34 return false;
35 }
36 // Special case: no operand matchers means don't verify.
37 if (operands_.empty()) {
38 return true;
39 }
40 const auto& operands = instruction->operands();
41 if (operands.size() != operands_.size()) {
42 *listener << " has too "
43 << (operands.size() > operands_.size() ? "many" : "few")
44 << " operands (got " << operands.size() << ", want "
45 << operands_.size() << ")";
46 return false;
47 }
48 for (int index = 0; index < operands.size(); index++) {
49 ::testing::StringMatchResultListener inner_listener;
50 if (!operands_[index].MatchAndExplain(operands[index], &inner_listener)) {
51 if (listener->IsInterested()) {
52 *listener << "\noperand " << index << ":\n\t"
53 << operands[index]->ToString()
54 << "\ndoesn't match expected:\n\t";
55 operands_[index].DescribeTo(listener->stream());
56 string explanation = inner_listener.str();
57 if (!explanation.empty()) {
58 *listener << ", " << explanation;
59 }
60 }
61 return false;
62 }
63 }
64 return true;
65}
66
67void HloMatcher::DescribeTo(::std::ostream* os) const {
68 *os << opcode_;

Callers 2

ExplainFunction · 0.45
ExplainFunction · 0.45

Calls 15

CompatibleClass · 0.85
opcodeMethod · 0.80
comparison_directionMethod · 0.80
has_shardingMethod · 0.80
shardingMethod · 0.80
has_layoutMethod · 0.80
EqualClass · 0.50
ToStringMethod · 0.45
emptyMethod · 0.45
operandsMethod · 0.45
sizeMethod · 0.45

Tested by 2

ExplainFunction · 0.36
ExplainFunction · 0.36