diff options
Diffstat (limited to 'eval')
11 files changed, 60 insertions, 16 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: |