diff options
author | Arne Juul <arnej@verizonmedia.com> | 2021-04-14 17:08:10 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2021-04-14 17:08:10 +0000 |
commit | f57bbb336dcc6eabcfe09034be5aac32cd02073c (patch) | |
tree | b6fa8cd789250a409b69c470c6a722d55a407b58 /searchlib | |
parent | 8ed6273fd8458eb36da7d75413437e6b63ae5aac (diff) |
restore optimization lost when moving code around
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/vespa/searchlib/tensor/euclidean_distance.h | 19 |
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; }; |