20 #ifndef FST_TUPLE_WEIGHT_H_ 21 #define FST_TUPLE_WEIGHT_H_ 39 template <
class W,
size_t n>
47 template <
class Iterator>
49 std::copy(begin, end, values_.begin());
52 explicit TupleWeight(
const W &weight = W::Zero()) { values_.fill(weight); }
58 values_[index] = weight;
76 constexpr
static size_t Length() {
return n; }
78 std::istream &
Read(std::istream &istrm) {
79 for (
size_t i = 0; i < n; ++i) values_[i].
Read(istrm);
83 std::ostream &
Write(std::ostream &ostrm)
const {
84 for (
size_t i = 0; i < n; ++i) values_[i].
Write(ostrm);
89 return std::all_of(values_.begin(), values_.end(), std::mem_fn(&W::Member));
94 for (
size_t i = 0; i < n; ++i) hash = 5 * hash + values_[i].
Hash();
100 for (
size_t i = 0; i < n; ++i) {
101 weight.values_[i] = values_[i].Quantize(delta);
108 for (
size_t i = 0; i < n; ++i) w.values_[i] = values_[i].Reverse();
112 const W &
Value(
size_t i)
const {
return values_[i]; }
114 void SetValue(
size_t i,
const W &w) { values_[i] = w; }
117 std::array<W, n> values_;
120 template <
class W,
size_t n>
123 for (
size_t i = 0; i < n; ++i) {
129 template <
class W,
size_t n>
132 for (
size_t i = 0; i < n; ++i) {
138 template <
class W,
size_t n>
141 for (
size_t i = 0; i < n; ++i) {
147 template <
class W,
size_t n>
157 template <
class W,
size_t n>
163 static_assert(n > 0,
"Size must be positive.");
164 for (
size_t i = 0; i < n - 1; ++i) {
177 #endif // FST_TUPLE_WEIGHT_H_
void SetValue(size_t i, const W &w)
TupleWeight(Index index, const W &weight, const W &default_weight)
ReverseWeight Reverse() const
static const TupleWeight< W, n > & NoWeight()
const W & Value(size_t i) const
std::istream & operator>>(std::istream &strm, FloatWeightTpl< T > &w)
bool operator!=(const ErrorWeight &, const ErrorWeight &)
TupleWeight(Iterator begin, Iterator end)
std::ostream & operator<<(std::ostream &strm, const ErrorWeight &)
std::ostream & Write(std::ostream &ostrm) const
static const TupleWeight< W, n > & One()
bool ReadElement(T *comp, bool last=false)
bool operator==(const ErrorWeight &, const ErrorWeight &)
static const TupleWeight< W, n > & Zero()
TupleWeight(const W &weight=W::Zero())
static constexpr size_t Length()
typename Arc::Weight Weight
void WriteElement(const T &comp)
std::istream & Read(std::istream &istrm)
bool ApproxEqual(const ErrorWeight &, const ErrorWeight &, float)
TupleWeight< W, n > Quantize(float delta=kDelta) const