Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/timbl/Testers.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ namespace Timbl{
double ) override;
private:
std::vector<metricTestFunction*> metricTest;
// Per-feature test info precomputed once, in permuted order, so the inner
// test loop avoids the permutation indirection and, for plain Overlap
// features (the common case), the virtual metricTestFunction / fvDistance
// / metric->distance() chain -- which for Overlap only computes
// (F==G ? 0 : weight).
std::vector<metricTestFunction*> permTest; // metricTest in permuted order
std::vector<char> isOverlap; // 1 if feature uses Overlap
};

class SimilarityTester: public TesterClass {
Expand Down
23 changes: 20 additions & 3 deletions src/Testers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ namespace Timbl{
metricTest[i] = new overlapTestFunction();
}
}
// Precompute, in permuted order, the metric test function and an Overlap
// flag for each feature, so test() can use a flat index and take a direct
// path for Overlap features.
permTest.resize(_size,0);
isOverlap.resize(_size,0);
for ( size_t j=0; j < _size; ++j ){
Feature *feat = permFeatures[j];
permTest[j] = metricTest[permutation[j]];
isOverlap[j] = ( feat && !feat->Ignore()
&& feat->getMetricType() == Overlap ) ? 1 : 0;
}
}

size_t DistanceTester::test( const vector<FeatureValue *>& G,
Expand All @@ -164,9 +175,15 @@ namespace Timbl{
cerr << "feature " << TrueF << " (perm=" << permutation[TrueF]
<< ")" << endl;
#endif
double result = metricTest[permutation[TrueF]]->test( (*FV)[TrueF],
G[i],
permFeatures[TrueF] );
double result;
if ( isOverlap[TrueF] ){
// plain Overlap: distance is 0 for an exact value match, otherwise
// the feature weight -- no virtual metric dispatch needed.
result = ( (*FV)[TrueF] == G[i] ) ? 0.0 : permFeatures[TrueF]->Weight();
}
else {
result = permTest[TrueF]->test( (*FV)[TrueF], G[i], permFeatures[TrueF] );
}
distances[i+1] = distances[i] + result;
if ( distances[i+1] > Threshold ){
#ifdef DBGTEST
Expand Down
Loading