20 #ifndef FST_TUPLE_WEIGHT_H_ 21 #define FST_TUPLE_WEIGHT_H_ 40 template <
class W,
size_t n>
48 template <
class Iterator>
50 std::copy(begin, end, values_.begin());
53 explicit TupleWeight(
const W &weight = W::Zero()) { values_.fill(weight); }
59 values_[index] = weight;
77 constexpr
static size_t Length() {
return n; }
79 std::istream &
Read(std::istream &istrm) {
80 for (
size_t i = 0; i < n; ++i) values_[i].
Read(istrm);
84 std::ostream &
Write(std::ostream &ostrm)
const {
85 for (
size_t i = 0; i < n; ++i) values_[i].
Write(ostrm);
90 return std::all_of(values_.begin(), values_.end(), std::mem_fn(&W::Member));
95 for (
size_t i = 0; i < n; ++i) hash = 5 * hash + values_[i].
Hash();
101 for (
size_t i = 0; i < n; ++i) {
102 weight.values_[i] = values_[i].Quantize(delta);
109 for (
size_t i = 0; i < n; ++i) w.values_[i] = values_[i].Reverse();
113 const W &
Value(
size_t i)
const {
return values_[i]; }
115 void SetValue(
size_t i,
const W &w) { values_[i] = w; }
118 std::array<W, n> values_;
121 template <
class W,
size_t n>
124 for (
size_t i = 0; i < n; ++i) {
130 template <
class W,
size_t n>
133 for (
size_t i = 0; i < n; ++i) {
139 template <
class W,
size_t n>
142 for (
size_t i = 0; i < n; ++i) {
148 template <
class W,
size_t n>
158 template <
class W,
size_t n>
164 static_assert(n > 0,
"Size must be positive.");
165 for (
size_t i = 0; i < n - 1; ++i) {
178 #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()
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