48 template <
class Weight1,
class Weight2>
49 bool operator()(
const Weight1 &w1,
const Weight2 &w2)
const {
62 template <
class Arc,
class WeightEqual>
64 uint8_t etype = kEqualFsts) {
65 if ((etype & kEqualFstTypes) && (fst1.
Type() != fst2.
Type())) {
66 VLOG(1) <<
"Equal: Mismatched FST types (" << fst1.
Type()
67 <<
" != " << fst2.
Type() <<
")";
70 if ((etype & kEqualCompatProperties) &&
73 VLOG(1) <<
"Equal: Properties not compatible";
76 if (etype & kEqualCompatSymbols) {
78 VLOG(1) <<
"Equal: Input symbols not compatible";
82 VLOG(1) <<
"Equal: Output symbols not compatible";
86 if (!(etype & kEqualFsts))
return true;
88 VLOG(1) <<
"Equal: Mismatched start states (" << fst1.
Start()
89 <<
" != " << fst2.
Start() <<
")";
94 while (!siter1.
Done() || !siter2.
Done()) {
95 if (siter1.
Done() || siter2.
Done()) {
96 VLOG(1) <<
"Equal: Mismatched number of states";
99 const auto s1 = siter1.
Value();
100 const auto s2 = siter2.
Value();
102 VLOG(1) <<
"Equal: Mismatched states (" << s1 <<
"!= " << s2 <<
")";
105 const auto &final1 = fst1.
Final(s1);
106 const auto &final2 = fst2.
Final(s2);
107 if (!weight_equal(final1, final2)) {
108 VLOG(1) <<
"Equal: Mismatched final weights at state " << s1 <<
" (" 109 << final1 <<
" != " << final2 <<
")";
114 for (
auto a = 0; !aiter1.
Done() || !aiter2.
Done(); ++a) {
115 if (aiter1.
Done() || aiter2.
Done()) {
116 VLOG(1) <<
"Equal: Mismatched number of arcs at state " << s1;
119 const auto &arc1 = aiter1.
Value();
120 const auto &arc2 = aiter2.
Value();
121 if (arc1.ilabel != arc2.ilabel) {
122 VLOG(1) <<
"Equal: Mismatched arc input labels at state " << s1
123 <<
", arc " << a <<
" (" << arc1.ilabel <<
" != " << arc2.ilabel
126 }
else if (arc1.olabel != arc2.olabel) {
127 VLOG(1) <<
"Equal: Mismatched arc output labels at state " << s1
128 <<
", arc " << a <<
" (" << arc1.olabel <<
" != " << arc2.olabel
131 }
else if (!weight_equal(arc1.weight, arc2.weight)) {
132 VLOG(1) <<
"Equal: Mismatched arc weights at state " << s1 <<
", arc " 133 << a <<
" (" << arc1.weight <<
" != " << arc2.weight <<
")";
135 }
else if (arc1.nextstate != arc2.nextstate) {
136 VLOG(1) <<
"Equal: Mismatched next state at state " << s1 <<
", arc " 137 << a <<
" (" << arc1.nextstate <<
" != " << arc2.nextstate
146 FSTERROR() <<
"Equal: Inconsistent arc counts at state " << s1 <<
" (" 151 FSTERROR() <<
"Equal: Inconsistent input epsilon counts at state " << s1
157 FSTERROR() <<
"Equal: Inconsistent output epsilon counts at state " << s1
169 uint8_t etype = kEqualFsts) {
179 uint8_t etype = kEqualFsts) {
185 #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