diff options
author | Tor Brede Vekterli <vekterli@yahoo-inc.com> | 2017-04-04 11:26:33 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahoo-inc.com> | 2017-04-04 11:26:33 +0000 |
commit | c97525a6e4ed2ee26222362006c3c033953dca01 (patch) | |
tree | 7fbda69d12ee232c46786049cb9b935960709323 /searchlib | |
parent | 412be26e9a6fbc187868feca3c3241e3e81d101b (diff) |
Improve naming and comments. No logic changes.
Diffstat (limited to 'searchlib')
4 files changed, 62 insertions, 46 deletions
diff --git a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp index d5097e70479..3ff8dab9096 100644 --- a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp +++ b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp @@ -31,14 +31,14 @@ template <typename DimensionVType, typename DimensionHType, typename ComponentTy VectorBase<DimensionVType, DimensionHType, ComponentType, HashMapComparator>::~VectorBase() { } template <typename Vector, typename Buffer> -DotProductExecutor<Vector, Buffer>::DotProductExecutor(const IAttributeVector * attribute, const Vector & vector) : +DotProductExecutor<Vector, Buffer>::DotProductExecutor(const IAttributeVector * attribute, const Vector & queryVector) : FeatureExecutor(), _attribute(attribute), - _vector(vector), + _queryVector(queryVector), _buffer() { _buffer.allocate(_attribute->getMaxValueCount()); - _vector.syncMap(); + _queryVector.syncMap(); } template <typename Vector, typename Buffer> @@ -46,11 +46,11 @@ void DotProductExecutor<Vector, Buffer>::execute(uint32_t docId) { feature_t val = 0; - if (!_vector.getDimMap().empty()) { + if (!_queryVector.getDimMap().empty()) { _buffer.fill(*_attribute, docId); for (size_t i = 0; i < _buffer.size(); ++i) { - typename Vector::HashMap::const_iterator itr = _vector.getDimMap().find(_buffer[i].getValue()); - if (itr != _vector.getDimMap().end()) { + typename Vector::HashMap::const_iterator itr = _queryVector.getDimMap().find(_buffer[i].getValue()); + if (itr != _queryVector.getDimMap().end()) { val += _buffer[i].getWeight() * itr->second; } } @@ -65,10 +65,10 @@ StringVector::~StringVector() { } namespace array { template <typename BaseType> -DotProductExecutorBase<BaseType>::DotProductExecutorBase(const V & vector) +DotProductExecutorBase<BaseType>::DotProductExecutorBase(const V & queryVector) : FeatureExecutor(), _multiplier(IAccelrated::getAccelrator()), - _vector(vector) + _queryVector(queryVector) { } @@ -79,15 +79,15 @@ template <typename BaseType> void DotProductExecutorBase<BaseType>::execute(uint32_t docId) { const AT *values(nullptr); size_t count = getAttributeValues(docId, values); - size_t commonRange = std::min(count, _vector.size()); + size_t commonRange = std::min(count, _queryVector.size()); static_assert(std::is_same<typename AT::ValueType, BaseType>::value); outputs().set_number(0, _multiplier->dotProduct( - &_vector[0], reinterpret_cast<const typename AT::ValueType *>(values), commonRange)); + &_queryVector[0], reinterpret_cast<const typename AT::ValueType *>(values), commonRange)); } template <typename A> -DotProductExecutor<A>::DotProductExecutor(const A * attribute, const V & vector) : - DotProductExecutorBase<typename A::BaseType>(vector), +DotProductExecutor<A>::DotProductExecutor(const A * attribute, const V & queryVector) : + DotProductExecutorBase<typename A::BaseType>(queryVector), _attribute(attribute) { } @@ -103,10 +103,10 @@ DotProductExecutor<A>::getAttributeValues(uint32_t docId, const AT * & values) } template <typename A> -SparseDotProductExecutor<A>::SparseDotProductExecutor(const A * attribute, const V & values, const IV & indexes) : - DotProductExecutor<A>(attribute, values), - _indexes(indexes), - _scratch(std::max(static_cast<size_t>(attribute->getMaxValueCount()), indexes.size())) +SparseDotProductExecutor<A>::SparseDotProductExecutor(const A * attribute, const V & queryVector, const IV & queryIndexes) : + DotProductExecutor<A>(attribute, queryVector), + _queryIndexes(queryIndexes), + _scratch(std::max(static_cast<size_t>(attribute->getMaxValueCount()), queryIndexes.size())) { } @@ -121,15 +121,15 @@ SparseDotProductExecutor<A>::getAttributeValues(uint32_t docId, const AT * & val size_t count = this->_attribute->getRawValues(docId, allValues); values = &_scratch[0]; size_t i(0); - for (; (i < _indexes.size()) && (_indexes[i] < count); i++) { - _scratch[i] = allValues[_indexes[i]]; + for (; (i < _queryIndexes.size()) && (_queryIndexes[i] < count); i++) { + _scratch[i] = allValues[_queryIndexes[i]]; } return i; } template <typename A> -DotProductByCopyExecutor<A>::DotProductByCopyExecutor(const A * attribute, const V & values) : - DotProductExecutor<A>(attribute, values), +DotProductByCopyExecutor<A>::DotProductByCopyExecutor(const A * attribute, const V & queryVector) : + DotProductExecutor<A>(attribute, queryVector), _copy(static_cast<size_t>(attribute->getMaxValueCount())) { } @@ -151,9 +151,9 @@ DotProductByCopyExecutor<A>::getAttributeValues(uint32_t docId, const AT * & val } template <typename A> -SparseDotProductByCopyExecutor<A>::SparseDotProductByCopyExecutor(const A * attribute, const V & values, const IV & indexes) : - SparseDotProductExecutor<A>(attribute, values, indexes), - _copy(std::max(static_cast<size_t>(attribute->getMaxValueCount()), indexes.size())) +SparseDotProductByCopyExecutor<A>::SparseDotProductByCopyExecutor(const A * attribute, const V & queryVector, const IV & queryIndexes) : + SparseDotProductExecutor<A>(attribute, queryVector, queryIndexes), + _copy(std::max(static_cast<size_t>(attribute->getMaxValueCount()), queryIndexes.size())) { } @@ -170,7 +170,7 @@ SparseDotProductByCopyExecutor<A>::getAttributeValues(uint32_t docId, const AT * count = this->_attribute->getAll(docId, &_copy[0], _copy.size()); } size_t i(0); - for (const IV & iv(this->_indexes); (i < iv.size()) && (iv[i] < count); i++) { + for (const IV & iv(this->_queryIndexes); (i < iv.size()) && (iv[i] < count); i++) { _copy[i] = _copy[iv[i]]; } values = reinterpret_cast<const AT *>(&_copy[0]); @@ -180,8 +180,8 @@ SparseDotProductByCopyExecutor<A>::getAttributeValues(uint32_t docId, const AT * template <typename BaseType> DotProductByContentFillExecutor<BaseType>::DotProductByContentFillExecutor( const attribute::IAttributeVector * attribute, - const V & vector) - : DotProductExecutorBase<BaseType>(vector), + const V & queryVector) + : DotProductExecutorBase<BaseType>(queryVector), _attribute(attribute), _filler() { @@ -220,14 +220,14 @@ size_t DotProductByContentFillExecutor<BaseType>::getAttributeValues(uint32_t do template <typename BaseType> SparseDotProductByContentFillExecutor<BaseType>::SparseDotProductByContentFillExecutor( const attribute::IAttributeVector * attribute, - const V & vector, - const IV & indexes) - : DotProductExecutorBase<BaseType>(vector), + const V & queryVector, + const IV & queryIndexes) + : DotProductExecutorBase<BaseType>(queryVector), _attribute(attribute), - _indexes(indexes), + _queryIndexes(queryIndexes), _filler() { - _filler.allocate(std::max(static_cast<size_t>(attribute->getMaxValueCount()), indexes.size())); + _filler.allocate(std::max(static_cast<size_t>(attribute->getMaxValueCount()), queryIndexes.size())); } template <typename BaseType> @@ -241,8 +241,8 @@ size_t SparseDotProductByContentFillExecutor<BaseType>::getAttributeValues(uint3 const size_t count = _filler.size(); BaseType * data = _filler.data(); size_t i = 0; - for (; (i < _indexes.size()) && (_indexes[i] < count); ++i) { - data[i] = data[_indexes[i]]; + for (; (i < _queryIndexes.size()) && (_queryIndexes[i] < count); ++i) { + data[i] = data[_queryIndexes[i]]; } sanity_check_reinterpret_cast_compatibility<BaseType, AT, decltype(*_filler.data())>(); diff --git a/searchlib/src/vespa/searchlib/features/dotproductfeature.h b/searchlib/src/vespa/searchlib/features/dotproductfeature.h index 5a5b809875b..d25803a085b 100644 --- a/searchlib/src/vespa/searchlib/features/dotproductfeature.h +++ b/searchlib/src/vespa/searchlib/features/dotproductfeature.h @@ -113,11 +113,11 @@ template <typename Vector, typename Buffer> class DotProductExecutor : public fef::FeatureExecutor { private: const search::attribute::IAttributeVector * _attribute; - Vector _vector; + Vector _queryVector; Buffer _buffer; public: - DotProductExecutor(const search::attribute::IAttributeVector * attribute, const Vector & vector); + DotProductExecutor(const search::attribute::IAttributeVector * attribute, const Vector & queryVector); void execute(uint32_t docId) override; }; @@ -137,10 +137,10 @@ public: using V = std::vector<BaseType>; private: vespalib::hwaccelrated::IAccelrated::UP _multiplier; - V _vector; + V _queryVector; virtual size_t getAttributeValues(uint32_t docid, const AT * & count) = 0; public: - DotProductExecutorBase(const V & vector); + DotProductExecutorBase(const V & queryVector); ~DotProductExecutorBase(); void execute(uint32_t docId) final override; }; @@ -158,7 +158,7 @@ protected: private: virtual size_t getAttributeValues(uint32_t docid, const AT * & count); public: - DotProductExecutor(const A * attribute, const V & vector); + DotProductExecutor(const A * attribute, const V & queryVector); ~DotProductExecutor(); }; @@ -166,7 +166,7 @@ template <typename A> class DotProductByCopyExecutor : public DotProductExecutor<A> { public: typedef typename DotProductExecutor<A>::V V; - DotProductByCopyExecutor(const A * attribute, const V & vector); + DotProductByCopyExecutor(const A * attribute, const V & queryVector); ~DotProductByCopyExecutor(); private: typedef typename DotProductExecutor<A>::AT AT; @@ -192,7 +192,7 @@ public: using AT = typename DotProductExecutorBase<BaseType>::AT; using ValueFiller = attribute::AttributeContent<BaseType>; - DotProductByContentFillExecutor(const attribute::IAttributeVector * attribute, const V & vector); + DotProductByContentFillExecutor(const attribute::IAttributeVector * attribute, const V & queryVector); ~DotProductByContentFillExecutor(); private: size_t getAttributeValues(uint32_t docid, const AT * & values) final override; @@ -206,13 +206,13 @@ class SparseDotProductExecutor : public DotProductExecutor<A> { public: typedef std::vector<uint32_t> IV; typedef typename DotProductExecutor<A>::V V; - SparseDotProductExecutor(const A * attribute, const V & vector, const IV & indexes); + SparseDotProductExecutor(const A * attribute, const V & queryVector, const IV & queryIndexes); ~SparseDotProductExecutor(); private: typedef typename DotProductExecutor<A>::AT AT; size_t getAttributeValues(uint32_t docid, const AT * & count) override; protected: - IV _indexes; + IV _queryIndexes; std::vector<AT> _scratch; }; @@ -221,7 +221,7 @@ class SparseDotProductByCopyExecutor : public SparseDotProductExecutor<A> { public: typedef std::vector<uint32_t> IV; typedef typename DotProductExecutor<A>::V V; - SparseDotProductByCopyExecutor(const A * attribute, const V & vector, const IV & indexes); + SparseDotProductByCopyExecutor(const A * attribute, const V & queryVector, const IV & queryIndexes); ~SparseDotProductByCopyExecutor(); private: typedef typename DotProductExecutor<A>::AT AT; @@ -242,14 +242,14 @@ public: using ValueFiller = attribute::AttributeContent<BaseType>; SparseDotProductByContentFillExecutor(const attribute::IAttributeVector * attribute, - const V & vector, - const IV & indexes); + const V & queryVector, + const IV & queryIndexes); ~SparseDotProductByContentFillExecutor(); private: size_t getAttributeValues(uint32_t docid, const AT * & values) final override; const attribute::IAttributeVector* _attribute; - IV _indexes; + IV _queryIndexes; ValueFiller _filler; }; diff --git a/searchlib/src/vespa/searchlib/fef/test/attribute_map.h b/searchlib/src/vespa/searchlib/fef/test/attribute_map.h index db62cbebdab..b7b5a83ab1b 100644 --- a/searchlib/src/vespa/searchlib/fef/test/attribute_map.h +++ b/searchlib/src/vespa/searchlib/fef/test/attribute_map.h @@ -11,6 +11,14 @@ namespace search { namespace fef { namespace test { +/** + * Simple mapping from attribute name to IAttributeVector which can be used for tests + * that do do not want the complexity of instantiating a full AttributeManager, or + * for tests that need to work with IAttributeVectors rather than AttributeVectors. + * + * Allows for creating AttributeContext instances which transparently access the + * attribute map for their lookups. + */ class AttributeMap { std::map<vespalib::string, std::shared_ptr<attribute::IAttributeVector>> _attributes; public: diff --git a/searchlib/src/vespa/searchlib/fef/test/mock_attribute_context.h b/searchlib/src/vespa/searchlib/fef/test/mock_attribute_context.h index adfa7048d67..5c5cfa1dcce 100644 --- a/searchlib/src/vespa/searchlib/fef/test/mock_attribute_context.h +++ b/searchlib/src/vespa/searchlib/fef/test/mock_attribute_context.h @@ -12,6 +12,14 @@ namespace test { class AttributeMap; +/** + * Simple IAttributeContext implementation which forwards all attribute lookups + * to a referenced AttributeMap. + * + * Note that the attribute mapping does not use any kind of snapshot visibility; + * changes to the associated AttributeMap after the context has been created will + * be reflected in subsequent calls to the attribute context. + */ class MockAttributeContext : public attribute::IAttributeContext { const AttributeMap& _attributes; public: |