27 #ifndef FST_LEXICOGRAPHIC_WEIGHT_H_ 28 #define FST_LEXICOGRAPHIC_WEIGHT_H_ 41 template <
class W1,
class W2>
48 typename W2::ReverseWeight>;
82 static const std::string &
Type() {
83 static const std::string *
const type =
84 new std::string(W1::Type() +
"_LT_" + W2::Type());
91 if (
Value1() == W1::Zero() &&
Value2() == W2::Zero())
return true;
92 if (
Value1() != W1::Zero() &&
Value2() != W2::Zero())
return true;
105 return W1::Properties() & W2::Properties() &
111 template <
class W1,
class W2>
126 template <
class W1,
class W2>
133 template <
class W1,
class W2>
146 template <
class W1,
class W2>
154 bool allow_zero =
true,
157 allow_zero_(allow_zero),
158 num_random_weights_(num_random_weights),
159 generator1_(seed, false, num_random_weights),
160 generator2_(seed, false, num_random_weights) {}
165 std::uniform_int_distribution<>(0, num_random_weights_)(rand_);
166 if (sample == num_random_weights_)
return Weight(W1::Zero(), W2::Zero());
168 return Weight(generator1_(), generator2_());
172 mutable std::mt19937_64 rand_;
173 const bool allow_zero_;
174 const size_t num_random_weights_;
181 #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 &)
LexicographicWeight()=default
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