46 template <
class Weight1,
class Weight2>
47 bool operator()(
const Weight1 &w1,
const Weight2 &w2)
const {
60 template <
class Arc,
class WeightEqual>
62 uint8_t etype = kEqualFsts) {
63 if ((etype & kEqualFstTypes) && (fst1.
Type() != fst2.
Type())) {
64 VLOG(1) <<
"Equal: Mismatched FST types (" << fst1.
Type()
65 <<
" != " << fst2.
Type() <<
")";
68 if ((etype & kEqualCompatProperties) &&
71 VLOG(1) <<
"Equal: Properties not compatible";
74 if (etype & kEqualCompatSymbols) {
76 VLOG(1) <<
"Equal: Input symbols not compatible";
80 VLOG(1) <<
"Equal: Output symbols not compatible";
84 if (!(etype & kEqualFsts))
return true;
86 VLOG(1) <<
"Equal: Mismatched start states (" << fst1.
Start()
87 <<
" != " << fst2.
Start() <<
")";
92 while (!siter1.
Done() || !siter2.
Done()) {
93 if (siter1.
Done() || siter2.
Done()) {
94 VLOG(1) <<
"Equal: Mismatched number of states";
97 const auto s1 = siter1.
Value();
98 const auto s2 = siter2.
Value();
100 VLOG(1) <<
"Equal: Mismatched states (" << s1 <<
"!= " << s2 <<
")";
103 const auto &final1 = fst1.
Final(s1);
104 const auto &final2 = fst2.
Final(s2);
105 if (!weight_equal(final1, final2)) {
106 VLOG(1) <<
"Equal: Mismatched final weights at state " << s1 <<
" (" 107 << final1 <<
" != " << final2 <<
")";
112 for (
auto a = 0; !aiter1.
Done() || !aiter2.
Done(); ++a) {
113 if (aiter1.
Done() || aiter2.
Done()) {
114 VLOG(1) <<
"Equal: Mismatched number of arcs at state " << s1;
117 const auto &arc1 = aiter1.
Value();
118 const auto &arc2 = aiter2.
Value();
119 if (arc1.ilabel != arc2.ilabel) {
120 VLOG(1) <<
"Equal: Mismatched arc input labels at state " << s1
121 <<
", arc " << a <<
" (" << arc1.ilabel <<
" != " << arc2.ilabel
124 }
else if (arc1.olabel != arc2.olabel) {
125 VLOG(1) <<
"Equal: Mismatched arc output labels at state " << s1
126 <<
", arc " << a <<
" (" << arc1.olabel <<
" != " << arc2.olabel
129 }
else if (!weight_equal(arc1.weight, arc2.weight)) {
130 VLOG(1) <<
"Equal: Mismatched arc weights at state " << s1 <<
", arc " 131 << a <<
" (" << arc1.weight <<
" != " << arc2.weight <<
")";
133 }
else if (arc1.nextstate != arc2.nextstate) {
134 VLOG(1) <<
"Equal: Mismatched next state at state " << s1 <<
", arc " 135 << a <<
" (" << arc1.nextstate <<
" != " << arc2.nextstate
144 FSTERROR() <<
"Equal: Inconsistent arc counts at state " << s1 <<
" (" 149 FSTERROR() <<
"Equal: Inconsistent input epsilon counts at state " << s1
155 FSTERROR() <<
"Equal: Inconsistent output epsilon counts at state " << s1
167 uint8_t etype = kEqualFsts) {
177 uint8_t etype = kEqualFsts) {
183 #endif // FST_EQUAL_H_ virtual uint64_t Properties(uint64_t mask, bool test) const =0
virtual size_t NumArcs(StateId) const =0
bool CompatProperties(uint64_t props1, uint64_t props2)
constexpr uint8_t kEqualCompatProperties
virtual Weight Final(StateId) const =0
WeightApproxEqual(float delta)
constexpr uint8_t kEqualFstTypes
const Arc & Value() const
virtual size_t NumInputEpsilons(StateId) const =0
virtual const std::string & Type() const =0
constexpr uint8_t kEqualAll
constexpr uint64_t kCopyProperties
virtual StateId Start() const =0
bool Equal(const Fst< Arc > &fst1, const Fst< Arc > &fst2, WeightEqual weight_equal, uint8_t etype=kEqualFsts)
virtual const SymbolTable * InputSymbols() const =0
bool operator()(const Weight1 &w1, const Weight2 &w2) const
bool CompatSymbols(const SymbolTable *syms1, const SymbolTable *syms2, bool warning=true)
constexpr uint8_t kEqualFsts
constexpr uint8_t kEqualCompatSymbols
virtual size_t NumOutputEpsilons(StateId) const =0
bool ApproxEqual(const ErrorWeight &, const ErrorWeight &, float)
virtual const SymbolTable * OutputSymbols() const =0