summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-04-14 20:54:25 +0200
committerGitHub <noreply@github.com>2021-04-14 20:54:25 +0200
commit73b45b0b5223cc1b6b2ae2dbdf6a587ef59ab192 (patch)
treedc1682874cc3b9fddf15a4beac3e8e49f34cb81c /searchlib
parent01758085e04f5b08f8aa7f22e7705384812e483a (diff)
parentf57bbb336dcc6eabcfe09034be5aac32cd02073c (diff)
Merge pull request #17433 from vespa-engine/arnej/restore-lost-calc-with-limit
restore optimization lost when moving code around
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/tensor/euclidean_distance.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchlib/tensor/euclidean_distance.h b/searchlib/src/vespa/searchlib/tensor/euclidean_distance.h
index 0669476c7aa..f0eb03293cd 100644
--- a/searchlib/src/vespa/searchlib/tensor/euclidean_distance.h
+++ b/searchlib/src/vespa/searchlib/tensor/euclidean_distance.h
@@ -43,6 +43,7 @@ public:
{
assert(expected_cell_type() == vespalib::eval::get_cell_type<FloatType>());
}
+
double calc(const vespalib::eval::TypedCells& lhs, const vespalib::eval::TypedCells& rhs) const override {
constexpr vespalib::eval::CellType expected = vespalib::eval::get_cell_type<FloatType>();
assert(lhs.type == expected && rhs.type == expected);
@@ -52,6 +53,24 @@ public:
assert(sz == rhs_vector.size());
return _computer.squaredEuclideanDistance(&lhs_vector[0], &rhs_vector[0], sz);
}
+
+ double calc_with_limit(const vespalib::eval::TypedCells& lhs,
+ const vespalib::eval::TypedCells& rhs,
+ double limit) const override
+ {
+ constexpr vespalib::eval::CellType expected = vespalib::eval::get_cell_type<FloatType>();
+ assert(lhs.type == expected && rhs.type == expected);
+ auto lhs_vector = lhs.typify<FloatType>();
+ auto rhs_vector = rhs.typify<FloatType>();
+ double sum = 0.0;
+ size_t sz = lhs_vector.size();
+ assert(sz == rhs_vector.size());
+ for (size_t i = 0; i < sz && sum <= limit; ++i) {
+ double diff = lhs_vector[i] - rhs_vector[i];
+ sum += diff*diff;
+ }
+ return sum;
+ }
private:
const vespalib::hwaccelrated::IAccelrated & _computer;
};