Skip to content

Commit

Permalink
Restore old (1.6.5) NaturalWeight
Browse files Browse the repository at this point in the history
Because of a conflict with Kaldi's specialization on CompactLatticeWeightTpl,
https://groups.google.com/forum/#!topic/kaldi-developers/RuH8Z1Ttuuk

There is a pending PR to remove the dependency:
kaldi-asr/kaldi#2313

Also rename one type alias in arc-map.h because of a name hiding warning.
  • Loading branch information
kkm committed May 30, 2018
1 parent 48bfdde commit 478e02a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/include/fst/arc-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,10 +914,10 @@ class FromGallicMapper {
template <GallicType GT>
static bool Extract(const GallicWeight<Label, AW, GT> &gallic_weight,
typename A::Weight *weight, typename A::Label *label) {
using GW = StringWeight<Label, GallicStringType(GT)>;
const GW &w1 = gallic_weight.Value1();
using GWT = StringWeight<Label, GallicStringType(GT)>;
const GWT &w1 = gallic_weight.Value1();
const AW &w2 = gallic_weight.Value2();
typename GW::Iterator iter1(w1);
typename GWT::Iterator iter1(w1);
const Label l = w1.Size() == 1 ? iter1.Value() : 0;
if (l == kStringInfinity || l == kStringBad || w1.Size() > 1) return false;
*label = l;
Expand Down
33 changes: 8 additions & 25 deletions src/include/fst/weight.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,37 +169,20 @@ enum DivideType {
//
// We define the strict version of this order below.

// Declares the template with a second parameter determining whether or not it
// can actually be constructed.
template <class W, class IdempotentType = void>
class NaturalLess;

// Variant for idempotent weights.
template <class W>
class NaturalLess<W, typename std::enable_if<IsIdempotent<W>::value>::type> {
public:
using Weight = W;

NaturalLess() {}

bool operator()(const Weight &w1, const Weight &w2) const {
return w1 != w2 && Plus(w1, w2) == w1;
}
};

// Non-constructible variant for non-idempotent weights.
template <class W>
class NaturalLess<W, typename std::enable_if<!IsIdempotent<W>::value>::type> {
public:
class NaturalLess {
public:
using Weight = W;

// TODO(kbg): Trace down anywhere this is being instantiated, then add a
// static_assert to prevent this from being instantiated.
NaturalLess() {
FSTERROR() << "NaturalLess: Weight type is not idempotent: " << W::Type();
if (!(W::Properties() & kIdempotent)) {
FSTERROR() << "NaturalLess: Weight type is not idempotent: " << W::Type();
}
}

bool operator()(const Weight &, const Weight &) const { return false; }
bool operator()(const W &w1, const W &w2) const {
return (Plus(w1, w2) == w1) && w1 != w2;
}
};

// Power is the iterated product for arbitrary semirings such that Power(w, 0)
Expand Down

0 comments on commit 478e02a

Please sign in to comment.