summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-03-17 12:40:03 +0000
committerArne Juul <arnej@verizonmedia.com>2021-03-17 12:40:03 +0000
commitf0972d5ffd90a80952ab196d0209137feae8284c (patch)
tree9be61af5027b35089e12ae50e99e87373ba408d4 /eval
parent9041c2e4664d86ba5458d21ca91f697e7d19c8a1 (diff)
rewrite DenseSimpleExpandFunction test using EvalFixture::verify<FunInfo>
Diffstat (limited to 'eval')
-rw-r--r--eval/src/tests/instruction/dense_simple_expand_function/dense_simple_expand_function_test.cpp72
1 files changed, 22 insertions, 50 deletions
diff --git a/eval/src/tests/instruction/dense_simple_expand_function/dense_simple_expand_function_test.cpp b/eval/src/tests/instruction/dense_simple_expand_function/dense_simple_expand_function_test.cpp
index e8f68e5021e..d68f8c8b412 100644
--- a/eval/src/tests/instruction/dense_simple_expand_function/dense_simple_expand_function_test.cpp
+++ b/eval/src/tests/instruction/dense_simple_expand_function/dense_simple_expand_function_test.cpp
@@ -1,6 +1,5 @@
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/eval/eval/fast_value.h>
#include <vespa/eval/eval/tensor_function.h>
#include <vespa/eval/instruction/dense_simple_expand_function.h>
#include <vespa/eval/eval/test/eval_fixture.h>
@@ -14,46 +13,25 @@ using namespace vespalib::eval::tensor_function;
using Inner = DenseSimpleExpandFunction::Inner;
-const ValueBuilderFactory &prod_factory = FastValueBuilderFactory::get();
-
-EvalFixture::ParamRepo make_params() {
- return EvalFixture::ParamRepo()
- .add("a", GenSpec(1.5))
- .add("sparse", GenSpec().map("x", {"a"}))
- .add("mixed", GenSpec().map("y", {"a"}).idx("z", 5))
- .add_variants("a5", GenSpec().idx("a", 5))
- .add_variants("b3", GenSpec().idx("b", 3))
- .add_variants("A1a5c1", GenSpec().idx("A", 1).idx("a", 5).idx("c", 1))
- .add_variants("B1b3c1", GenSpec().idx("B", 1).idx("b", 3).idx("c", 1))
- .add_variants("a5c3", GenSpec().idx("a", 5).idx("c", 3))
- .add_variants("x3y2", GenSpec().idx("x", 3).idx("y", 2))
- .add_variants("a1b1c1", GenSpec().idx("a", 1).idx("b", 1).idx("c", 1))
- .add_variants("x1y1z1", GenSpec().idx("x", 1).idx("y", 1).idx("z", 1));
-}
-
-EvalFixture::ParamRepo param_repo = make_params();
+struct FunInfo {
+ using LookFor = DenseSimpleExpandFunction;
+ Inner inner;
+ void verify(const LookFor &fun) const {
+ EXPECT_TRUE(fun.result_is_mutable());
+ EXPECT_EQ(fun.inner(), inner);
+ }
+};
void verify_optimized(const vespalib::string &expr, Inner inner) {
- EvalFixture slow_fixture(prod_factory, expr, param_repo, false);
- EvalFixture fixture(prod_factory, expr, param_repo, true, true);
- EXPECT_EQ(fixture.result(), EvalFixture::ref(expr, param_repo));
- EXPECT_EQ(fixture.result(), slow_fixture.result());
- auto info = fixture.find_all<DenseSimpleExpandFunction>();
- ASSERT_EQ(info.size(), 1u);
- EXPECT_TRUE(info[0]->result_is_mutable());
- EXPECT_EQ(info[0]->inner(), inner);
- ASSERT_EQ(fixture.num_params(), 2);
- EXPECT_TRUE(!(fixture.get_param(0) == fixture.result()));
- EXPECT_TRUE(!(fixture.get_param(1) == fixture.result()));
+ SCOPED_TRACE(expr.c_str());
+ CellTypeSpace all_types(CellTypeUtils::list_types(), 2);
+ EvalFixture::verify<FunInfo>(expr, {FunInfo{inner}}, all_types);
}
void verify_not_optimized(const vespalib::string &expr) {
- EvalFixture slow_fixture(prod_factory, expr, param_repo, false);
- EvalFixture fixture(prod_factory, expr, param_repo, true);
- EXPECT_EQ(fixture.result(), EvalFixture::ref(expr, param_repo));
- EXPECT_EQ(fixture.result(), slow_fixture.result());
- auto info = fixture.find_all<DenseSimpleExpandFunction>();
- EXPECT_TRUE(info.empty());
+ SCOPED_TRACE(expr.c_str());
+ CellTypeSpace just_double({CellType::DOUBLE}, 2);
+ EvalFixture::verify<FunInfo>(expr, {}, just_double);
}
TEST(ExpandTest, simple_expand_is_optimized) {
@@ -80,19 +58,13 @@ TEST(ExpandTest, simple_expand_handles_asymmetric_operations_correctly) {
verify_optimized("join(b3,a5,f(x,y)(x/y))", Inner::LHS);
}
-TEST(ExpandTest, simple_expand_can_have_various_cell_types) {
- verify_optimized("join(a5,b3_f,f(x,y)(x*y))", Inner::RHS);
- verify_optimized("join(a5_f,b3,f(x,y)(x*y))", Inner::RHS);
- verify_optimized("join(a5_f,b3_f,f(x,y)(x*y))", Inner::RHS);
- verify_optimized("join(b3,a5_f,f(x,y)(x*y))", Inner::LHS);
- verify_optimized("join(b3_f,a5,f(x,y)(x*y))", Inner::LHS);
- verify_optimized("join(b3_f,a5_f,f(x,y)(x*y))", Inner::LHS);
-}
-
+#if 0
+// XXX no way to really verify this now
TEST(ExpandTest, simple_expand_is_never_inplace) {
verify_optimized("join(@a5,@b3,f(x,y)(x*y))", Inner::RHS);
verify_optimized("join(@b3,@a5,f(x,y)(x*y))", Inner::LHS);
}
+#endif
TEST(ExpandTest, interleaved_dimensions_are_not_optimized) {
verify_not_optimized("join(a5c3,b3,f(x,y)(x*y))");
@@ -105,7 +77,7 @@ TEST(ExpandTest, matching_dimensions_are_not_expanding) {
}
TEST(ExpandTest, scalar_is_not_expanding) {
- verify_not_optimized("join(a5,a,f(x,y)(x*y))");
+ verify_not_optimized("join(a5,@$1,f(x,y)(x*y))");
}
TEST(ExpandTest, unit_tensor_is_not_expanding) {
@@ -115,13 +87,13 @@ TEST(ExpandTest, unit_tensor_is_not_expanding) {
}
TEST(ExpandTest, sparse_expand_is_not_optimized) {
- verify_not_optimized("join(a5,sparse,f(x,y)(x*y))");
- verify_not_optimized("join(sparse,a5,f(x,y)(x*y))");
+ verify_not_optimized("join(a5,x1_1,f(x,y)(x*y))");
+ verify_not_optimized("join(x1_1,a5,f(x,y)(x*y))");
}
TEST(ExpandTest, mixed_expand_is_not_optimized) {
- verify_not_optimized("join(a5,mixed,f(x,y)(x*y))");
- verify_not_optimized("join(mixed,a5,f(x,y)(x*y))");
+ verify_not_optimized("join(a5,y1_1z2,f(x,y)(x*y))");
+ verify_not_optimized("join(y1_1z2,a5,f(x,y)(x*y))");
}
GTEST_MAIN_RUN_ALL_TESTS()