From c6e92173cf30de539ef1afa4f62585efaa4b9050 Mon Sep 17 00:00:00 2001 From: Geir Storli Date: Wed, 20 Feb 2019 14:19:27 +0000 Subject: Implement remove operation for sparse tensor. --- .../tensor/tensor_remove_operation/CMakeLists.txt | 8 ++++ .../tensor_remove_operation_test.cpp | 46 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 eval/src/tests/tensor/tensor_remove_operation/CMakeLists.txt create mode 100644 eval/src/tests/tensor/tensor_remove_operation/tensor_remove_operation_test.cpp (limited to 'eval/src/tests') diff --git a/eval/src/tests/tensor/tensor_remove_operation/CMakeLists.txt b/eval/src/tests/tensor/tensor_remove_operation/CMakeLists.txt new file mode 100644 index 00000000000..8dfb8181f2b --- /dev/null +++ b/eval/src/tests/tensor/tensor_remove_operation/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(eval_tensor_remove_operation_test_app TEST + SOURCES + tensor_remove_operation_test.cpp + DEPENDS + vespaeval +) +vespa_add_test(NAME eval_tensor_remove_operation_test_app COMMAND eval_tensor_remove_operation_test_app) diff --git a/eval/src/tests/tensor/tensor_remove_operation/tensor_remove_operation_test.cpp b/eval/src/tests/tensor/tensor_remove_operation/tensor_remove_operation_test.cpp new file mode 100644 index 00000000000..8b0c44a6e06 --- /dev/null +++ b/eval/src/tests/tensor/tensor_remove_operation/tensor_remove_operation_test.cpp @@ -0,0 +1,46 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include +#include +#include +#include +#include +#include + +using vespalib::eval::Value; +using vespalib::eval::TensorSpec; +using vespalib::tensor::test::makeTensor; +using namespace vespalib::tensor; + +void +assertRemove(const TensorSpec &source, const TensorSpec &arg, const TensorSpec &expected) +{ + auto sourceTensor = makeTensor(source); + auto argTensor = makeTensor(arg); + auto resultTensor = sourceTensor->remove(CellValues(*argTensor)); + auto actual = resultTensor->toSpec(); + EXPECT_EQUAL(actual, expected); +} + +TEST("require that cells can be removed from a sparse tensor") +{ + assertRemove(TensorSpec("tensor(x{},y{})") + .add({{"x","a"},{"y","b"}}, 2) + .add({{"x","c"},{"y","d"}}, 3), + TensorSpec("tensor(x{},y{})") + .add({{"x","c"},{"y","d"}}, 1) + .add({{"x","e"},{"y","f"}}, 1), + TensorSpec("tensor(x{},y{})") + .add({{"x","a"},{"y","b"}}, 2)); +} + +TEST("require that all cells can be removed from a sparse tensor") +{ + assertRemove(TensorSpec("tensor(x{},y{})") + .add({{"x","a"},{"y","b"}}, 2), + TensorSpec("tensor(x{},y{})") + .add({{"x","a"},{"y","b"}}, 1), + TensorSpec("tensor(x{},y{})")); +} + +TEST_MAIN() { TEST_RUN_ALL(); } -- cgit v1.2.3