From 33b21d16da3230ed1bbf6b1aa39e56594b1bf095 Mon Sep 17 00:00:00 2001 From: Geir Storli Date: Fri, 8 Feb 2019 12:18:02 +0000 Subject: Rename unit test tensor_modify -> tensor_modify_operation. --- eval/src/tests/tensor/tensor_modify/CMakeLists.txt | 8 -- .../tensor/tensor_modify/tensor_modify_test.cpp | 92 ---------------------- .../tensor/tensor_modify_operation/CMakeLists.txt | 8 ++ .../tensor_modify_operation_test.cpp | 92 ++++++++++++++++++++++ 4 files changed, 100 insertions(+), 100 deletions(-) delete mode 100644 eval/src/tests/tensor/tensor_modify/CMakeLists.txt delete mode 100644 eval/src/tests/tensor/tensor_modify/tensor_modify_test.cpp create mode 100644 eval/src/tests/tensor/tensor_modify_operation/CMakeLists.txt create mode 100644 eval/src/tests/tensor/tensor_modify_operation/tensor_modify_operation_test.cpp (limited to 'eval/src') diff --git a/eval/src/tests/tensor/tensor_modify/CMakeLists.txt b/eval/src/tests/tensor/tensor_modify/CMakeLists.txt deleted file mode 100644 index 2d4055db7e2..00000000000 --- a/eval/src/tests/tensor/tensor_modify/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# 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_modify_test_app TEST - SOURCES - tensor_modify_test.cpp - DEPENDS - vespaeval -) -vespa_add_test(NAME eval_tensor_modify_test_app COMMAND eval_tensor_modify_test_app) diff --git a/eval/src/tests/tensor/tensor_modify/tensor_modify_test.cpp b/eval/src/tests/tensor/tensor_modify/tensor_modify_test.cpp deleted file mode 100644 index c3c817d28c4..00000000000 --- a/eval/src/tests/tensor/tensor_modify/tensor_modify_test.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// 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 namespace vespalib::tensor; - -namespace { - -double -replace(double, double b) -{ - return b; -} - -template -const Tensor *asTensor(Value &value) -{ - auto *tensor = dynamic_cast(value.as_tensor()); - ASSERT_TRUE(tensor); - return tensor; -} - -} - -void checkUpdate(const TensorSpec &source, const TensorSpec &update, const TensorSpec &expect) { - auto sourceValue = DefaultTensorEngine::ref().from_spec(source); - auto sourceTensor = asTensor(*sourceValue); - auto updateValue = DefaultTensorEngine::ref().from_spec(update); - auto updateTensor = asTensor(*updateValue); - const CellValues cellValues(*updateTensor); - auto actualTensor = sourceTensor->modify(replace, cellValues); - auto actual = actualTensor->toSpec(); - auto expectValue = DefaultTensorEngine::ref().from_spec(expect); - auto expectTensor = asTensor(*expectValue); - auto expectPadded = expectTensor->toSpec(); - EXPECT_EQUAL(actual, expectPadded); -} - -TEST("require that sparse tensors can be modified") { - checkUpdate(TensorSpec("tensor(x{},y{})") - .add({{"x","8"},{"y","9"}}, 11) - .add({{"x","9"},{"y","9"}}, 11), - TensorSpec("tensor(x{},y{})") - .add({{"x","8"},{"y","9"}}, 2), - TensorSpec("tensor(x{},y{})") - .add({{"x","8"},{"y","9"}}, 2) - .add({{"x","9"},{"y","9"}}, 11)); -} - -TEST("require that dense tensors can be modified") { - checkUpdate(TensorSpec("tensor(x[10],y[10])") - .add({{"x",8},{"y",9}}, 11) - .add({{"x",9},{"y",9}}, 11), - TensorSpec("tensor(x{},y{})") - .add({{"x","8"},{"y","9"}}, 2), - TensorSpec("tensor(x[10],y[10])") - .add({{"x",8},{"y",9}}, 2) - .add({{"x",9},{"y",9}}, 11)); -} - -TEST("require that sparse tensors ignore updates to missing cells") { - checkUpdate(TensorSpec("tensor(x{},y{})") - .add({{"x","8"},{"y","9"}}, 11) - .add({{"x","9"},{"y","9"}}, 11), - TensorSpec("tensor(x{},y{})") - .add({{"x","7"},{"y","9"}}, 2) - .add({{"x","8"},{"y","9"}}, 2), - TensorSpec("tensor(x{},y{})") - .add({{"x","8"},{"y","9"}}, 2) - .add({{"x","9"},{"y","9"}}, 11)); -} - -TEST("require that dense tensors ignore updates to out of range cells") { - checkUpdate(TensorSpec("tensor(x[10],y[10])") - .add({{"x",8},{"y",9}}, 11) - .add({{"x",9},{"y",9}}, 11), - TensorSpec("tensor(x{},y{})") - .add({{"x","8"},{"y","9"}}, 2) - .add({{"x","10"},{"y","9"}}, 2), - TensorSpec("tensor(x[10],y[10])") - .add({{"x",8},{"y",9}}, 2) - .add({{"x",9},{"y",9}}, 11)); -} - -TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/eval/src/tests/tensor/tensor_modify_operation/CMakeLists.txt b/eval/src/tests/tensor/tensor_modify_operation/CMakeLists.txt new file mode 100644 index 00000000000..b0ffa48eb3b --- /dev/null +++ b/eval/src/tests/tensor/tensor_modify_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_modify_operation_test_app TEST + SOURCES + tensor_modify_operation_test.cpp + DEPENDS + vespaeval +) +vespa_add_test(NAME eval_tensor_modify_operation_test_app COMMAND eval_tensor_modify_operation_test_app) diff --git a/eval/src/tests/tensor/tensor_modify_operation/tensor_modify_operation_test.cpp b/eval/src/tests/tensor/tensor_modify_operation/tensor_modify_operation_test.cpp new file mode 100644 index 00000000000..c3c817d28c4 --- /dev/null +++ b/eval/src/tests/tensor/tensor_modify_operation/tensor_modify_operation_test.cpp @@ -0,0 +1,92 @@ +// 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 namespace vespalib::tensor; + +namespace { + +double +replace(double, double b) +{ + return b; +} + +template +const Tensor *asTensor(Value &value) +{ + auto *tensor = dynamic_cast(value.as_tensor()); + ASSERT_TRUE(tensor); + return tensor; +} + +} + +void checkUpdate(const TensorSpec &source, const TensorSpec &update, const TensorSpec &expect) { + auto sourceValue = DefaultTensorEngine::ref().from_spec(source); + auto sourceTensor = asTensor(*sourceValue); + auto updateValue = DefaultTensorEngine::ref().from_spec(update); + auto updateTensor = asTensor(*updateValue); + const CellValues cellValues(*updateTensor); + auto actualTensor = sourceTensor->modify(replace, cellValues); + auto actual = actualTensor->toSpec(); + auto expectValue = DefaultTensorEngine::ref().from_spec(expect); + auto expectTensor = asTensor(*expectValue); + auto expectPadded = expectTensor->toSpec(); + EXPECT_EQUAL(actual, expectPadded); +} + +TEST("require that sparse tensors can be modified") { + checkUpdate(TensorSpec("tensor(x{},y{})") + .add({{"x","8"},{"y","9"}}, 11) + .add({{"x","9"},{"y","9"}}, 11), + TensorSpec("tensor(x{},y{})") + .add({{"x","8"},{"y","9"}}, 2), + TensorSpec("tensor(x{},y{})") + .add({{"x","8"},{"y","9"}}, 2) + .add({{"x","9"},{"y","9"}}, 11)); +} + +TEST("require that dense tensors can be modified") { + checkUpdate(TensorSpec("tensor(x[10],y[10])") + .add({{"x",8},{"y",9}}, 11) + .add({{"x",9},{"y",9}}, 11), + TensorSpec("tensor(x{},y{})") + .add({{"x","8"},{"y","9"}}, 2), + TensorSpec("tensor(x[10],y[10])") + .add({{"x",8},{"y",9}}, 2) + .add({{"x",9},{"y",9}}, 11)); +} + +TEST("require that sparse tensors ignore updates to missing cells") { + checkUpdate(TensorSpec("tensor(x{},y{})") + .add({{"x","8"},{"y","9"}}, 11) + .add({{"x","9"},{"y","9"}}, 11), + TensorSpec("tensor(x{},y{})") + .add({{"x","7"},{"y","9"}}, 2) + .add({{"x","8"},{"y","9"}}, 2), + TensorSpec("tensor(x{},y{})") + .add({{"x","8"},{"y","9"}}, 2) + .add({{"x","9"},{"y","9"}}, 11)); +} + +TEST("require that dense tensors ignore updates to out of range cells") { + checkUpdate(TensorSpec("tensor(x[10],y[10])") + .add({{"x",8},{"y",9}}, 11) + .add({{"x",9},{"y",9}}, 11), + TensorSpec("tensor(x{},y{})") + .add({{"x","8"},{"y","9"}}, 2) + .add({{"x","10"},{"y","9"}}, 2), + TensorSpec("tensor(x[10],y[10])") + .add({{"x",8},{"y",9}}, 2) + .add({{"x",9},{"y",9}}, 11)); +} + +TEST_MAIN() { TEST_RUN_ALL(); } -- cgit v1.2.3