diff options
Diffstat (limited to 'eval/src/tests/tensor')
4 files changed, 0 insertions, 125 deletions
diff --git a/eval/src/tests/tensor/sparse_tensor_builder/.gitignore b/eval/src/tests/tensor/sparse_tensor_builder/.gitignore deleted file mode 100644 index e0316d190bb..00000000000 --- a/eval/src/tests/tensor/sparse_tensor_builder/.gitignore +++ /dev/null @@ -1 +0,0 @@ -vespalib_sparse_tensor_builder_test_app diff --git a/eval/src/tests/tensor/sparse_tensor_builder/CMakeLists.txt b/eval/src/tests/tensor/sparse_tensor_builder/CMakeLists.txt deleted file mode 100644 index 2132a37f9fa..00000000000 --- a/eval/src/tests/tensor/sparse_tensor_builder/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(eval_sparse_tensor_builder_test_app TEST - SOURCES - sparse_tensor_builder_test.cpp - DEPENDS - vespaeval -) -vespa_add_test(NAME eval_sparse_tensor_builder_test_app COMMAND eval_sparse_tensor_builder_test_app) diff --git a/eval/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp b/eval/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp deleted file mode 100644 index 708c2f761f7..00000000000 --- a/eval/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/vespalib/testkit/test_kit.h> -#include <vespa/eval/tensor/sparse/sparse_tensor_builder.h> -#include <vespa/eval/tensor/sparse/sparse_tensor_address_combiner.h> -#include <vespa/vespalib/test/insertion_operators.h> - -using namespace vespalib::tensor; -using namespace vespalib::tensor::sparse; -using vespalib::eval::TensorSpec; -using vespalib::eval::ValueType; - -void -assertCellValue(double expValue, const TensorAddress &address, - const ValueType &type, - const SparseTensor::Cells &cells) -{ - SparseTensorAddressBuilder addressBuilder; - auto dimsItr = type.dimensions().cbegin(); - auto dimsItrEnd = type.dimensions().cend(); - for (const auto &element : address.elements()) { - while ((dimsItr < dimsItrEnd) && (dimsItr->name < element.dimension())) { - addressBuilder.add(""); - ++dimsItr; - } - assert((dimsItr != dimsItrEnd) && (dimsItr->name == element.dimension())); - addressBuilder.add(element.label()); - ++dimsItr; - } - while (dimsItr < dimsItrEnd) { - addressBuilder.add(""); - ++dimsItr; - } - SparseTensorAddressRef addressRef(addressBuilder.getAddressRef()); - auto itr = cells.find(addressRef); - EXPECT_FALSE(itr == cells.end()); - EXPECT_EQUAL(expValue, itr->second); -} - -Tensor::UP -buildTensor() -{ - SparseTensorBuilder builder; - builder.define_dimension("c"); - builder.define_dimension("d"); - builder.define_dimension("a"); - builder.define_dimension("b"); - builder.add_label(builder.define_dimension("a"), "1"). - add_label(builder.define_dimension("b"), "2").add_cell(10). - add_label(builder.define_dimension("c"), "3"). - add_label(builder.define_dimension("d"), "4").add_cell(20); - return builder.build(); -} - -TEST("require that tensor can be constructed") -{ - Tensor::UP tensor = buildTensor(); - const SparseTensor &sparseTensor = dynamic_cast<const SparseTensor &>(*tensor); - const ValueType &type = sparseTensor.type(); - const SparseTensor::Cells &cells = sparseTensor.cells(); - EXPECT_EQUAL(2u, cells.size()); - assertCellValue(10, TensorAddress({{"a","1"},{"b","2"}}), type, cells); - assertCellValue(20, TensorAddress({{"c","3"},{"d","4"}}), type, cells); -} - -TEST("require that tensor can be converted to tensor spec") -{ - Tensor::UP tensor = buildTensor(); - TensorSpec expSpec("tensor(a{},b{},c{},d{})"); - expSpec.add({{"a", "1"}, {"b", "2"}, {"c", ""}, {"d", ""}}, 10). - add({{"a", ""},{"b",""},{"c", "3"}, {"d", "4"}}, 20); - TensorSpec actSpec = tensor->toSpec(); - EXPECT_EQUAL(expSpec, actSpec); -} - -TEST("require that dimensions are extracted") -{ - SparseTensorBuilder builder; - builder.define_dimension("c"); - builder.define_dimension("a"); - builder.define_dimension("b"); - builder. - add_label(builder.define_dimension("a"), "1"). - add_label(builder.define_dimension("b"), "2").add_cell(10). - add_label(builder.define_dimension("b"), "3"). - add_label(builder.define_dimension("c"), "4").add_cell(20); - Tensor::UP tensor = builder.build(); - const SparseTensor &sparseTensor = dynamic_cast<const SparseTensor &>(*tensor); - const auto &dims = sparseTensor.type().dimensions(); - EXPECT_EQUAL(3u, dims.size()); - EXPECT_EQUAL("a", dims[0].name); - EXPECT_EQUAL("b", dims[1].name); - EXPECT_EQUAL("c", dims[2].name); - EXPECT_EQUAL("tensor(a{},b{},c{})", sparseTensor.type().to_spec()); -} - -void verifyAddressCombiner(const ValueType & a, const ValueType & b, size_t numDim, size_t numOverlapping) { - TensorAddressCombiner combiner(a, b); - EXPECT_EQUAL(numDim, combiner.numDimensions()); - EXPECT_EQUAL(numOverlapping, combiner.numOverlappingDimensions()); -} -TEST("Test sparse tensor address combiner") { - verifyAddressCombiner(ValueType::tensor_type({{"a"}}), ValueType::tensor_type({{"b"}}), 2, 0); - verifyAddressCombiner(ValueType::tensor_type({{"a"}, {"b"}}), ValueType::tensor_type({{"b"}}), 2, 1); - verifyAddressCombiner(ValueType::tensor_type({{"a"}, {"b"}}), ValueType::tensor_type({{"b"}, {"c"}}), 3, 1); - -} - -TEST("Test essential object sizes") { - EXPECT_EQUAL(16u, sizeof(SparseTensorAddressRef)); - EXPECT_EQUAL(24u, sizeof(std::pair<SparseTensorAddressRef, double>)); - EXPECT_EQUAL(32u, sizeof(vespalib::hash_node<std::pair<SparseTensorAddressRef, double>>)); -} - -TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/eval/src/tests/tensor/tensor_serialization/tensor_serialization_test.cpp b/eval/src/tests/tensor/tensor_serialization/tensor_serialization_test.cpp index 2c113e814e9..b43a127bc60 100644 --- a/eval/src/tests/tensor/tensor_serialization/tensor_serialization_test.cpp +++ b/eval/src/tests/tensor/tensor_serialization/tensor_serialization_test.cpp @@ -2,7 +2,6 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/eval/tensor/sparse/sparse_tensor.h> -#include <vespa/eval/tensor/sparse/sparse_tensor_builder.h> #include <vespa/eval/tensor/types.h> #include <vespa/eval/tensor/default_tensor_engine.h> #include <vespa/eval/tensor/serialization/typed_binary_format.h> |