summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval/src/tests/tensor/direct_dense_tensor_builder/direct_dense_tensor_builder_test.cpp2
-rw-r--r--eval/src/vespa/eval/eval/engine_or_factory.cpp10
-rw-r--r--eval/src/vespa/eval/eval/engine_or_factory.h1
-rw-r--r--eval/src/vespa/eval/eval/tensor_spec.cpp11
-rw-r--r--eval/src/vespa/eval/eval/test/CMakeLists.txt1
-rw-r--r--eval/src/vespa/eval/eval/test/value_compare.cpp20
-rw-r--r--eval/src/vespa/eval/eval/test/value_compare.h14
-rw-r--r--eval/src/vespa/eval/tensor/dense/dense_tensor.cpp8
-rw-r--r--eval/src/vespa/eval/tensor/dense/dense_tensor_reduce.hpp4
-rw-r--r--eval/src/vespa/eval/tensor/dense/dense_tensor_view.h3
-rw-r--r--eval/src/vespa/eval/tensor/serialization/dense_binary_format.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp4
15 files changed, 68 insertions, 24 deletions
diff --git a/eval/src/tests/tensor/direct_dense_tensor_builder/direct_dense_tensor_builder_test.cpp b/eval/src/tests/tensor/direct_dense_tensor_builder/direct_dense_tensor_builder_test.cpp
index 4c96145862c..52768663647 100644
--- a/eval/src/tests/tensor/direct_dense_tensor_builder/direct_dense_tensor_builder_test.cpp
+++ b/eval/src/tests/tensor/direct_dense_tensor_builder/direct_dense_tensor_builder_test.cpp
@@ -176,7 +176,7 @@ TEST("require that dense tensor cells iterator works for 2d tensor") {
TEST("require that memory used count is reasonable") {
Tensor::UP full = build2DTensor();
const DenseTensorView &full_view = dynamic_cast<const DenseTensorView &>(*full);
- DenseTensorView ref_view(full_view.fast_type(), full_view.cellsRef());
+ DenseTensorView ref_view(full_view.fast_type(), full_view.cells());
size_t full_sz = full->get_memory_usage().usedBytes();
size_t view_sz = full_view.get_memory_usage().usedBytes();
diff --git a/eval/src/vespa/eval/eval/engine_or_factory.cpp b/eval/src/vespa/eval/eval/engine_or_factory.cpp
index 67885ede48e..2a3ba2e543f 100644
--- a/eval/src/vespa/eval/eval/engine_or_factory.cpp
+++ b/eval/src/vespa/eval/eval/engine_or_factory.cpp
@@ -8,6 +8,8 @@
#include <vespa/eval/tensor/default_tensor_engine.h>
#include <vespa/eval/tensor/default_value_builder_factory.h>
#include <vespa/eval/tensor/mixed/packed_mixed_tensor_builder_factory.h>
+#include <vespa/vespalib/data/memory.h>
+#include <vespa/vespalib/objects/nbostream.h>
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/util/stringfmt.h>
@@ -76,6 +78,14 @@ EngineOrFactory::decode(nbostream &input) const
}
}
+std::unique_ptr<Value>
+EngineOrFactory::copy(const Value &value)
+{
+ nbostream stream;
+ encode(value, stream);
+ return decode(stream);
+}
+
const Value &
EngineOrFactory::map(const Value &a, operation::op1_t function, Stash &stash) const {
return engine().map(a, function, stash);
diff --git a/eval/src/vespa/eval/eval/engine_or_factory.h b/eval/src/vespa/eval/eval/engine_or_factory.h
index e94febd54ea..a22d484b5b5 100644
--- a/eval/src/vespa/eval/eval/engine_or_factory.h
+++ b/eval/src/vespa/eval/eval/engine_or_factory.h
@@ -47,6 +47,7 @@ public:
std::unique_ptr<Value> from_spec(const TensorSpec &spec) const;
void encode(const Value &value, nbostream &output) const;
std::unique_ptr<Value> decode(nbostream &input) const;
+ std::unique_ptr<Value> copy(const Value &value);
// engine-only forwarding functions
const Value &map(const Value &a, operation::op1_t function, Stash &stash) const;
const Value &join(const Value &a, const Value &b, operation::op2_t function, Stash &stash) const;
diff --git a/eval/src/vespa/eval/eval/tensor_spec.cpp b/eval/src/vespa/eval/eval/tensor_spec.cpp
index 1a6a9520e58..98bc09217c1 100644
--- a/eval/src/vespa/eval/eval/tensor_spec.cpp
+++ b/eval/src/vespa/eval/eval/tensor_spec.cpp
@@ -2,6 +2,7 @@
#include "tensor_spec.h"
#include "value.h"
+#include "value_codec.h"
#include "tensor.h"
#include "tensor_engine.h"
#include "simple_tensor_engine.h"
@@ -115,13 +116,11 @@ TensorSpec::from_slime(const slime::Inspector &tensor)
TensorSpec
TensorSpec::from_value(const eval::Value &value)
{
- if (const eval::Tensor *tensor = value.as_tensor()) {
- return tensor->engine().to_spec(*tensor);
+ if (auto tensor = dynamic_cast<const vespalib::eval::Tensor *>(&value)) {
+ return tensor->engine().to_spec(value);
+ } else {
+ return spec_from_value(value);
}
- if (value.is_double()) {
- return TensorSpec("double").add({}, value.as_double());
- }
- return TensorSpec("error");
}
TensorSpec
diff --git a/eval/src/vespa/eval/eval/test/CMakeLists.txt b/eval/src/vespa/eval/eval/test/CMakeLists.txt
index 8b4f7c4f93b..6e88beab9b7 100644
--- a/eval/src/vespa/eval/eval/test/CMakeLists.txt
+++ b/eval/src/vespa/eval/eval/test/CMakeLists.txt
@@ -5,4 +5,5 @@ vespa_add_library(eval_eval_test OBJECT
eval_spec.cpp
tensor_conformance.cpp
test_io.cpp
+ value_compare.cpp
)
diff --git a/eval/src/vespa/eval/eval/test/value_compare.cpp b/eval/src/vespa/eval/eval/test/value_compare.cpp
new file mode 100644
index 00000000000..ff6a4e72ebc
--- /dev/null
+++ b/eval/src/vespa/eval/eval/test/value_compare.cpp
@@ -0,0 +1,20 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "value_compare.h"
+#include <vespa/eval/eval/tensor.h>
+#include <vespa/eval/eval/tensor_engine.h>
+#include <vespa/eval/eval/value_codec.h>
+
+namespace vespalib::eval {
+
+bool operator==(const Value &lhs, const Value &rhs)
+{
+ return TensorSpec::from_value(lhs) == TensorSpec::from_value(rhs);
+}
+
+std::ostream &operator<<(std::ostream &out, const Value &value)
+{
+ return out << TensorSpec::from_value(value);
+}
+
+} // namespace vespalib::eval
diff --git a/eval/src/vespa/eval/eval/test/value_compare.h b/eval/src/vespa/eval/eval/test/value_compare.h
new file mode 100644
index 00000000000..f514cec8da7
--- /dev/null
+++ b/eval/src/vespa/eval/eval/test/value_compare.h
@@ -0,0 +1,14 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <vespa/eval/eval/value.h>
+
+namespace vespalib::eval {
+
+bool operator==(const Value &lhs, const Value &rhs);
+
+std::ostream &operator<<(std::ostream &out, const Value &value);
+
+}
+
diff --git a/eval/src/vespa/eval/tensor/dense/dense_tensor.cpp b/eval/src/vespa/eval/tensor/dense/dense_tensor.cpp
index 7faba87dbd3..26f9194c8ce 100644
--- a/eval/src/vespa/eval/tensor/dense/dense_tensor.cpp
+++ b/eval/src/vespa/eval/tensor/dense/dense_tensor.cpp
@@ -25,19 +25,19 @@ void
checkCellsSize(const DenseTensor<T> &arg)
{
auto cellsSize = calcCellsSize(arg.fast_type());
- if (arg.cellsRef().size != cellsSize) {
+ if (arg.cells().size != cellsSize) {
throw IllegalStateException(make_string("Wrong cell size, "
"expected=%zu, "
"actual=%zu",
cellsSize,
- arg.cellsRef().size));
+ arg.cells().size));
}
- if (arg.fast_type().cell_type() != arg.cellsRef().type) {
+ if (arg.fast_type().cell_type() != arg.cells().type) {
throw IllegalStateException(make_string("Wrong cell type, "
"expected=%u, "
"actual=%u",
(unsigned char)arg.fast_type().cell_type(),
- (unsigned char)arg.cellsRef().type));
+ (unsigned char)arg.cells().type));
}
}
diff --git a/eval/src/vespa/eval/tensor/dense/dense_tensor_reduce.hpp b/eval/src/vespa/eval/tensor/dense/dense_tensor_reduce.hpp
index 5673a35c7e6..cbdf7e0a3ca 100644
--- a/eval/src/vespa/eval/tensor/dense/dense_tensor_reduce.hpp
+++ b/eval/src/vespa/eval/tensor/dense/dense_tensor_reduce.hpp
@@ -75,7 +75,7 @@ std::unique_ptr<DenseTensorView>
reduce(const DenseTensorView &tensor, const vespalib::string &dimensionToRemove, Function &&func)
{
DimensionReducer reducer(tensor.fast_type(), dimensionToRemove);
- TypedCells oldCells = tensor.cellsRef();
+ TypedCells oldCells = tensor.cells();
return dispatch_1<CallReduceCells>(oldCells, reducer, func);
}
@@ -97,7 +97,7 @@ reduce(const DenseTensorView &tensor, const std::vector<vespalib::string> &dimen
{
eval::ValueType newType = tensor.fast_type().reduce(dimensions);
assert(newType.is_double());
- double result = reduce_all_dimensions(tensor.cellsRef(), func);
+ double result = reduce_all_dimensions(tensor.cells(), func);
std::vector<double> newCells({result});
return std::make_unique<DenseTensor<double>>(std::move(newType), std::move(newCells));
}
diff --git a/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h b/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h
index 27a032b784f..cd0e1ae84da 100644
--- a/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h
+++ b/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h
@@ -27,8 +27,7 @@ public:
}
const eval::ValueType &fast_type() const { return _typeRef; }
- const TypedCells &cellsRef() const { return _cellsRef; }
- TypedCells cells() const override { return _cellsRef; }
+ TypedCells cells() const final override { return _cellsRef; }
const Index &index() const override { return eval::TrivialIndex::get(); }
bool operator==(const DenseTensorView &rhs) const;
CellsIterator cellsIterator() const { return CellsIterator(_typeRef, _cellsRef); }
diff --git a/eval/src/vespa/eval/tensor/serialization/dense_binary_format.cpp b/eval/src/vespa/eval/tensor/serialization/dense_binary_format.cpp
index 4d6cfb1c9af..13c4711668b 100644
--- a/eval/src/vespa/eval/tensor/serialization/dense_binary_format.cpp
+++ b/eval/src/vespa/eval/tensor/serialization/dense_binary_format.cpp
@@ -77,7 +77,7 @@ void
DenseBinaryFormat::serialize(nbostream &stream, const DenseTensorView &tensor)
{
size_t cellsSize = encodeDimensions(stream, tensor.fast_type());
- TypedCells cells = tensor.cellsRef();
+ TypedCells cells = tensor.cells();
assert(cells.size == cellsSize);
switch (tensor.fast_type().cell_type()) {
case CellType::DOUBLE:
diff --git a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp
index 877ed6b5094..e99e14c8d6b 100644
--- a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp
@@ -24,7 +24,7 @@ template<typename LCT, typename RCT>
void
convert_cells(std::unique_ptr<DenseTensorView> &original, vespalib::eval::ValueType want_type)
{
- auto old_cells = original->cellsRef().typify<LCT>();
+ auto old_cells = original->cells().typify<LCT>();
std::vector<RCT> new_cells;
new_cells.reserve(old_cells.size());
for (LCT value : old_cells) {
@@ -66,7 +66,7 @@ NearestNeighborBlueprint::NearestNeighborBlueprint(const queryeval::FieldSpec& f
_found_hits(),
_global_filter(GlobalFilter::create())
{
- auto lct = _query_tensor->cellsRef().type;
+ auto lct = _query_tensor->cells().type;
auto rct = _attr_tensor.getTensorType().cell_type();
using MyTypify = vespalib::eval::TypifyCellType;
auto fixup_fun = vespalib::typify_invoke<2,MyTypify,ConvertCellsSelector>(lct, rct);
@@ -124,7 +124,7 @@ NearestNeighborBlueprint::perform_top_k()
auto rhs_type = _attr_tensor.getTensorType();
// different cell types should be converted already
if (lhs_type == rhs_type) {
- auto lhs = _query_tensor->cellsRef();
+ auto lhs = _query_tensor->cells();
uint32_t k = _target_num_hits;
if (_global_filter->has_filter()) {
auto filter = _global_filter->filter();
diff --git a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp
index cf4e8ae2f6a..3012de7563b 100644
--- a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp
@@ -37,7 +37,7 @@ public:
NearestNeighborImpl(Params params_in)
: NearestNeighborIterator(params_in),
- _lhs(params().queryTensor.cellsRef()),
+ _lhs(params().queryTensor.cells()),
_fieldTensor(params().tensorAttribute.getTensorType()),
_lastScore(0.0)
{
@@ -77,7 +77,7 @@ public:
private:
double computeDistance(uint32_t docId, double limit) {
params().tensorAttribute.extract_dense_view(docId, _fieldTensor);
- auto rhs = _fieldTensor.cellsRef();
+ auto rhs = _fieldTensor.cells();
return params().distanceFunction->calc_with_limit(_lhs, rhs, limit);
}
diff --git a/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp
index 0a34c18bae9..81c8df982b1 100644
--- a/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp
@@ -149,7 +149,7 @@ DenseTensorAttribute::prepare_set_tensor(DocId docid, const Tensor& tensor) cons
if (_index) {
const auto* view = dynamic_cast<const DenseTensorView*>(&tensor);
assert(view);
- return _index->prepare_add_document(docid, view->cellsRef(), getGenerationHandler().takeGuard());
+ return _index->prepare_add_document(docid, view->cells(), getGenerationHandler().takeGuard());
}
return std::unique_ptr<PrepareResult>();
}
diff --git a/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp b/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp
index 7a020d33d5c..e250a19214c 100644
--- a/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp
@@ -166,11 +166,11 @@ template <class TensorType>
TensorStore::EntryRef
DenseTensorStore::setDenseTensor(const TensorType &tensor)
{
- size_t numCells = tensor.cellsRef().size;
+ size_t numCells = tensor.cells().size;
assert(numCells == getNumCells());
assert(tensor.type() == _type);
auto raw = allocRawBuffer();
- memcpy(raw.data, tensor.cellsRef().data, getBufSize());
+ memcpy(raw.data, tensor.cells().data, getBufSize());
return raw.ref;
}