diff options
author | Håvard Pettersen <havardpe@oath.com> | 2021-03-12 14:50:34 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@oath.com> | 2021-03-12 15:31:55 +0000 |
commit | b50d4ecd6eaac1254f5853139e741da7439627a9 (patch) | |
tree | a7037a7d716ce9ccc75668dfc80b122877c59dc5 /eval/src/tests | |
parent | 5fc288ac15612f400879f7278d588541fe8257a4 (diff) |
revisit dense_single_reduce_function with test
goal: support/test more cell types and simplify test
Diffstat (limited to 'eval/src/tests')
-rw-r--r-- | eval/src/tests/eval/gen_spec/gen_spec_test.cpp | 8 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_single_reduce_function/dense_single_reduce_function_test.cpp | 109 |
2 files changed, 55 insertions, 62 deletions
diff --git a/eval/src/tests/eval/gen_spec/gen_spec_test.cpp b/eval/src/tests/eval/gen_spec/gen_spec_test.cpp index 30ef42d7ebb..304eac1eb09 100644 --- a/eval/src/tests/eval/gen_spec/gen_spec_test.cpp +++ b/eval/src/tests/eval/gen_spec/gen_spec_test.cpp @@ -237,10 +237,10 @@ TEST(GenSpecTest, gen_spec_can_be_implicitly_converted_to_tensor_spec) { //----------------------------------------------------------------------------- TEST(GenSpecFromDescTest, dim_spec_and_gen_spec_can_be_created_from_desc) { - // 'a2b3#7c5#' - auto expect = GenSpec().idx("a", 2).map("b", 3, 7).map("c", 5).gen(); - auto dim_desc = GenSpec().desc("a2").desc("b3#7").desc("c5#").gen(); - auto gen_desc = GenSpec::from_desc("a2b3#7c5#").gen(); + // 'a2b3_7' + auto expect = GenSpec().idx("a", 2).map("b", 3, 7).gen(); + auto dim_desc = GenSpec().desc("a2").desc("b3_7").gen(); + auto gen_desc = GenSpec::from_desc("a2b3_7").gen(); EXPECT_EQ(dim_desc, expect); EXPECT_EQ(gen_desc, expect); } diff --git a/eval/src/tests/instruction/dense_single_reduce_function/dense_single_reduce_function_test.cpp b/eval/src/tests/instruction/dense_single_reduce_function/dense_single_reduce_function_test.cpp index a2733b1f7cb..c26f46f5e11 100644 --- a/eval/src/tests/instruction/dense_single_reduce_function/dense_single_reduce_function_test.cpp +++ b/eval/src/tests/instruction/dense_single_reduce_function/dense_single_reduce_function_test.cpp @@ -14,23 +14,10 @@ using namespace vespalib; using namespace vespalib::eval; using namespace vespalib::eval::test; using namespace vespalib::eval::tensor_function; +using vespalib::make_string_short::fmt; const ValueBuilderFactory &prod_factory = FastValueBuilderFactory::get(); -EvalFixture::ParamRepo make_params() { - return EvalFixture::ParamRepo() - .add_variants("a2b3c4d5", GenSpec().idx("a", 2).idx("b", 3).idx("c", 4).idx("d", 5)) - .add_variants("a9b9c9d9", GenSpec().idx("a", 9).idx("b", 9).idx("c", 9).idx("d", 9)) - .add_variants("a2b1c1", GenSpec().idx("a", 2).idx("b", 1).idx("c", 1)) - .add_variants("a1b2c1", GenSpec().idx("a", 1).idx("b", 2).idx("c", 1)) - .add_variants("a1b1c2", GenSpec().idx("a", 1).idx("b", 1).idx("c", 2)) - .add_variants("a1b1c1", GenSpec().idx("a", 1).idx("b", 1).idx("c", 1)) - .add_variants("a10", GenSpec().idx("a", 10)) - .add("xy_mapped", GenSpec().map("x", {"a", "b"}).map("y", {"x", "y"})) - .add("xyz_mixed", GenSpec().map("x", {"a", "b"}).map("y", {"x", "y"}).idx("z", 3)); -} -EvalFixture::ParamRepo param_repo = make_params(); - struct ReduceSpec { size_t outer_size; size_t reduce_size; @@ -38,37 +25,49 @@ struct ReduceSpec { Aggr aggr; }; -void verify_optimized_impl(const vespalib::string &expr, const std::vector<ReduceSpec> &spec_list) { - EvalFixture slow_fixture(prod_factory, expr, param_repo, false); - EvalFixture fixture(prod_factory, expr, param_repo, true); - EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo)); - EXPECT_EQUAL(fixture.result(), slow_fixture.result()); - auto info = fixture.find_all<DenseSingleReduceFunction>(); - ASSERT_EQUAL(info.size(), spec_list.size()); - for (size_t i = 0; i < spec_list.size(); ++i) { - EXPECT_TRUE(info[i]->result_is_mutable()); - EXPECT_EQUAL(info[i]->outer_size(), spec_list[i].outer_size); - EXPECT_EQUAL(info[i]->reduce_size(), spec_list[i].reduce_size); - EXPECT_EQUAL(info[i]->inner_size(), spec_list[i].inner_size); - EXPECT_EQUAL(int(info[i]->aggr()), int(spec_list[i].aggr)); +void verify_impl(const vespalib::string &expr, + const std::vector<ReduceSpec> &spec_list, + const std::vector<CellType> &with_cell_types) +{ + auto fun = Function::parse(expr); + ASSERT_EQUAL(fun->num_params(), 1u); + vespalib::string param_name = fun->param_name(0); + const auto param_spec = GenSpec::from_desc(param_name); + for (CellType ct: with_cell_types) { + EvalFixture::ParamRepo param_repo; + param_repo.add(param_name, param_spec.cpy().cells(ct)); + EvalFixture slow_fixture(prod_factory, expr, param_repo, false); + EvalFixture fixture(prod_factory, expr, param_repo, true); + EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo)); + EXPECT_EQUAL(fixture.result(), slow_fixture.result()); + auto info = fixture.find_all<DenseSingleReduceFunction>(); + ASSERT_EQUAL(info.size(), spec_list.size()); + for (size_t i = 0; i < spec_list.size(); ++i) { + EXPECT_TRUE(info[i]->result_is_mutable()); + EXPECT_EQUAL(info[i]->outer_size(), spec_list[i].outer_size); + EXPECT_EQUAL(info[i]->reduce_size(), spec_list[i].reduce_size); + EXPECT_EQUAL(info[i]->inner_size(), spec_list[i].inner_size); + EXPECT_EQUAL(int(info[i]->aggr()), int(spec_list[i].aggr)); + } } } -void verify_optimized(const vespalib::string &expr, const ReduceSpec &spec) { - verify_optimized_impl(expr, {spec}); +void verify_not_optimized(const vespalib::string &expr, + std::vector<CellType> with_cell_types = {CellType::DOUBLE}) +{ + verify_impl(expr, {}, with_cell_types); } -void verify_optimized(const vespalib::string &expr, const ReduceSpec &spec1, const ReduceSpec &spec2) { - verify_optimized_impl(expr, {spec1, spec2}); +void verify_optimized(const vespalib::string &expr, const ReduceSpec &spec, + std::vector<CellType> with_cell_types = CellTypeUtils::list_types()) +{ + verify_impl(expr, {spec}, with_cell_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_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo)); - EXPECT_EQUAL(fixture.result(), slow_fixture.result()); - auto info = fixture.find_all<DenseSingleReduceFunction>(); - EXPECT_TRUE(info.empty()); +void verify_optimized(const vespalib::string &expr, const ReduceSpec &spec1, const ReduceSpec &spec2, + std::vector<CellType> with_cell_types = CellTypeUtils::list_types()) +{ + verify_impl(expr, {spec1, spec2}, with_cell_types); } TEST("require that reduce to scalar is not optimized") { @@ -77,14 +76,14 @@ TEST("require that reduce to scalar is not optimized") { } TEST("require that sparse reduce is not optimized") { - TEST_DO(verify_not_optimized("reduce(xy_mapped,sum,x)")); - TEST_DO(verify_not_optimized("reduce(xy_mapped,sum,y)")); + TEST_DO(verify_not_optimized("reduce(x2_1y2_1,sum,x)")); + TEST_DO(verify_not_optimized("reduce(x2_1y2_1,sum,y)")); } TEST("require that mixed reduce is not optimized") { - TEST_DO(verify_not_optimized("reduce(xyz_mixed,sum,x)")); - TEST_DO(verify_not_optimized("reduce(xyz_mixed,sum,y)")); - TEST_DO(verify_not_optimized("reduce(xyz_mixed,sum,z)")); + TEST_DO(verify_not_optimized("reduce(x2_1y2_1z3,sum,x)")); + TEST_DO(verify_not_optimized("reduce(x2_1y2_1z3,sum,y)")); + TEST_DO(verify_not_optimized("reduce(x2_1y2_1z3,sum,z)")); } TEST("require that reducing trivial dimensions is not optimized") { @@ -98,11 +97,11 @@ TEST("require that reducing trivial dimensions is not optimized") { } TEST("require that atleast_8 dense single reduce works") { - TEST_DO(verify_optimized("reduce(a9b9c9d9,avg,a)", {1, 9, 729, Aggr::AVG})); - TEST_DO(verify_optimized("reduce(a9b9c9d9,avg,b)", {9, 9, 81, Aggr::AVG})); - TEST_DO(verify_optimized("reduce(a9b9c9d9,avg,c)", {81, 9, 9, Aggr::AVG})); - TEST_DO(verify_optimized("reduce(a9b9c9d9,avg,d)", {729, 9, 1, Aggr::AVG})); - TEST_DO(verify_optimized("reduce(a9b9c9d9,sum,c,d)", {81, 81, 1, Aggr::SUM})); + TEST_DO(verify_optimized("reduce(a9b9c9d9,avg,a)", {1, 9, 729, Aggr::AVG}, {CellType::FLOAT})); + TEST_DO(verify_optimized("reduce(a9b9c9d9,avg,b)", {9, 9, 81, Aggr::AVG}, {CellType::FLOAT})); + TEST_DO(verify_optimized("reduce(a9b9c9d9,avg,c)", {81, 9, 9, Aggr::AVG}, {CellType::FLOAT})); + TEST_DO(verify_optimized("reduce(a9b9c9d9,avg,d)", {729, 9, 1, Aggr::AVG}, {CellType::FLOAT})); + TEST_DO(verify_optimized("reduce(a9b9c9d9,sum,c,d)", {81, 81, 1, Aggr::SUM}, {CellType::FLOAT})); } TEST("require that simple aggregators can be decomposed into multiple reduce operations") { @@ -123,17 +122,11 @@ TEST("require that non-simple aggregators cannot be decomposed into multiple red TEST_DO(verify_not_optimized("reduce(a2b3c4d5,median,a,c)")); } -vespalib::string make_expr(const vespalib::string &arg, const vespalib::string &dim, bool float_cells, Aggr aggr) { - return make_string("reduce(%s%s,%s,%s)", arg.c_str(), float_cells ? "_f" : "", AggrNames::name_of(aggr)->c_str(), dim.c_str()); -} - void verify_optimized_multi(const vespalib::string &arg, const vespalib::string &dim, size_t outer_size, size_t reduce_size, size_t inner_size) { - for (bool float_cells: {false, true}) { - for (Aggr aggr: Aggregator::list()) { - if (aggr != Aggr::PROD) { - auto expr = make_expr(arg, dim, float_cells, aggr); - TEST_DO(verify_optimized(expr, {outer_size, reduce_size, inner_size, aggr})); - } + for (Aggr aggr: Aggregator::list()) { + if (aggr != Aggr::PROD) { + auto expr = fmt("reduce(%s,%s,%s)", arg.c_str(), AggrNames::name_of(aggr)->c_str(), dim.c_str()); + TEST_DO(verify_optimized(expr, {outer_size, reduce_size, inner_size, aggr})); } } } |