aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval/CMakeLists.txt1
-rw-r--r--eval/src/tests/tensor/default_value_builder_factory/CMakeLists.txt9
-rw-r--r--eval/src/tests/tensor/default_value_builder_factory/default_value_builder_factory_test.cpp61
-rw-r--r--eval/src/vespa/eval/tensor/sparse/sparse_tensor_value.cpp14
-rw-r--r--eval/src/vespa/eval/tensor/sparse/sparse_tensor_value.h8
-rw-r--r--eval/src/vespa/eval/tensor/sparse/sparse_tensor_value_builder.cpp8
6 files changed, 84 insertions, 17 deletions
diff --git a/eval/CMakeLists.txt b/eval/CMakeLists.txt
index 33bd098975a..03a19b8c2c4 100644
--- a/eval/CMakeLists.txt
+++ b/eval/CMakeLists.txt
@@ -34,6 +34,7 @@ vespa_define_module(
src/tests/gp/ponder_nov2017
src/tests/instruction/generic_join
src/tests/instruction/generic_rename
+ src/tests/tensor/default_value_builder_factory
src/tests/tensor/dense_add_dimension_optimizer
src/tests/tensor/dense_dimension_combiner
src/tests/tensor/dense_dot_product_function
diff --git a/eval/src/tests/tensor/default_value_builder_factory/CMakeLists.txt b/eval/src/tests/tensor/default_value_builder_factory/CMakeLists.txt
new file mode 100644
index 00000000000..cd7f552ec28
--- /dev/null
+++ b/eval/src/tests/tensor/default_value_builder_factory/CMakeLists.txt
@@ -0,0 +1,9 @@
+# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(eval_default_value_builder_factory_test_app TEST
+ SOURCES
+ default_value_builder_factory_test.cpp
+ DEPENDS
+ vespaeval
+ GTest::GTest
+)
+vespa_add_test(NAME eval_default_value_builder_factory_test_app COMMAND eval_default_value_builder_factory_test_app )
diff --git a/eval/src/tests/tensor/default_value_builder_factory/default_value_builder_factory_test.cpp b/eval/src/tests/tensor/default_value_builder_factory/default_value_builder_factory_test.cpp
new file mode 100644
index 00000000000..5663dda592f
--- /dev/null
+++ b/eval/src/tests/tensor/default_value_builder_factory/default_value_builder_factory_test.cpp
@@ -0,0 +1,61 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/eval/eval/value.h>
+#include <vespa/eval/eval/value_codec.h>
+#include <vespa/eval/eval/tensor_spec.h>
+#include <vespa/eval/tensor/default_value_builder_factory.h>
+#include <vespa/eval/tensor/mixed/packed_mixed_tensor.h>
+#include <vespa/eval/tensor/sparse/sparse_tensor_value.h>
+#include <vespa/eval/tensor/dense/dense_tensor.h>
+#include <vespa/vespalib/gtest/gtest.h>
+
+using namespace vespalib;
+using namespace vespalib::eval;
+using namespace vespalib::tensor;
+using namespace vespalib::eval::packed_mixed_tensor;
+
+Value::UP v_of(const TensorSpec &spec) {
+ return value_from_spec(spec, DefaultValueBuilderFactory::get());
+}
+
+TEST(MakeInputTest, print_some_test_input) {
+ auto dbl = v_of(TensorSpec("double").add({}, 3.0));
+ auto trivial = v_of(TensorSpec("tensor(x[1])").add({{"x",0}}, 7.0));
+ auto dense = v_of(TensorSpec("tensor<float>(x[2],y[3])").add({{"x",1},{"y",2}}, 17.0));
+ auto sparse = v_of(TensorSpec("tensor(x{},y{})").add({{"x","foo"},{"y","bar"}}, 31.0));
+ auto mixed = v_of(TensorSpec("tensor<float>(x[2],y{})").add({{"x",1},{"y","quux"}}, 42.0));
+
+ EXPECT_TRUE(dynamic_cast<DoubleValue *>(dbl.get()));
+ EXPECT_TRUE(dynamic_cast<DenseTensorView *>(trivial.get()));
+ EXPECT_TRUE(dynamic_cast<DenseTensorView *>(dense.get()));
+ EXPECT_TRUE(dynamic_cast<SparseTensorValue *>(sparse.get()));
+ EXPECT_TRUE(dynamic_cast<PackedMixedTensor *>(mixed.get()));
+
+ EXPECT_EQ(dbl->as_double(), 3.0);
+ EXPECT_EQ(trivial->cells().typify<double>()[0], 7.0);
+ EXPECT_EQ(dense->cells().typify<float>()[5], 17.0);
+ EXPECT_EQ(sparse->cells().typify<double>()[0], 31.0);
+ EXPECT_EQ(mixed->cells().typify<float>()[1], 42.0);
+
+ stringref y_look = "bar";
+ stringref x_res = "xxx";
+ auto view = sparse->index().create_view({1});
+ view->lookup({&y_look});
+ size_t ss = 12345;
+ bool br = view->next_result({&x_res}, ss);
+ EXPECT_TRUE(br);
+ EXPECT_EQ(ss, 0);
+ EXPECT_EQ(x_res, "foo");
+ br = view->next_result({&x_res}, ss);
+ EXPECT_FALSE(br);
+
+ ss = 12345;
+ view = mixed->index().create_view({});
+ view->lookup({});
+ br = view->next_result({&x_res}, ss);
+ EXPECT_TRUE(br);
+ EXPECT_EQ(ss, 0);
+ EXPECT_EQ(x_res, "quux");
+}
+
+GTEST_MAIN_RUN_ALL_TESTS()
diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_value.cpp b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_value.cpp
index ba9c78aeb7b..89cfb89ae8e 100644
--- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_value.cpp
+++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_value.cpp
@@ -216,29 +216,25 @@ SparseTensorValueIndex::create_view(const std::vector<size_t> &dims) const
//-----------------------------------------------------------------------------
template<typename T>
-SparseTensorValue<T>::SparseTensorValue(const eval::ValueType &type_in, const SparseTensorValueIndex &index_in, ConstArrayRef<T> cells_in)
+SparseTensorValue::SparseTensorValue(const eval::ValueType &type_in, const SparseTensorValueIndex &index_in, ConstArrayRef<T> cells_in)
: _type(type_in),
_index(index_in.num_mapped_dims),
_cells(),
_stash(needed_memory_for(index_in.map, cells_in))
{
copyMap(_index.map, index_in.map, _stash);
- _cells = _stash.copy_array<T>(cells_in);
+ _cells = TypedCells(_stash.copy_array<T>(cells_in));
}
-template<typename T>
-SparseTensorValue<T>::SparseTensorValue(eval::ValueType &&type_in, SparseTensorValueIndex &&index_in, ConstArrayRef<T> &&cells_in, Stash &&stash_in)
+SparseTensorValue::SparseTensorValue(eval::ValueType &&type_in, SparseTensorValueIndex &&index_in, TypedCells cells_in, Stash &&stash_in)
: _type(std::move(type_in)),
_index(std::move(index_in)),
- _cells(std::move(cells_in)),
+ _cells(cells_in),
_stash(std::move(stash_in))
{
}
-template<typename T> SparseTensorValue<T>::~SparseTensorValue() = default;
-
-template class SparseTensorValue<float>;
-template class SparseTensorValue<double>;
+SparseTensorValue::~SparseTensorValue() = default;
//-----------------------------------------------------------------------------
diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_value.h b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_value.h
index ad916021bbc..a565d6edc1f 100644
--- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_value.h
+++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_value.h
@@ -29,22 +29,22 @@ struct SparseTensorValueIndex : public vespalib::eval::Value::Index
* improve CPU cache and TLB hit ratio, relative to SimpleTensor
* implementation.
*/
-template<typename T>
class SparseTensorValue : public vespalib::eval::Value
{
private:
eval::ValueType _type;
SparseTensorValueIndex _index;
- ConstArrayRef<T> _cells;
+ TypedCells _cells;
Stash _stash;
public:
+ template<typename T>
SparseTensorValue(const eval::ValueType &type_in, const SparseTensorValueIndex &index_in, ConstArrayRef<T> cells_in);
- SparseTensorValue(eval::ValueType &&type_in, SparseTensorValueIndex &&index_in, ConstArrayRef<T> &&cells_in, Stash &&stash_in);
+ SparseTensorValue(eval::ValueType &&type_in, SparseTensorValueIndex &&index_in, TypedCells cells_in, Stash &&stash_in);
~SparseTensorValue() override;
- TypedCells cells() const override { return TypedCells(_cells); }
+ TypedCells cells() const override { return _cells; }
const Index &index() const override { return _index; }
diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_value_builder.cpp b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_value_builder.cpp
index 7a670ab8f85..ca51e101a89 100644
--- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor_value_builder.cpp
+++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor_value_builder.cpp
@@ -28,10 +28,10 @@ SparseTensorValueBuilder<T>::build(std::unique_ptr<eval::ValueBuilder<T>>)
// copy cells to stash:
ConstArrayRef<T> tmp_cells = _cells;
ConstArrayRef<T> cells_copy = _stash.copy_array<T>(tmp_cells);
- return std::make_unique<SparseTensorValue<T>>(std::move(_type),
- std::move(_index),
- std::move(cells_copy),
- std::move(_stash));
+ return std::make_unique<SparseTensorValue>(std::move(_type),
+ std::move(_index),
+ TypedCells(cells_copy),
+ std::move(_stash));
}
template class SparseTensorValueBuilder<float>;