summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-03-31 13:04:08 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-03-31 13:04:08 +0000
commit83eeb7b0240b96c2d8c2695affad4bcd69282111 (patch)
tree7a597fe2f731fd866e7875247d3c32b8d02cd352 /searchlib
parent451173e78f50c4db14f0def7a12eb9881720b94a (diff)
- Add testing of enumerated weighted sets.
- Add testing that query can use floating point numbers for the weight. - Stay with the type feature_t for query. Do not assume th ethe weight type used in the attribute.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/features/prod_features.cpp10
-rw-r--r--searchlib/src/vespa/searchlib/features/dotproductfeature.cpp23
2 files changed, 19 insertions, 14 deletions
diff --git a/searchlib/src/tests/features/prod_features.cpp b/searchlib/src/tests/features/prod_features.cpp
index 64a999906d8..1c07c81bc2f 100644
--- a/searchlib/src/tests/features/prod_features.cpp
+++ b/searchlib/src/tests/features/prod_features.cpp
@@ -1238,10 +1238,11 @@ Test::testDotProduct()
assertDotProduct(0, "(f:5,g:5)", 1, "wsextstr");
assertDotProduct(550, "(a:1,b:2,c:3,d:4,e:5)", 1, "wsextstr");
}
- for (const char * name : {"wsbyte", "wsint"}) {
- assertDotProduct(0, "()", 1, name);
- assertDotProduct(0, "(6:5,7:5)", 1, name);
- assertDotProduct(55, "(1:1,2:2,3:3,4:4,5:5)", 1, name);
+ for (const char * name : {"wsbyte", "wsint", "wsint_fast"}) {
+ TEST_DO(assertDotProduct(0, "()", 1, name));
+ TEST_DO(assertDotProduct(0, "(6:5,7:5)", 1, name));
+ TEST_DO(assertDotProduct(18, "(4:4.5)", 1, name));
+ TEST_DO(assertDotProduct(57, "(1:1,2:2,3:3,4:4.5,5:5)", 1, name));
}
for (const char * name : {"arrbyte", "arrint", "arrfloat", "arrint_fast", "arrfloat_fast"}) {
assertDotProduct(0, "()", 1, name);
@@ -1300,6 +1301,7 @@ Test::setupForDotProductTest(FtFeatureTest & ft)
};
std::vector<Config> cfgList = { {"wsint", AVBT::INT32, AVCT::WSET, false},
{"wsbyte", AVBT::INT8, AVCT::WSET, false},
+ {"wsint_fast", AVBT::INT8, AVCT::WSET, true},
{"arrbyte", AVBT::INT8, AVCT::ARRAY, false},
{"arrint", AVBT::INT32, AVCT::ARRAY, false},
{"arrfloat", AVBT::FLOAT, AVCT::ARRAY, false},
diff --git a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp
index ec31bcb5117..a8737a19eec 100644
--- a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp
+++ b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp
@@ -224,25 +224,27 @@ private:
template <typename A>
class SingleDotProductExecutorByValue final : public fef::FeatureExecutor {
public:
- SingleDotProductExecutorByValue(const A * attribute, multivalue::WeightedValue<typename A::BaseType> keyValue)
+ SingleDotProductExecutorByValue(const A * attribute, typename A::BaseType key, feature_t value)
: _attribute(attribute),
- _keyValue(keyValue)
+ _key(key),
+ _value(value)
{}
void execute(uint32_t docId) override {
const multivalue::WeightedValue<typename A::BaseType> *values(nullptr);
uint32_t sz = _attribute->getRawValues(docId, values);
for (size_t i = 0; i < sz; ++i) {
- if (values[i].value() == _keyValue.value()) {
- outputs().set_number(0, values[i].weight()*_keyValue.weight());
+ if (values[i].value() == _key) {
+ outputs().set_number(0, values[i].weight() * _value);
return;
}
}
outputs().set_number(0, 0);
}
private:
- const A * _attribute;
- multivalue::WeightedValue<typename A::BaseType> _keyValue;
+ const A * _attribute;
+ typename A::BaseType _key;
+ feature_t _value;
};
}
@@ -628,9 +630,9 @@ size_t extractSize(const dotproduct::wset::IntegerVectorT<T> & v) {
}
template<typename T>
-multivalue::WeightedValue<T> extractElem(const dotproduct::wset::IntegerVectorT<T> & v, size_t idx) {
+std::pair<T, feature_t> extractElem(const dotproduct::wset::IntegerVectorT<T> & v, size_t idx) {
const auto & pair = v.getVector()[idx];
- return multivalue::WeightedValue<T>(pair.first, pair.second);
+ return std::pair<T, feature_t>(pair.first, pair.second);
}
template<typename T>
@@ -639,7 +641,7 @@ size_t extractSize(const std::unique_ptr<dotproduct::wset::IntegerVectorT<T>> &
}
template<typename T>
-multivalue::WeightedValue<T> extractElem(const std::unique_ptr<dotproduct::wset::IntegerVectorT<T>> & v, size_t idx) {
+std::pair<T, feature_t> extractElem(const std::unique_ptr<dotproduct::wset::IntegerVectorT<T>> & v, size_t idx) {
return extractElem(*v, idx);
}
@@ -656,7 +658,8 @@ createForDirectWSetImpl(const IAttributeVector * attribute, V && vector, vespali
auto * exactA = dynamic_cast<const ExactA *>(iattr);
if (exactA != nullptr) {
if (extractSize(vector) == 1) {
- return stash.create<SingleDotProductExecutorByValue<ExactA>>(exactA, extractElem(vector, 0ul));
+ auto elem = extractElem(vector, 0ul);
+ return stash.create<SingleDotProductExecutorByValue<ExactA>>(exactA, elem.first, elem.second);
}
return stash.create<DotProductExecutor<ExactA>>(exactA, std::forward<V>(vector));
}