diff options
author | Arne H Juul <arnej27959@users.noreply.github.com> | 2020-12-09 20:21:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-09 20:21:04 +0100 |
commit | 80db966fd7477f1267613f469ff70787af95b54e (patch) | |
tree | bdb878f82fecdbd8c004204c3ca60fbd57ba2af5 /eval/src/tests/instruction/dense_tensor_create_function/dense_tensor_create_function_test.cpp | |
parent | f3e2acd0df995ea17ddf016719d0f2ef33ef1427 (diff) | |
parent | b66792587ac1c7164700db323dd7f2483062bbbd (diff) |
Merge pull request #15764 from vespa-engine/arnej/move-dense-optimizers
Arnej/move dense optimizers
Diffstat (limited to 'eval/src/tests/instruction/dense_tensor_create_function/dense_tensor_create_function_test.cpp')
-rw-r--r-- | eval/src/tests/instruction/dense_tensor_create_function/dense_tensor_create_function_test.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/eval/src/tests/instruction/dense_tensor_create_function/dense_tensor_create_function_test.cpp b/eval/src/tests/instruction/dense_tensor_create_function/dense_tensor_create_function_test.cpp new file mode 100644 index 00000000000..25bbe5b422c --- /dev/null +++ b/eval/src/tests/instruction/dense_tensor_create_function/dense_tensor_create_function_test.cpp @@ -0,0 +1,59 @@ +// Copyright 2019 Oath Inc. 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/eval/tensor_function.h> +#include <vespa/eval/instruction/dense_tensor_create_function.h> +#include <vespa/eval/eval/test/tensor_model.hpp> +#include <vespa/eval/eval/test/eval_fixture.h> + +#include <vespa/vespalib/util/stringfmt.h> +#include <vespa/vespalib/util/stash.h> + +using namespace vespalib; +using namespace vespalib::eval; +using namespace vespalib::eval::test; +using namespace vespalib::eval::tensor_function; + +const ValueBuilderFactory &prod_factory = FastValueBuilderFactory::get(); + +EvalFixture::ParamRepo make_params() { + return EvalFixture::ParamRepo() + .add("a", spec(1.0)) + .add("b", spec(2.0)) + .add("c", spec(3.0)); +} +EvalFixture::ParamRepo param_repo = make_params(); + +void verify(const vespalib::string &expr, size_t expect_optimized_cnt, size_t expect_not_optimized_cnt) { + EvalFixture fixture(prod_factory, expr, param_repo, true); + EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo)); + auto info = fixture.find_all<DenseTensorCreateFunction>(); + EXPECT_EQUAL(info.size(), expect_optimized_cnt); + for (size_t i = 0; i < info.size(); ++i) { + EXPECT_TRUE(info[i]->result_is_mutable()); + } + EXPECT_EQUAL(fixture.find_all<Create>().size(), expect_not_optimized_cnt); +} + +//----------------------------------------------------------------------------- + +TEST("require that tensor create can be optimized") { + TEST_DO(verify("tensor(x[3]):{{x:0}:1,{x:1}:2,{x:2}:3}", 0, 0)); // NB: const value + TEST_DO(verify("tensor(x[3]):{{x:0}:a,{x:1}:b,{x:2}:c}", 1, 0)); + TEST_DO(verify("tensor<float>(x[3]):{{x:0}:a,{x:1}:b,{x:2}:c}", 1, 0)); + TEST_DO(verify("tensor(x[3]):{{x:0}:a+b,{x:1}:b-c,{x:2}:c*a}", 1, 0)); +} + +TEST("require that tensor create can be optimized with missing cells (padded with 0.0)") { + TEST_DO(verify("tensor(x[3],y[5]):{{x:0,y:1}:a,{x:1,y:3}:b,{x:2,y:4}:c}", 1, 0)); +} + +TEST("require that tensor create in not optimized for sparse tensor") { + TEST_DO(verify("tensor(x{}):{{x:0}:a,{x:1}:b,{x:2}:c}", 0, 1)); +} + +TEST("require that tensor create in not optimized for mixed tensor") { + TEST_DO(verify("tensor(x{},y[3]):{{x:a,y:0}:a,{x:a,y:1}:b,{x:a,y:2}:c}", 0, 1)); +} + +TEST_MAIN() { TEST_RUN_ALL(); } |