27 #ifndef FST_LEXICOGRAPHIC_WEIGHT_H_ 28 #define FST_LEXICOGRAPHIC_WEIGHT_H_ 42 template <
class W1,
class W2>
49 typename W2::ReverseWeight>;
83 static const std::string &
Type() {
84 static const std::string *
const type =
85 new std::string(W1::Type() +
"_LT_" + W2::Type());
92 if (
Value1() == W1::Zero() &&
Value2() == W2::Zero())
return true;
93 if (
Value1() != W1::Zero() &&
Value2() != W2::Zero())
return true;
106 return W1::Properties() & W2::Properties() &
112 template <
class W1,
class W2>
127 template <
class W1,
class W2>
134 template <
class W1,
class W2>
147 template <
class W1,
class W2>
155 bool allow_zero =
true,
158 allow_zero_(allow_zero),
159 num_random_weights_(num_random_weights),
160 generator1_(seed, false, num_random_weights),
161 generator2_(seed, false, num_random_weights) {}
166 std::uniform_int_distribution<>(0, num_random_weights_)(rand_);
167 if (sample == num_random_weights_)
return Weight(W1::Zero(), W2::Zero());
169 return Weight(generator1_(), generator2_());
173 mutable std::mt19937_64 rand_;
174 const bool allow_zero_;
175 const size_t num_random_weights_;
182 #endif // FST_LEXICOGRAPHIC_WEIGHT_H_ LexicographicWeight(const PairWeight< W1, W2 > &w)
static constexpr uint64_t Properties()
LexicographicWeight< typename W1::ReverseWeight, typename W2::ReverseWeight > ReverseWeight
ErrorWeight Plus(const ErrorWeight &, const ErrorWeight &)
static const std::string & Type()
ErrorWeight Times(const ErrorWeight &, const ErrorWeight &)
const W2 & Value2() const
constexpr uint64_t kIdempotent
LexicographicWeight(W1 w1, W2 w2)
constexpr uint64_t kRightSemiring
WeightGenerate(uint64_t seed=std::random_device()(), bool allow_zero=true, size_t num_random_weights=kNumRandomWeights)
static const LexicographicWeight & One()
static const LexicographicWeight & Zero()
constexpr uint64_t kCommutative
LexicographicWeight Quantize(float delta=kDelta) const
ReverseWeight Reverse() const
static const LexicographicWeight & NoWeight()
ErrorWeight Divide(const ErrorWeight &, const ErrorWeight &)
constexpr size_t kNumRandomWeights
Weight operator()() const
constexpr uint64_t kLeftSemiring
std::bool_constant<(W::Properties()&kPath)!=0 > IsPath
const W1 & Value1() const