summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorHÃ¥vard Pettersen <3535158+havardpe@users.noreply.github.com>2021-02-01 19:19:21 +0100
committerGitHub <noreply@github.com>2021-02-01 19:19:21 +0100
commitfe6300b1e9b81c09aa0235b5049439198c6a2206 (patch)
treef1fc4262c3b4028f4a0ddc089b0afe71225555f8 /eval
parenta02729e2fe3064ac94e143091bb25424adef9b69 (diff)
parent4c4c46cffd1cce053788b0bb1c84996a90ccd0ba (diff)
Merge pull request #16306 from vespa-engine/arnej/use-genspec-in-unit-tests
Arnej/use genspec in unit tests
Diffstat (limited to 'eval')
-rw-r--r--eval/src/tests/instruction/generic_concat/generic_concat_test.cpp107
-rw-r--r--eval/src/tests/instruction/generic_create/generic_create_test.cpp44
-rw-r--r--eval/src/tests/instruction/generic_join/generic_join_test.cpp70
-rw-r--r--eval/src/tests/instruction/generic_map/generic_map_test.cpp44
-rw-r--r--eval/src/tests/instruction/generic_merge/generic_merge_test.cpp50
-rw-r--r--eval/src/tests/instruction/generic_peek/generic_peek_test.cpp36
-rw-r--r--eval/src/tests/instruction/generic_reduce/generic_reduce_test.cpp59
-rw-r--r--eval/src/tests/instruction/generic_rename/generic_rename_test.cpp49
-rw-r--r--eval/src/vespa/eval/eval/test/gen_spec.cpp5
-rw-r--r--eval/src/vespa/eval/eval/test/gen_spec.h5
10 files changed, 242 insertions, 227 deletions
diff --git a/eval/src/tests/instruction/generic_concat/generic_concat_test.cpp b/eval/src/tests/instruction/generic_concat/generic_concat_test.cpp
index bc8ea84744f..88bf7f26b11 100644
--- a/eval/src/tests/instruction/generic_concat/generic_concat_test.cpp
+++ b/eval/src/tests/instruction/generic_concat/generic_concat_test.cpp
@@ -7,7 +7,7 @@
#include <vespa/eval/instruction/generic_concat.h>
#include <vespa/eval/eval/interpreted_function.h>
#include <vespa/eval/eval/test/reference_operations.h>
-#include <vespa/eval/eval/test/tensor_model.hpp>
+#include <vespa/eval/eval/test/gen_spec.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/gtest/gtest.h>
@@ -18,53 +18,48 @@ using namespace vespalib::eval::test;
using vespalib::make_string_short::fmt;
-std::vector<Layout> concat_layouts = {
- {}, {},
- {}, {y(5)},
- float_cells({y(5)}), {},
- {}, float_cells({y(5)}),
- {y(5)}, {},
- {y(2)}, {y(3)},
- {y(2)}, {x(3)},
- {x(2)}, {z(3)},
- {x(2),y(3)}, {x(2),y(3)},
- {x(2),y(3)}, {x(2),y(4)},
- {y(3),z(5)}, {y(3),z(5)},
- {y(3),z(5)}, {y(4),z(5)},
- {x(2),y(3),z(5)}, {x(2),y(3),z(5)},
- {x(2),y(3),z(5)}, {x(2),y(4),z(5)},
- {x(2),y(3),z({"a","b"})}, {x(2),y(3),z({"b","c"})},
- {x(2),y(3),z({"a","b"})}, {x(2),y(4),z({"b","c"})},
- {y(5)}, {y(2),x(5)},
- {x(3)}, {y(2),z(3)},
- {y(2)}, {y(3),x(5),z(2)},
- {y(2),x(5),z(2)}, {y(3),x(5),z(2)},
- {y(3),x(5)}, {x(5),z(7)},
- float_cells({y(3),x(5)}), {x(5),z(7)},
- float_cells({y(3),x(5)}), {},
- {y(3),x(5)}, float_cells({x(5),z(7)}),
- float_cells({y(3),x(5)}), float_cells({x(5),z(7)}),
- {x({"a","b","c"})}, {x({"a","b","c"})},
- {x({"a","b","c"})}, {x({"a","b"})},
- {x({"a","b","c"})}, {x({"b","c","d"})},
- float_cells({x({"a","b","c"})}), {x({"b","c","d"})},
- {x({"a","b","c"})}, float_cells({x({"b","c","d"})}),
- float_cells({x({"a","b","c"})}), float_cells({z({"foo","bar","baz"})}),
- {x({"a","b","c"})}, {x({"a","b","c"}),z({"foo","bar","baz"})},
- {x({"a","b"}),z({"foo","bar","baz"})}, {x({"a","b","c"}),z({"foo","bar"})},
- {x({"a","b","c"}),y(3)}, {y(2)},
- {x({"a","b","c"}),y(3)}, {z(5)},
- {x({"a","b","c"}),y(3)}, {y(2),z(5)},
- {x({"a","b","c"}),y(3)}, {y(2)},
- {x({"a","b","c"}),y(3),z(5)}, {z(5)},
- {y(2)}, {x({"a","b","c"}),y(3)},
- {z(5)}, {x({"a","b","c"}),y(3)},
- {y(2),z(5)}, {x({"a","b","c"}),y(3)},
- {y(2)}, {x({"a","b","c"}),y(3)},
- {z(5)}, {x({"a","b","c"}),y(3),z(5)},
- {y(2),z(5)}, {x({"a","b","c"}),y(3),z(5)},
- {y(2),x({"a","b","c"})}, {y(3),x({"b","c","d"})},
- {y(2),x({"a","b"})}, {y(3),z({"c","d"})}
+GenSpec G() { return GenSpec().cells_float(); }
+
+GenSpec::seq_t N_16ths = [] (size_t i) { return (i + 1.0) / 16.0; };
+
+std::vector<GenSpec> concat_layouts = {
+ G(), G(),
+ G(), G().idx("y", 5),
+ G().idx("y", 5), G(),
+ G().idx("y", 2), G().idx("y", 3),
+ G().idx("y", 2), G().idx("x", 3),
+ G().idx("x", 2), G().idx("z", 3),
+ G().idx("x", 2).idx("y", 3), G().idx("x", 2).idx("y", 3),
+ G().idx("x", 2).idx("y", 3), G().idx("x", 2).idx("y", 4),
+ G().idx("y", 3).idx("z", 5), G().idx("y", 3).idx("z", 5),
+ G().idx("y", 3).idx("z", 5), G().idx("y", 4).idx("z", 5),
+ G().idx("x", 2).idx("y", 3).idx("z", 5), G().idx("x", 2).idx("y", 3).idx("z", 5),
+ G().idx("x", 2).idx("y", 3).idx("z", 5), G().idx("x", 2).idx("y", 4).idx("z", 5),
+ G().idx("x", 2).idx("y", 3).map("z", {"a","b"}), G().idx("x", 2).idx("y", 3).map("z", {"b","c"}),
+ G().idx("x", 2).idx("y", 3).map("z", {"a","b"}), G().idx("x", 2).idx("y", 4).map("z", {"b","c"}),
+ G().idx("y", 5), G().idx("x", 5).idx("y", 2),
+ G().idx("x", 3), G().idx("y", 2).idx("z", 3),
+ G().idx("y", 2), G().idx("x", 5).idx("y", 3).idx("z", 2),
+ G().idx("x", 5).idx("y", 2).idx("z", 2), G().idx("x", 5).idx("y", 3).idx("z", 2),
+ G().idx("x", 5).idx("y", 3), G().idx("x", 5).idx("z", 7),
+ G().map("x", {"a","b","c"}), G().map("x", {"a","b","c"}),
+ G().map("x", {"a","b","c"}), G().map("x", {"a","b"}),
+ G().map("x", {"a","b","c"}), G().map("x", {"b","c","d"}),
+ G().map("x", {"a","b","c"}), G().map("x", {"a","b","c"}).map("z", {"foo","bar","baz"}),
+ G().map("x", {"a","b"}).map("z", {"foo","bar","baz"}), G().map("x", {"a","b","c"}).map("z", {"foo","bar"}),
+ G().map("x", {"a","b","c"}).idx("y", 3), G().idx("y", 2),
+ G().map("x", {"a","b","c"}).idx("y", 3), G().idx("z", 5),
+ G().map("x", {"a","b","c"}).idx("y", 3), G().idx("y", 2).idx("z", 5),
+ G().map("x", {"a","b","c"}).idx("y", 3), G().idx("y", 2),
+ G().map("x", {"a","b","c"}).idx("y", 3).idx("z", 5), G().idx("z", 5),
+ G().idx("y", 2), G().map("x", {"a","b","c"}).idx("y", 3),
+ G().idx("z", 5), G().map("x", {"a","b","c"}).idx("y", 3),
+ G().idx("y", 2).idx("z", 5), G().map("x", {"a","b","c"}).idx("y", 3),
+ G().idx("y", 2), G().map("x", {"a","b","c"}).idx("y", 3),
+ G().idx("z", 5), G().map("x", {"a","b","c"}).idx("y", 3).idx("z", 5),
+ G().idx("y", 2).idx("z", 5), G().map("x", {"a","b","c"}).idx("y", 3).idx("z", 5),
+ G().map("x", {"a","b","c"}).idx("y", 2), G().map("x", {"b","c","d"}).idx("y", 3),
+ G().map("x", {"a","b"}).idx("y", 2), G().idx("y", 3).map("z", {"c","d"})
};
TensorSpec perform_generic_concat(const TensorSpec &a, const TensorSpec &b,
@@ -81,12 +76,16 @@ TensorSpec perform_generic_concat(const TensorSpec &a, const TensorSpec &b,
void test_generic_concat_with(const ValueBuilderFactory &factory) {
ASSERT_TRUE((concat_layouts.size() % 2) == 0);
for (size_t i = 0; i < concat_layouts.size(); i += 2) {
- const TensorSpec lhs = spec(concat_layouts[i], N());
- const TensorSpec rhs = spec(concat_layouts[i + 1], Div16(N()));
- SCOPED_TRACE(fmt("\n===\nin LHS: %s\nin RHS: %s\n===\n", lhs.to_string().c_str(), rhs.to_string().c_str()));
- auto actual = perform_generic_concat(lhs, rhs, "y", factory);
- auto expect = ReferenceOperations::concat(lhs, rhs, "y");
- EXPECT_EQ(actual, expect);
+ const auto &l = concat_layouts[i];
+ const auto &r = concat_layouts[i+1].seq(N_16ths);
+ for (TensorSpec lhs : { l.gen(), l.cpy().cells_double().gen() }) {
+ for (TensorSpec rhs : { r.gen(), r.cpy().cells_double().gen() }) {
+ SCOPED_TRACE(fmt("\n===\nin LHS: %s\nin RHS: %s\n===\n", lhs.to_string().c_str(), rhs.to_string().c_str()));
+ auto actual = perform_generic_concat(lhs, rhs, "y", factory);
+ auto expect = ReferenceOperations::concat(lhs, rhs, "y");
+ EXPECT_EQ(actual, expect);
+ }
+ }
}
}
diff --git a/eval/src/tests/instruction/generic_create/generic_create_test.cpp b/eval/src/tests/instruction/generic_create/generic_create_test.cpp
index 00af75e4d83..2dce4509571 100644
--- a/eval/src/tests/instruction/generic_create/generic_create_test.cpp
+++ b/eval/src/tests/instruction/generic_create/generic_create_test.cpp
@@ -6,7 +6,7 @@
#include <vespa/eval/instruction/generic_create.h>
#include <vespa/eval/eval/interpreted_function.h>
#include <vespa/eval/eval/test/reference_operations.h>
-#include <vespa/eval/eval/test/tensor_model.hpp>
+#include <vespa/eval/eval/test/gen_spec.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/gtest/gtest.h>
#include <stdlib.h>
@@ -19,18 +19,17 @@ using namespace vespalib::eval::test;
using vespalib::make_string_short::fmt;
-std::vector<Layout> create_layouts = {
- {x(3)},
- {x(3),y(5)},
- {x(3),y(5),z(7)},
- float_cells({x(3),y(5),z(7)}),
- {x({"a","b","c"})},
- {x({"a","b","c"}),y({"foo","bar"})},
- {x({"a","b","c"}),y({"foo","bar"}),z({"i","j","k","l"})},
- float_cells({x({"a","b","c"}),y({"foo","bar"}),z({"i","j","k","l"})}),
- {x(3),y({"foo", "bar"}),z(7)},
- {x({"a","b","c"}),y(5),z({"i","j","k","l"})},
- float_cells({x({"a","b","c"}),y(5),z({"i","j","k","l"})})
+GenSpec G() { return GenSpec().cells_float(); }
+
+std::vector<GenSpec> create_layouts = {
+ G().idx("x", 3),
+ G().idx("x", 3).idx("y", 5),
+ G().idx("x", 3).idx("y", 5).idx("z", 7),
+ G().map("x", {"a","b","c"}),
+ G().map("x", {"a","b","c"}).map("y", {"foo","bar"}),
+ G().map("x", {"a","b","c"}).map("y", {"foo","bar"}).map("z", {"i","j","k","l"}),
+ G().idx("x", 3).map("y", {"foo", "bar"}).idx("z", 7),
+ G().map("x", {"a","b","c"}).idx("y", 5).map("z", {"i","j","k","l"})
};
TensorSpec remove_each(const TensorSpec &a, size_t n) {
@@ -91,16 +90,17 @@ TensorSpec perform_generic_create(const TensorSpec &a, const ValueBuilderFactory
}
void test_generic_create_with(const ValueBuilderFactory &factory) {
- for (const auto & layout : create_layouts) {
- TensorSpec full = spec(layout, N());
- auto actual = perform_generic_create(full, factory);
- auto expect = reference_create(full).normalize();
- EXPECT_EQ(actual, expect);
- for (size_t n : {2, 3, 4, 5}) {
- TensorSpec partial = remove_each(full, n);
- actual = perform_generic_create(partial, factory);
- expect = reference_create(partial).normalize();
+ for (const auto &layout : create_layouts) {
+ for (TensorSpec full : { layout.gen(), layout.cpy().cells_double().gen() }) {
+ auto actual = perform_generic_create(full, factory);
+ auto expect = reference_create(full).normalize();
EXPECT_EQ(actual, expect);
+ for (size_t n : {2, 3, 4, 5}) {
+ TensorSpec partial = remove_each(full, n);
+ actual = perform_generic_create(partial, factory);
+ expect = reference_create(partial).normalize();
+ EXPECT_EQ(actual, expect);
+ }
}
}
}
diff --git a/eval/src/tests/instruction/generic_join/generic_join_test.cpp b/eval/src/tests/instruction/generic_join/generic_join_test.cpp
index 8eca3cad763..e8af8f8ad38 100644
--- a/eval/src/tests/instruction/generic_join/generic_join_test.cpp
+++ b/eval/src/tests/instruction/generic_join/generic_join_test.cpp
@@ -6,7 +6,7 @@
#include <vespa/eval/instruction/generic_join.h>
#include <vespa/eval/eval/interpreted_function.h>
#include <vespa/eval/eval/test/reference_operations.h>
-#include <vespa/eval/eval/test/tensor_model.hpp>
+#include <vespa/eval/eval/test/gen_spec.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/gtest/gtest.h>
@@ -17,33 +17,25 @@ using namespace vespalib::eval::test;
using vespalib::make_string_short::fmt;
-std::vector<Layout> join_layouts = {
- {}, {},
- {x(5)}, {x(5)},
- {x(5)}, {y(5)},
- {x(5)}, {x(5),y(5)},
- {y(3)}, {x(2),z(3)},
- {x(3),y(5)}, {y(5),z(7)},
- float_cells({x(3),y(5)}), {y(5),z(7)},
- {x(3),y(5)}, float_cells({y(5),z(7)}),
- float_cells({x(3),y(5)}), float_cells({y(5),z(7)}),
- {x({"a","b","c"})}, {x({"a","b","c"})},
- {x({"a","b","c"})}, {x({"a","b"})},
- {x({"a","b","c"})}, {y({"foo","bar","baz"})},
- {x({"a","b","c"})}, {x({"a","b","c"}),y({"foo","bar","baz"})},
- {x({"a","b"}),y({"foo","bar","baz"})}, {x({"a","b","c"}),y({"foo","bar"})},
- {x({"a","b"}),y({"foo","bar","baz"})}, {y({"foo","bar"}),z({"i","j","k","l"})},
- float_cells({x({"a","b"}),y({"foo","bar","baz"})}), {y({"foo","bar"}),z({"i","j","k","l"})},
- {x({"a","b"}),y({"foo","bar","baz"})}, float_cells({y({"foo","bar"}),z({"i","j","k","l"})}),
- float_cells({x({"a","b"}),y({"foo","bar","baz"})}), float_cells({y({"foo","bar"}),z({"i","j","k","l"})}),
- {x(3),y({"foo", "bar"})}, {y({"foo", "bar"}),z(7)},
- {x({"a","b","c"}),y(5)}, {y(5),z({"i","j","k","l"})},
- float_cells({x({"a","b","c"}),y(5)}), {y(5),z({"i","j","k","l"})},
- {x({"a","b","c"}),y(5)}, float_cells({y(5),z({"i","j","k","l"})}),
- float_cells({x({"a","b","c"}),y(5)}), float_cells({y(5),z({"i","j","k","l"})}),
- {x({"a","b","c"}),y(5)}, float_cells({y(5)}),
- {y(5)}, float_cells({x({"a","b","c"}),y(5)}),
- {x({}),y(5)}, float_cells({y(5)})
+GenSpec::seq_t N_16ths = [] (size_t i) { return (i + 1.0) / 16.0; };
+
+GenSpec G() { return GenSpec().cells_float().seq(N_16ths); }
+
+std::vector<GenSpec> join_layouts = {
+ G(), G(),
+ G().idx("x", 5), G().idx("x", 5),
+ G().idx("x", 5), G().idx("y", 5),
+ G().idx("x", 5), G().idx("x", 5).idx("y", 5),
+ G().idx("y", 3), G().idx("x", 2).idx("z", 3),
+ G().idx("x", 3).idx("y", 5), G().idx("y", 5).idx("z", 7),
+ G().map("x", {"a","b","c"}), G().map("x", {"a","b","c"}),
+ G().map("x", {"a","b","c"}), G().map("x", {"a","b"}),
+ G().map("x", {"a","b","c"}), G().map("y", {"foo","bar","baz"}),
+ G().map("x", {"a","b","c"}), G().map("x", {"a","b","c"}).map("y", {"foo","bar","baz"}),
+ G().map("x", {"a","b"}).map("y", {"foo","bar","baz"}), G().map("x", {"a","b","c"}).map("y", {"foo","bar"}),
+ G().map("x", {"a","b"}).map("y", {"foo","bar","baz"}), G().map("y", {"foo","bar"}).map("z", {"i","j","k","l"}),
+ G().idx("x", 3).map("y", {"foo", "bar"}), G().map("y", {"foo", "bar"}).idx("z", 7),
+ G().map("x", {"a","b","c"}).idx("y", 5), G().idx("y", 5).map("z", {"i","j","k","l"})
};
bool join_address(const TensorSpec::Address &a, const TensorSpec::Address &b, TensorSpec::Address &addr) {
@@ -113,15 +105,19 @@ TEST(GenericJoinTest, dense_join_plan_can_be_executed) {
TEST(GenericJoinTest, generic_join_works_for_simple_and_fast_values) {
ASSERT_TRUE((join_layouts.size() % 2) == 0);
for (size_t i = 0; i < join_layouts.size(); i += 2) {
- TensorSpec lhs = spec(join_layouts[i], Div16(N()));
- TensorSpec rhs = spec(join_layouts[i + 1], Div16(N()));
- for (auto fun: {operation::Add::f, operation::Sub::f, operation::Mul::f, operation::Div::f}) {
- SCOPED_TRACE(fmt("\n===\nLHS: %s\nRHS: %s\n===\n", lhs.to_string().c_str(), rhs.to_string().c_str()));
- auto expect = ReferenceOperations::join(lhs, rhs, fun);
- auto simple = perform_generic_join(lhs, rhs, fun, SimpleValueBuilderFactory::get());
- auto fast = perform_generic_join(lhs, rhs, fun, FastValueBuilderFactory::get());
- EXPECT_EQ(simple, expect);
- EXPECT_EQ(fast, expect);
+ const auto &l = join_layouts[i];
+ const auto &r = join_layouts[i+1];
+ for (TensorSpec lhs : { l.gen(), l.cpy().cells_double().gen() }) {
+ for (TensorSpec rhs : { r.gen(), r.cpy().cells_double().gen() }) {
+ for (auto fun: {operation::Add::f, operation::Sub::f, operation::Mul::f, operation::Div::f}) {
+ SCOPED_TRACE(fmt("\n===\nLHS: %s\nRHS: %s\n===\n", lhs.to_string().c_str(), rhs.to_string().c_str()));
+ auto expect = ReferenceOperations::join(lhs, rhs, fun);
+ auto simple = perform_generic_join(lhs, rhs, fun, SimpleValueBuilderFactory::get());
+ auto fast = perform_generic_join(lhs, rhs, fun, FastValueBuilderFactory::get());
+ EXPECT_EQ(simple, expect);
+ EXPECT_EQ(fast, expect);
+ }
+ }
}
}
}
diff --git a/eval/src/tests/instruction/generic_map/generic_map_test.cpp b/eval/src/tests/instruction/generic_map/generic_map_test.cpp
index 687b6aa60ac..d8203ea135c 100644
--- a/eval/src/tests/instruction/generic_map/generic_map_test.cpp
+++ b/eval/src/tests/instruction/generic_map/generic_map_test.cpp
@@ -6,7 +6,7 @@
#include <vespa/eval/instruction/generic_map.h>
#include <vespa/eval/eval/interpreted_function.h>
#include <vespa/eval/eval/test/reference_operations.h>
-#include <vespa/eval/eval/test/tensor_model.hpp>
+#include <vespa/eval/eval/test/gen_spec.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/gtest/gtest.h>
@@ -17,18 +17,20 @@ using namespace vespalib::eval::test;
using vespalib::make_string_short::fmt;
-std::vector<Layout> map_layouts = {
- {x(3)},
- {x(3),y(5)},
- {x(3),y(5),z(7)},
- float_cells({x(3),y(5),z(7)}),
- {x({"a","b","c"})},
- {x({"a","b","c"}),y({"foo","bar"})},
- {x({"a","b","c"}),y({"foo","bar"}),z({"i","j","k","l"})},
- float_cells({x({"a","b","c"}),y({"foo","bar"}),z({"i","j","k","l"})}),
- {x(3),y({"foo", "bar"}),z(7)},
- {x({"a","b","c"}),y(5),z({"i","j","k","l"})},
- float_cells({x({"a","b","c"}),y(5),z({"i","j","k","l"})})
+GenSpec::seq_t N_16ths = [] (size_t i) { return (i + 1.0) / 16.0; };
+
+GenSpec G() { return GenSpec().cells_float().seq(N_16ths); }
+
+std::vector<GenSpec> map_layouts = {
+ G(),
+ G().idx("x", 3),
+ G().idx("x", 3).idx("y", 5),
+ G().idx("x", 3).idx("y", 5).idx("z", 7),
+ G().map("x", {"a","b","c"}),
+ G().map("x", {"a","b","c"}).map("y", {"foo","bar"}),
+ G().map("x", {"a","b","c"}).map("y", {"foo","bar"}).map("z", {"i","j","k","l"}),
+ G().idx("x", 3).map("y", {"foo", "bar"}).idx("z", 7),
+ G().map("x", {"a","b","c"}).idx("y", 5).map("z", {"i","j","k","l"})
};
TensorSpec perform_generic_map(const TensorSpec &a, map_fun_t func, const ValueBuilderFactory &factory)
@@ -40,14 +42,14 @@ TensorSpec perform_generic_map(const TensorSpec &a, map_fun_t func, const ValueB
}
void test_generic_map_with(const ValueBuilderFactory &factory) {
- for (const auto & layout : map_layouts) {
- TensorSpec lhs = spec(layout, Div16(N()));
- ValueType lhs_type = ValueType::from_spec(lhs.type());
- for (auto func : {operation::Floor::f, operation::Fabs::f, operation::Square::f, operation::Inv::f}) {
- SCOPED_TRACE(fmt("\n===\nLHS: %s\n===\n", lhs.to_string().c_str()));
- auto expect = ReferenceOperations::map(lhs, func);
- auto actual = perform_generic_map(lhs, func, factory);
- EXPECT_EQ(actual, expect);
+ for (const auto &layout : map_layouts) {
+ for (TensorSpec lhs : { layout.gen(), layout.cpy().cells_double().gen() }) {
+ for (auto func : {operation::Floor::f, operation::Fabs::f, operation::Square::f, operation::Inv::f}) {
+ SCOPED_TRACE(fmt("\n===\nLHS: %s\n===\n", lhs.to_string().c_str()));
+ auto expect = ReferenceOperations::map(lhs, func);
+ auto actual = perform_generic_map(lhs, func, factory);
+ EXPECT_EQ(actual, expect);
+ }
}
}
}
diff --git a/eval/src/tests/instruction/generic_merge/generic_merge_test.cpp b/eval/src/tests/instruction/generic_merge/generic_merge_test.cpp
index 60a27e6f6e9..2554e018cf0 100644
--- a/eval/src/tests/instruction/generic_merge/generic_merge_test.cpp
+++ b/eval/src/tests/instruction/generic_merge/generic_merge_test.cpp
@@ -6,7 +6,7 @@
#include <vespa/eval/instruction/generic_merge.h>
#include <vespa/eval/eval/interpreted_function.h>
#include <vespa/eval/eval/test/reference_operations.h>
-#include <vespa/eval/eval/test/tensor_model.hpp>
+#include <vespa/eval/eval/test/gen_spec.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/gtest/gtest.h>
#include <optional>
@@ -18,20 +18,22 @@ using namespace vespalib::eval::test;
using vespalib::make_string_short::fmt;
-std::vector<Layout> merge_layouts = {
- {}, {},
- {x(5)}, {x(5)},
- {x(3),y(5)}, {x(3),y(5)},
- float_cells({x(3),y(5)}), {x(3),y(5)},
- {x(3),y(5)}, float_cells({x(3),y(5)}),
- {x({"a","b","c"})}, {x({"a","b","c"})},
- {x({"a","b","c"})}, {x({"c","d","e"})},
- {x({"a","c","e"})}, {x({"b","c","d"})},
- {x({"b","c","d"})}, {x({"a","c","e"})},
- {x({"a","b","c"})}, {x({"c","d"})},
- {x({"a","b"}),y({"foo","bar","baz"})}, {x({"b","c"}),y({"any","foo","bar"})},
- {x(3),y({"foo", "bar"})}, {x(3),y({"baz", "bar"})},
- {x({"a","b","c"}),y(5)}, {x({"b","c","d"}),y(5)}
+GenSpec G() { return GenSpec().cells_float(); }
+
+GenSpec::seq_t N_16ths = [] (size_t i) { return (i + 1.0) / 16.0; };
+
+std::vector<GenSpec> merge_layouts = {
+ G(), G(),
+ G().idx("x", 5), G().idx("x", 5),
+ G().idx("x", 3).idx("y", 5), G().idx("x", 3).idx("y", 5),
+ G().map("x", {"a","b","c"}), G().map("x", {"a","b","c"}),
+ G().map("x", {"a","b","c"}), G().map("x", {"c","d","e"}),
+ G().map("x", {"a","c","e"}), G().map("x", {"b","c","d"}),
+ G().map("x", {"b","c","d"}), G().map("x", {"a","c","e"}),
+ G().map("x", {"a","b","c"}), G().map("x", {"c","d"}),
+ G().map("x", {"a","b"}).map("y", {"foo","bar","baz"}), G().map("x", {"b","c"}).map("y", {"any","foo","bar"}),
+ G().idx("x", 3).map("y", {"foo", "bar"}), G().idx("x", 3).map("y", {"baz", "bar"}),
+ G().map("x", {"a","b","c"}).idx("y", 5), G().map("x", {"b","c","d"}).idx("y", 5)
};
TensorSpec perform_generic_merge(const TensorSpec &a, const TensorSpec &b, join_fun_t fun, const ValueBuilderFactory &factory) {
@@ -46,13 +48,17 @@ TensorSpec perform_generic_merge(const TensorSpec &a, const TensorSpec &b, join_
void test_generic_merge_with(const ValueBuilderFactory &factory) {
ASSERT_TRUE((merge_layouts.size() % 2) == 0);
for (size_t i = 0; i < merge_layouts.size(); i += 2) {
- TensorSpec lhs = spec(merge_layouts[i], N());
- TensorSpec rhs = spec(merge_layouts[i + 1], Div16(N()));
- SCOPED_TRACE(fmt("\n===\nLHS: %s\nRHS: %s\n===\n", lhs.to_string().c_str(), rhs.to_string().c_str()));
- for (auto fun: {operation::Add::f, operation::Mul::f, operation::Sub::f, operation::Max::f}) {
- auto expect = ReferenceOperations::merge(lhs, rhs, fun);
- auto actual = perform_generic_merge(lhs, rhs, fun, factory);
- EXPECT_EQ(actual, expect);
+ const auto &l = merge_layouts[i];
+ const auto &r = merge_layouts[i+1].seq(N_16ths);
+ for (TensorSpec lhs : { l.gen(), l.cpy().cells_double().gen() }) {
+ for (TensorSpec rhs : { r.gen(), r.cpy().cells_double().gen() }) {
+ SCOPED_TRACE(fmt("\n===\nLHS: %s\nRHS: %s\n===\n", lhs.to_string().c_str(), rhs.to_string().c_str()));
+ for (auto fun: {operation::Add::f, operation::Mul::f, operation::Sub::f, operation::Max::f}) {
+ auto expect = ReferenceOperations::merge(lhs, rhs, fun);
+ auto actual = perform_generic_merge(lhs, rhs, fun, factory);
+ EXPECT_EQ(actual, expect);
+ }
+ }
}
}
}
diff --git a/eval/src/tests/instruction/generic_peek/generic_peek_test.cpp b/eval/src/tests/instruction/generic_peek/generic_peek_test.cpp
index 6841215038a..092a91711ba 100644
--- a/eval/src/tests/instruction/generic_peek/generic_peek_test.cpp
+++ b/eval/src/tests/instruction/generic_peek/generic_peek_test.cpp
@@ -7,7 +7,7 @@
#include <vespa/eval/instruction/generic_peek.h>
#include <vespa/eval/eval/interpreted_function.h>
#include <vespa/eval/eval/test/reference_operations.h>
-#include <vespa/eval/eval/test/tensor_model.hpp>
+#include <vespa/eval/eval/test/gen_spec.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/util/overload.h>
#include <vespa/vespalib/gtest/gtest.h>
@@ -22,17 +22,16 @@ using namespace vespalib::eval::test;
using vespalib::make_string_short::fmt;
-std::vector<Layout> peek_layouts = {
- {x(4)},
- {x(4),y(5)},
- {x(4),y(5),z(3)},
- float_cells({x(4),y(5),z(3)}),
- {x({"-1","0","2"})},
- {x({"-1","0","2"}),y({"-2","0","1"}),z({"-2","-1","0","1","2"})},
- float_cells({x({"-1","0","2"}),y({"-2","0","1"})}),
- {x(4),y({"-2","0","1"}),z(3)},
- {x({"-1","0","2"}),y(5),z({"-2","-1","0","1","2"})},
- float_cells({x({"-1","0","2"}),y(5),z({"-2","-1","0","1","2"})})
+GenSpec G() { return GenSpec().cells_float(); }
+
+std::vector<GenSpec> peek_layouts = {
+ G().idx("x", 4),
+ G().idx("x", 4).idx("y", 5),
+ G().idx("x", 4).idx("y", 5).idx("z", 3),
+ G().map("x", {"-1","0","2"}),
+ G().map("x", {"-1","0","2"}).map("y", {"-2","0","1"}).map("z", {"-2","-1","0","1","2"}),
+ G().idx("x", 4).map("y", {"-2","0","1"}).idx("z", 3),
+ G().map("x", {"-1","0","2"}).idx("y", 5).map("z", {"-2","-1","0","1","2"})
};
using PeekSpec = GenericPeek::SpecMap;
@@ -194,12 +193,13 @@ void fill_dims_and_check(const TensorSpec &input,
}
void test_generic_peek_with(const ValueBuilderFactory &factory) {
- for (const auto & layout : peek_layouts) {
- TensorSpec input = spec(layout, N());
- ValueType input_type = ValueType::from_spec(input.type());
- const auto &dims = input_type.dimensions();
- PeekSpec spec;
- fill_dims_and_check(input, spec, dims, factory);
+ for (const auto &layout : peek_layouts) {
+ for (TensorSpec input : { layout.gen(), layout.cpy().cells_double().gen() }) {
+ ValueType input_type = ValueType::from_spec(input.type());
+ const auto &dims = input_type.dimensions();
+ PeekSpec spec;
+ fill_dims_and_check(input, spec, dims, factory);
+ }
}
}
diff --git a/eval/src/tests/instruction/generic_reduce/generic_reduce_test.cpp b/eval/src/tests/instruction/generic_reduce/generic_reduce_test.cpp
index 9e2090fa968..1e9ce85d7e1 100644
--- a/eval/src/tests/instruction/generic_reduce/generic_reduce_test.cpp
+++ b/eval/src/tests/instruction/generic_reduce/generic_reduce_test.cpp
@@ -6,7 +6,7 @@
#include <vespa/eval/instruction/generic_reduce.h>
#include <vespa/eval/eval/interpreted_function.h>
#include <vespa/eval/eval/test/reference_operations.h>
-#include <vespa/eval/eval/test/tensor_model.hpp>
+#include <vespa/eval/eval/test/gen_spec.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/gtest/gtest.h>
#include <optional>
@@ -18,22 +18,23 @@ using namespace vespalib::eval::test;
using vespalib::make_string_short::fmt;
-std::vector<Layout> layouts = {
- {},
- {x(3)},
- {x(3),y(5)},
- {x(3),y(5),z(7)},
- float_cells({x(3),y(5),z(7)}),
- {x({"a","b","c"})},
- {x({})},
- {x({}),y(10)},
- {x({"a","b","c"}),y({"foo","bar"})},
- {x({"a","b","c"}),y({"foo","bar"}),z({"i","j","k","l"})},
- float_cells({x({"a","b","c"}),y({"foo","bar"}),z({"i","j","k","l"})}),
- {x(3),y({"foo", "bar"}),z(7)},
- {x({"a","b","c"}),y(5),z({"i","j","k","l"})},
- float_cells({x({"a","b","c"}),y(5),z({"i","j","k","l"})}),
- {x(3),y({}),z(7)}
+GenSpec::seq_t N_16ths = [] (size_t i) { return (i + 1.0) / 16.0; };
+
+GenSpec G() { return GenSpec().cells_float().seq(N_16ths); }
+
+std::vector<GenSpec> layouts = {
+ G(),
+ G().idx("x", 3),
+ G().idx("x", 3).idx("y", 5),
+ G().idx("x", 3).idx("y", 5).idx("z", 7),
+ G().map("x", {"a","b","c"}),
+ G().map("x", {}),
+ G().map("x", {}).idx("y", 10),
+ G().map("x", {"a","b","c"}).map("y", {"foo","bar"}),
+ G().map("x", {"a","b","c"}).map("y", {"foo","bar"}).map("z", {"i","j","k","l"}),
+ G().idx("x", 3).map("y", {"foo", "bar"}).idx("z", 7),
+ G().map("x", {"a","b","c"}).idx("y", 5).map("z", {"i","j","k","l"}),
+ G().idx("x", 3).map("y", {}).idx("z", 7)
};
TensorSpec perform_generic_reduce(const TensorSpec &a, Aggr aggr, const std::vector<vespalib::string> &dims,
@@ -68,19 +69,21 @@ TEST(GenericReduceTest, sparse_reduce_plan_can_be_created) {
}
void test_generic_reduce_with(const ValueBuilderFactory &factory) {
- for (const Layout &layout: layouts) {
- TensorSpec input = spec(layout, Div16(N()));
- SCOPED_TRACE(fmt("tensor type: %s, num_cells: %zu", input.type().c_str(), input.cells().size()));
- for (Aggr aggr: {Aggr::SUM, Aggr::AVG, Aggr::MIN, Aggr::MAX}) {
- SCOPED_TRACE(fmt("aggregator: %s", AggrNames::name_of(aggr)->c_str()));
- for (const Domain &domain: layout) {
- auto expect = ReferenceOperations::reduce(input, aggr, {domain.dimension}).normalize();
- auto actual = perform_generic_reduce(input, aggr, {domain.dimension}, factory);
+ for (const auto &layout: layouts) {
+ for (TensorSpec input : { layout.gen(), layout.cpy().cells_double().gen() }) {
+ SCOPED_TRACE(fmt("tensor type: %s, num_cells: %zu", input.type().c_str(), input.cells().size()));
+ for (Aggr aggr: {Aggr::SUM, Aggr::AVG, Aggr::MIN, Aggr::MAX}) {
+ SCOPED_TRACE(fmt("aggregator: %s", AggrNames::name_of(aggr)->c_str()));
+ auto t = layout.type();
+ for (const auto & dim: t.dimensions()) {
+ auto expect = ReferenceOperations::reduce(input, aggr, {dim.name}).normalize();
+ auto actual = perform_generic_reduce(input, aggr, {dim.name}, factory);
+ EXPECT_EQ(actual, expect);
+ }
+ auto expect = ReferenceOperations::reduce(input, aggr, {}).normalize();
+ auto actual = perform_generic_reduce(input, aggr, {}, factory);
EXPECT_EQ(actual, expect);
}
- auto expect = ReferenceOperations::reduce(input, aggr, {}).normalize();
- auto actual = perform_generic_reduce(input, aggr, {}, factory);
- EXPECT_EQ(actual, expect);
}
}
}
diff --git a/eval/src/tests/instruction/generic_rename/generic_rename_test.cpp b/eval/src/tests/instruction/generic_rename/generic_rename_test.cpp
index 20d155822b5..430e417e288 100644
--- a/eval/src/tests/instruction/generic_rename/generic_rename_test.cpp
+++ b/eval/src/tests/instruction/generic_rename/generic_rename_test.cpp
@@ -5,7 +5,7 @@
#include <vespa/eval/eval/value_codec.h>
#include <vespa/eval/instruction/generic_rename.h>
#include <vespa/eval/eval/interpreted_function.h>
-#include <vespa/eval/eval/test/tensor_model.hpp>
+#include <vespa/eval/eval/test/gen_spec.h>
#include <vespa/eval/eval/test/reference_operations.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/gtest/gtest.h>
@@ -17,18 +17,17 @@ using namespace vespalib::eval::test;
using vespalib::make_string_short::fmt;
-std::vector<Layout> rename_layouts = {
- {x(3)},
- {x(3),y(5)},
- {x(3),y(5),z(7)},
- float_cells({x(3),y(5),z(7)}),
- {x({"a","b","c"})},
- {x({"a","b","c"}),y({"foo","bar"})},
- {x({"a","b","c"}),y({"foo","bar"}),z({"i","j","k","l"})},
- float_cells({x({"a","b","c"}),y({"foo","bar"}),z({"i","j","k","l"})}),
- {x(3),y({"foo", "bar"}),z(7)},
- {x({"a","b","c"}),y(5),z({"i","j","k","l"})},
- float_cells({x({"a","b","c"}),y(5),z({"i","j","k","l"})})
+GenSpec G() { return GenSpec().cells_float(); }
+
+std::vector<GenSpec> rename_layouts = {
+ G().idx("x", 3),
+ G().idx("x", 3).idx("y", 5),
+ G().idx("x", 3).idx("y", 5).idx("z", 7),
+ G().map("x", {"a","b","c"}),
+ G().map("x", {"a","b","c"}).map("y", {"foo","bar"}),
+ G().map("x", {"a","b","c"}).map("y", {"foo","bar"}).map("z", {"i","j","k","l"}),
+ G().idx("x", 3).map("y", {"foo", "bar"}).idx("z", 7),
+ G().map("x", {"a","b","c"}).idx("y", 5).map("z", {"i","j","k","l"})
};
struct FromTo {
@@ -110,18 +109,18 @@ TensorSpec perform_generic_rename(const TensorSpec &a,
}
void test_generic_rename_with(const ValueBuilderFactory &factory) {
- for (const auto & layout : rename_layouts) {
- TensorSpec lhs = spec(layout, N());
- ValueType lhs_type = ValueType::from_spec(lhs.type());
- // printf("lhs_type: %s\n", lhs_type.to_spec().c_str());
- for (const auto & from_to : rename_from_to) {
- ValueType renamed_type = lhs_type.rename(from_to.from, from_to.to);
- if (renamed_type.is_error()) continue;
- // printf("type %s -> %s\n", lhs_type.to_spec().c_str(), renamed_type.to_spec().c_str());
- SCOPED_TRACE(fmt("\n===\nLHS: %s\n===\n", lhs.to_string().c_str()));
- auto expect = ReferenceOperations::rename(lhs, from_to.from, from_to.to);
- auto actual = perform_generic_rename(lhs, from_to, factory);
- EXPECT_EQ(actual, expect);
+ for (const auto &layout : rename_layouts) {
+ for (TensorSpec lhs : { layout.gen(), layout.cpy().cells_double().gen() }) {
+ ValueType lhs_type = ValueType::from_spec(lhs.type());
+ for (const auto & from_to : rename_from_to) {
+ ValueType renamed_type = lhs_type.rename(from_to.from, from_to.to);
+ if (renamed_type.is_error()) continue;
+ // printf("type %s -> %s\n", lhs_type.to_spec().c_str(), renamed_type.to_spec().c_str());
+ SCOPED_TRACE(fmt("\n===\nLHS: %s\n===\n", lhs.to_string().c_str()));
+ auto expect = ReferenceOperations::rename(lhs, from_to.from, from_to.to);
+ auto actual = perform_generic_rename(lhs, from_to, factory);
+ EXPECT_EQ(actual, expect);
+ }
}
}
}
diff --git a/eval/src/vespa/eval/eval/test/gen_spec.cpp b/eval/src/vespa/eval/eval/test/gen_spec.cpp
index 9c40c65620e..c20e9005318 100644
--- a/eval/src/vespa/eval/eval/test/gen_spec.cpp
+++ b/eval/src/vespa/eval/eval/test/gen_spec.cpp
@@ -20,6 +20,11 @@ DimSpec::make_dict(size_t size, size_t stride, const vespalib::string &prefix)
return dict;
}
+GenSpec::GenSpec(GenSpec &&other) = default;
+GenSpec::GenSpec(const GenSpec &other) = default;
+GenSpec &GenSpec::operator=(GenSpec &&other) = default;
+GenSpec &GenSpec::operator=(const GenSpec &other) = default;
+
GenSpec::~GenSpec() = default;
ValueType
diff --git a/eval/src/vespa/eval/eval/test/gen_spec.h b/eval/src/vespa/eval/eval/test/gen_spec.h
index 81843156fd9..471e0f58642 100644
--- a/eval/src/vespa/eval/eval/test/gen_spec.h
+++ b/eval/src/vespa/eval/eval/test/gen_spec.h
@@ -66,10 +66,15 @@ private:
static double default_seq(size_t idx) { return (idx + 1.0); }
public:
GenSpec() : _dims(), _cells(CellType::DOUBLE), _seq(default_seq) {}
+ GenSpec(GenSpec &&other);
+ GenSpec(const GenSpec &other);
+ GenSpec &operator=(GenSpec &&other);
+ GenSpec &operator=(const GenSpec &other);
~GenSpec();
std::vector<DimSpec> dims() const { return _dims; }
CellType cells() const { return _cells; }
seq_t seq() const { return _seq; }
+ GenSpec cpy() const { return *this; }
GenSpec &idx(const vespalib::string &name, size_t size) {
_dims.emplace_back(name, size);
return *this;