15 #ifndef FST_TEST_RAND_FST_H_ 16 #define FST_TEST_RAND_FST_H_ 30 template <
class Arc,
class Generate>
31 void RandFst(
const int num_random_states,
const int num_random_arcs,
32 const int num_random_labels,
const float acyclic_prob,
34 using Label =
typename Arc::Label;
35 using StateId =
typename Arc::StateId;
36 using Weight =
typename Arc::Weight;
42 FORWARD_DIRECTION = 1,
43 REVERSE_DIRECTION = 2,
47 std::mt19937_64 rand(seed);
49 std::uniform_int_distribution<>(0, num_random_states - 1)(rand);
50 std::uniform_int_distribution<size_t> arc_dist(0, num_random_arcs - 1);
51 std::uniform_int_distribution<Label> label_dist(0, num_random_labels - 1);
52 std::uniform_int_distribution<StateId> ns_dist(0, ns - 1);
54 ArcDirection arc_direction = ANY_DIRECTION;
55 if (!std::bernoulli_distribution(acyclic_prob)(rand)) {
56 arc_direction = std::bernoulli_distribution(.5)(rand) ? FORWARD_DIRECTION
65 const StateId start = ns_dist(rand);
68 const size_t na = arc_dist(rand);
69 for (
size_t n = 0; n < na; ++n) {
70 StateId s = ns_dist(rand);
72 arc.ilabel = label_dist(rand);
73 arc.olabel = label_dist(rand);
74 arc.weight = generate();
75 arc.nextstate = ns_dist(rand);
76 if ((arc_direction == FORWARD_DIRECTION ||
77 arc_direction == REVERSE_DIRECTION) &&
82 if ((arc_direction == FORWARD_DIRECTION && s > arc.nextstate) ||
83 (arc_direction == REVERSE_DIRECTION && s < arc.nextstate)) {
92 const StateId nf = std::uniform_int_distribution<>(0, ns)(rand);
93 for (StateId n = 0; n < nf; ++n) {
94 const StateId s = ns_dist(rand);
97 VLOG(1) <<
"Check FST for sanity (including property bits).";
105 for (
int n = 0; n < 8; ++n) {
106 mask |= std::uniform_int_distribution<>(0, 0xff)(rand);
115 #endif // FST_TEST_RAND_FST_H_
virtual uint64_t Properties(uint64_t mask, bool test) const =0
constexpr uint64_t kTrinaryProperties
virtual void SetStart(StateId)=0
virtual void SetProperties(uint64_t props, uint64_t mask)=0
void RandFst(const int num_random_states, const int num_random_arcs, const int num_random_labels, const float acyclic_prob, Generate generate, uint64_t seed, MutableFst< Arc > *fst)
bool Verify(const Fst< Arc > &fst, bool allow_negative_labels=false)
constexpr uint64_t kFstProperties
virtual void AddArc(StateId, const Arc &)=0
virtual void SetFinal(StateId s, Weight weight=Weight::One())=0
virtual void DeleteStates(const std::vector< StateId > &)=0
virtual void AddStates(size_t)=0