28 template <
class Weight>
29 bool operator()(
const Weight &w1,
const Weight &w2)
const {
42 template <
class Arc,
class WeightEqual>
44 WeightEqual weight_equal,
uint32 etype = kEqualFsts) {
45 if ((etype & kEqualFstTypes) && (fst1.
Type() != fst2.
Type())) {
46 VLOG(1) <<
"Equal: Mismatched FST types (" << fst1.
Type() <<
" != " 47 << fst2.
Type() <<
")";
50 if ((etype & kEqualCompatProperties) &&
53 VLOG(1) <<
"Equal: Properties not compatible";
56 if (etype & kEqualCompatSymbols) {
58 VLOG(1) <<
"Equal: Input symbols not compatible";
62 VLOG(1) <<
"Equal: Output symbols not compatible";
66 if (!(etype & kEqualFsts))
return true;
68 VLOG(1) <<
"Equal: Mismatched start states (" << fst1.
Start() <<
" != " 69 << fst2.
Start() <<
")";
74 while (!siter1.
Done() || !siter2.
Done()) {
75 if (siter1.
Done() || siter2.
Done()) {
76 VLOG(1) <<
"Equal: Mismatched number of states";
79 const auto s1 = siter1.
Value();
80 const auto s2 = siter2.
Value();
82 VLOG(1) <<
"Equal: Mismatched states (" << s1 <<
"!= " 86 const auto &final1 = fst1.
Final(s1);
87 const auto &final2 = fst2.
Final(s2);
88 if (!weight_equal(final1, final2)) {
89 VLOG(1) <<
"Equal: Mismatched final weights at state " << s1
90 <<
" (" << final1 <<
" != " << final2 <<
")";
95 for (
auto a = 0; !aiter1.
Done() || !aiter2.
Done(); ++a) {
96 if (aiter1.
Done() || aiter2.
Done()) {
97 VLOG(1) <<
"Equal: Mismatched number of arcs at state " << s1;
100 const auto &arc1 = aiter1.
Value();
101 const auto &arc2 = aiter2.
Value();
102 if (arc1.ilabel != arc2.ilabel) {
103 VLOG(1) <<
"Equal: Mismatched arc input labels at state " << s1
104 <<
", arc " << a <<
" (" << arc1.ilabel <<
" != " 105 << arc2.ilabel <<
")";
107 }
else if (arc1.olabel != arc2.olabel) {
108 VLOG(1) <<
"Equal: Mismatched arc output labels at state " << s1
109 <<
", arc " << a <<
" (" << arc1.olabel <<
" != " 110 << arc2.olabel <<
")";
112 }
else if (!weight_equal(arc1.weight, arc2.weight)) {
113 VLOG(1) <<
"Equal: Mismatched arc weights at state " << s1
114 <<
", arc " << a <<
" (" << arc1.weight <<
" != " 115 << arc2.weight <<
")";
117 }
else if (arc1.nextstate != arc2.nextstate) {
118 VLOG(1) <<
"Equal: Mismatched next state at state " << s1
119 <<
", arc " << a <<
" (" << arc1.nextstate <<
" != " 120 << arc2.nextstate <<
")";
128 FSTERROR() <<
"Equal: Inconsistent arc counts at state " << s1
129 <<
" (" << fst1.
NumArcs(s1) <<
" != " 134 FSTERROR() <<
"Equal: Inconsistent input epsilon counts at state " << s1
140 FSTERROR() <<
"Equal: Inconsistent output epsilon counts at state " << s1
162 double delta,
uint32 etype = kEqualFsts) {
169 #endif // FST_EQUAL_H_ constexpr uint32 kEqualAll
constexpr uint32 kEqualFstTypes
bool operator()(const Weight &w1, const Weight &w2) const
virtual size_t NumArcs(StateId) const =0
constexpr uint32 kEqualCompatProperties
virtual Weight Final(StateId) const =0
WeightApproxEqual(float delta)
bool CompatProperties(uint64 props1, uint64 props2)
constexpr uint32 kEqualCompatSymbols
constexpr uint64 kCopyProperties
const Arc & Value() const
virtual uint64 Properties(uint64 mask, bool test) const =0
virtual size_t NumInputEpsilons(StateId) const =0
virtual StateId Start() const =0
virtual const string & Type() const =0
virtual const SymbolTable * InputSymbols() const =0
constexpr bool ApproxEqual(const FloatWeightTpl< T > &w1, const FloatWeightTpl< T > &w2, float delta=kDelta)
bool Equal(const Fst< Arc > &fst1, const Fst< Arc > &fst2, WeightEqual weight_equal, uint32 etype=kEqualFsts)
bool CompatSymbols(const SymbolTable *syms1, const SymbolTable *syms2, bool warning=true)
constexpr uint32 kEqualFsts
virtual size_t NumOutputEpsilons(StateId) const =0
virtual const SymbolTable * OutputSymbols() const =0