summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-03-04 10:29:58 +0000
committerArne Juul <arnej@verizonmedia.com>2021-03-04 11:05:56 +0000
commit86585f9dc4939d407bc44b57925d81af0cd11ccd (patch)
treea16239fc41350ebb76c8c2892e5a4f03455e148c /eval
parent57920d4f49f4b32f6a8d02d30a919ded605b57e8 (diff)
test cleanup
Diffstat (limited to 'eval')
-rw-r--r--eval/src/tests/eval/reference_operations/reference_operations_test.cpp95
1 files changed, 54 insertions, 41 deletions
diff --git a/eval/src/tests/eval/reference_operations/reference_operations_test.cpp b/eval/src/tests/eval/reference_operations/reference_operations_test.cpp
index 0a76895f8d9..9d9645aafb0 100644
--- a/eval/src/tests/eval/reference_operations/reference_operations_test.cpp
+++ b/eval/src/tests/eval/reference_operations/reference_operations_test.cpp
@@ -10,14 +10,15 @@ using namespace vespalib;
using namespace vespalib::eval;
using vespalib::eval::test::GenSpec;
-TensorSpec dense_2d_some_cells(bool square) {
+TensorSpec dense_2d_input(bool square) {
return TensorSpec("tensor(a[3],d[5])")
.add({{"a", 1}, {"d", 2}}, square ? 9.0 : 3.0)
.add({{"a", 2}, {"d", 4}}, square ? 16.0 : 4.0)
- .add({{"a", 1}, {"d", 0}}, square ? 25.0 : 5.0);
+ .add({{"a", 1}, {"d", 0}}, square ? 25.0 : 5.0)
+ .normalize();
}
-TensorSpec sparse_2d_some_cells(bool square) {
+TensorSpec sparse_2d_input(bool square) {
return TensorSpec("tensor(c{},e{})")
.add({{"c", "foo"}, {"e", "foo"}}, square ? 1.0 : 1.0)
.add({{"c", "foo"}, {"e", "bar"}}, square ? 4.0 : 2.0)
@@ -26,13 +27,14 @@ TensorSpec sparse_2d_some_cells(bool square) {
.add({{"c", "qux"}, {"e", "qux"}}, square ? 25.0 : 5.0);
}
-TensorSpec mixed_5d_some_cells(bool square) {
+TensorSpec mixed_5d_input(bool square) {
return TensorSpec("tensor(a[3],b[1],c{},d[5],e{})")
.add({{"a", 1}, {"b", 0}, {"c", "foo"}, {"d", 2}, {"e", "bar"}}, square ? 4.0 : 2.0)
.add({{"a", 2}, {"b", 0}, {"c", "bar"}, {"d", 3}, {"e", "bar"}}, square ? 9.0 : 3.0)
.add({{"a", 0}, {"b", 0}, {"c", "foo"}, {"d", 4}, {"e", "foo"}}, square ? 16.0 : 4.0)
.add({{"a", 1}, {"b", 0}, {"c", "bar"}, {"d", 0}, {"e", "qux"}}, square ? 25.0 : 5.0)
- .add({{"a", 2}, {"b", 0}, {"c", "qux"}, {"d", 1}, {"e", "foo"}}, square ? 36.0 : 6.0);
+ .add({{"a", 2}, {"b", 0}, {"c", "qux"}, {"d", 1}, {"e", "foo"}}, square ? 36.0 : 6.0)
+ .normalize();
}
TensorSpec dense_1d_all_two() {
@@ -167,8 +169,9 @@ TEST(ReferenceCreateTest, simple_create_works) {
auto expect = TensorSpec("tensor(x[2],y{})")
.add({{"x",1},{"y","foo"}}, 1.5)
.add({{"x",0},{"y","bar"}}, 5.0)
- .add({{"x",1},{"y","bar"}}, 4.0);
- EXPECT_EQ(output, expect.normalize());
+ .add({{"x",1},{"y","bar"}}, 4.0)
+ .normalize();
+ EXPECT_EQ(output, expect);
}
//-----------------------------------------------------------------------------
@@ -181,15 +184,17 @@ TEST(ReferenceJoinTest, join_numbers) {
}
TEST(ReferenceJoinTest, join_mixed_tensors) {
- const auto expect_sq = mixed_5d_some_cells(true).normalize();
- auto a = mixed_5d_some_cells(false);
+ const auto expect_sq = mixed_5d_input(true);
+ auto a = mixed_5d_input(false);
auto b = TensorSpec("double").add({}, 2.0);
auto output = ReferenceOperations::join(a, b, operation::Pow::f);
EXPECT_EQ(output, expect_sq);
output = ReferenceOperations::join(a, a, operation::Mul::f);
EXPECT_EQ(output, expect_sq);
- auto c = ReferenceOperations::join(output, a, operation::Div::f);
- EXPECT_EQ(c, a.normalize());
+ // avoid division by zero:
+ b = ReferenceOperations::join(a, TensorSpec("double").add({}, 1.0), operation::Max::f);
+ auto c = ReferenceOperations::join(output, b, operation::Div::f);
+ EXPECT_EQ(c, a);
b = dense_1d_all_two();
output = ReferenceOperations::join(a, b, operation::Pow::f);
EXPECT_EQ(output, expect_sq);
@@ -209,27 +214,27 @@ TEST(ReferenceMapTest, map_numbers) {
}
TEST(ReferenceMapTest, map_dense_tensor) {
- auto input = dense_2d_some_cells(false);
+ auto input = dense_2d_input(false);
auto output = ReferenceOperations::map(input, operation::Square::f);
- EXPECT_EQ(output, dense_2d_some_cells(true).normalize());
+ EXPECT_EQ(output, dense_2d_input(true));
}
TEST(ReferenceMapTest, map_sparse_tensor) {
- auto input = sparse_2d_some_cells(false);
+ auto input = sparse_2d_input(false);
auto output = ReferenceOperations::map(input, operation::Square::f);
- EXPECT_EQ(output, sparse_2d_some_cells(true));
+ EXPECT_EQ(output, sparse_2d_input(true));
}
TEST(ReferenceMapTest, map_mixed_tensor) {
- auto input = mixed_5d_some_cells(false);
+ auto input = mixed_5d_input(false);
auto output = ReferenceOperations::map(input, operation::Square::f);
- EXPECT_EQ(output, mixed_5d_some_cells(true).normalize());
+ EXPECT_EQ(output, mixed_5d_input(true));
}
//-----------------------------------------------------------------------------
TEST(ReferenceMergeTest, simple_mixed_merge) {
- auto a = mixed_5d_some_cells(false);
+ auto a = mixed_5d_input(false);
auto b = TensorSpec("tensor(a[3],b[1],c{},d[5],e{})")
.add({{"a", 0}, {"b", 0}, {"c", "foo"}, {"d", 4}, {"e", "foo"}}, 0.0)
.add({{"a", 1}, {"b", 0}, {"c", "bar"}, {"d", 0}, {"e", "qux"}}, 42.0)
@@ -241,14 +246,15 @@ TEST(ReferenceMergeTest, simple_mixed_merge) {
.add({{"a", 0}, {"b", 0}, {"c", "foo"}, {"d", 4}, {"e", "foo"}}, 4.0)
.add({{"a", 1}, {"b", 0}, {"c", "bar"}, {"d", 0}, {"e", "qux"}}, 42.0)
.add({{"a", 2}, {"b", 0}, {"c", "qux"}, {"d", 1}, {"e", "foo"}}, 6.0)
- .add({{"a", 0}, {"b", 0}, {"c", "new"}, {"d", 0}, {"e", "new"}}, 1.0);
- EXPECT_EQ(output, expect.normalize());
+ .add({{"a", 0}, {"b", 0}, {"c", "new"}, {"d", 0}, {"e", "new"}}, 1.0)
+ .normalize();
+ EXPECT_EQ(output, expect);
}
//-----------------------------------------------------------------------------
TEST(ReferencePeekTest, verbatim_labels) {
- auto input = sparse_2d_some_cells(true);
+ auto input = sparse_2d_input(true);
ReferenceOperations::PeekSpec spec;
spec.emplace("c", "qux");
// peek 1 mapped dimension, verbatim label
@@ -272,18 +278,19 @@ TEST(ReferencePeekTest, verbatim_labels) {
spec.emplace("e", "nomatch");
// peek all mapped dimensions, non-matching verbatim labels
output = ReferenceOperations::peek(spec, {input});
- expect = TensorSpec("double").normalize();
+ expect = TensorSpec("double").add({}, 0.0);
EXPECT_EQ(output, expect);
- input = dense_2d_some_cells(false);
+ input = dense_2d_input(false);
spec.clear();
spec.emplace("a", TensorSpec::Label(1));
// peek 1 indexed dimension, verbatim label
output = ReferenceOperations::peek(spec, {input});
expect = TensorSpec("tensor(d[5])")
.add({{"d", 2}}, 3.0)
- .add({{"d", 0}}, 5.0);
- EXPECT_EQ(output, expect.normalize());
+ .add({{"d", 0}}, 5.0)
+ .normalize();
+ EXPECT_EQ(output, expect);
spec.emplace("d", TensorSpec::Label(2));
// peek all indexed dimensions, verbatim labels
output = ReferenceOperations::peek(spec, {input});
@@ -298,7 +305,7 @@ TEST(ReferencePeekTest, labels_from_children) {
auto too_big_ch = TensorSpec("double").add({}, 42.0);
std::vector<TensorSpec> children = {TensorSpec(""), too_big_ch, too_big_ch, zero_ch, pos_ch, neg_ch, too_big_ch};
auto &input = children[0];
- input = dense_2d_some_cells(false);
+ input = dense_2d_input(false);
ReferenceOperations::PeekSpec spec;
spec.emplace("a", size_t(4));
@@ -306,8 +313,9 @@ TEST(ReferencePeekTest, labels_from_children) {
auto output = ReferenceOperations::peek(spec, children);
auto expect = TensorSpec("tensor(d[5])")
.add({{"d", 2}}, 3.0)
- .add({{"d", 0}}, 5.0);
- EXPECT_EQ(output, expect.normalize());
+ .add({{"d", 0}}, 5.0)
+ .normalize();
+ EXPECT_EQ(output, expect);
spec.emplace("d", size_t(3));
// peek 2 indexed dimensions (both children)
output = ReferenceOperations::peek(spec, children);
@@ -317,14 +325,15 @@ TEST(ReferencePeekTest, labels_from_children) {
spec.emplace("a", size_t(1));
// peek 1 indexed dimension, child (evaluating to 42.0)
output = ReferenceOperations::peek(spec, children);
- expect = TensorSpec("tensor(d[5])").normalize();
- EXPECT_EQ(output, expect);
+ // nothing peeked gives zero-filled output:
+ auto empty = TensorSpec("tensor(d[5])").normalize();
+ EXPECT_EQ(output, empty);
spec.clear();
spec.emplace("a", size_t(5));
// peek 1 indexed dimension, child (evaluating to -2.0)
output = ReferenceOperations::peek(spec, children);
- expect = TensorSpec("tensor(d[5])").normalize();
- EXPECT_EQ(output, expect);
+ // nothing peeked gives zero-filled output:
+ EXPECT_EQ(output, empty);
input = TensorSpec("tensor(c{},e{})")
.add({{"c", "0"}, {"e", "0"}}, 2.0)
@@ -437,8 +446,9 @@ TEST(ReferenceReduceTest, various_reductions_of_big_mixed_tensor) {
.add({{"b", 0}, {"c", "foo"}, {"d", 2}, {"e", "foo"}}, 6.0)
.add({{"b", 0}, {"c", "foo"}, {"d", 3}, {"e", "foo"}}, 11.0)
.add({{"b", 0}, {"c", "foo"}, {"d", 4}, {"e", "foo"}}, 2.0)
- .add({{"b", 0}, {"c", "qux"}, {"d", 1}, {"e", "foo"}}, 14.0);
- EXPECT_EQ(output, expect.normalize());
+ .add({{"b", 0}, {"c", "qux"}, {"d", 1}, {"e", "foo"}}, 14.0)
+ .normalize();
+ EXPECT_EQ(output, expect);
output = ReferenceOperations::reduce(input, Aggr::SUM, {"a", "b", "d"});
expect = TensorSpec("tensor(c{},e{})")
@@ -463,8 +473,9 @@ TEST(ReferenceReduceTest, various_reductions_of_big_mixed_tensor) {
.add({{"a", 2}, {"b", 0}, {"d", 1}, {"e", "foo"}}, 14.0)
.add({{"a", 2}, {"b", 0}, {"d", 2}, {"e", "bar"}}, 13.0)
.add({{"a", 2}, {"b", 0}, {"d", 3}, {"e", "bar"}}, 12.0)
- .add({{"a", 2}, {"b", 0}, {"d", 3}, {"e", "foo"}}, 11.0);
- EXPECT_EQ(output, expect.normalize());
+ .add({{"a", 2}, {"b", 0}, {"d", 3}, {"e", "foo"}}, 11.0)
+ .normalize();
+ EXPECT_EQ(output, expect);
output = ReferenceOperations::reduce(input, Aggr::SUM, {"a", "c"});
expect = TensorSpec("tensor(b[1],d[5],e{})")
@@ -476,8 +487,9 @@ TEST(ReferenceReduceTest, various_reductions_of_big_mixed_tensor) {
.add({{"b", 0}, {"d", 2}, {"e", "qux"}}, 9.0)
.add({{"b", 0}, {"d", 3}, {"e", "bar"}}, 12.0)
.add({{"b", 0}, {"d", 3}, {"e", "foo"}}, 11.0)
- .add({{"b", 0}, {"d", 4}, {"e", "foo"}}, 5.0);
- EXPECT_EQ(output, expect.normalize());
+ .add({{"b", 0}, {"d", 4}, {"e", "foo"}}, 5.0)
+ .normalize();
+ EXPECT_EQ(output, expect);
output = ReferenceOperations::reduce(input, Aggr::SUM, {"a", "c", "d"});
expect = TensorSpec("tensor(b[1],e{})")
@@ -496,7 +508,7 @@ TEST(ReferenceReduceTest, various_reductions_of_big_mixed_tensor) {
//-----------------------------------------------------------------------------
TEST(ReferenceRenameTest, swap_and_rename_dimensions) {
- auto input = mixed_5d_some_cells(false);
+ auto input = mixed_5d_input(false);
auto output = ReferenceOperations::rename(input,
{"a","b","c","e"},
{"e","x","b","a"});
@@ -505,8 +517,9 @@ TEST(ReferenceRenameTest, swap_and_rename_dimensions) {
.add({{"e", 2}, {"x", 0}, {"b", "bar"}, {"d", 3}, {"a", "bar"}}, 3.0)
.add({{"e", 0}, {"x", 0}, {"b", "foo"}, {"d", 4}, {"a", "foo"}}, 4.0)
.add({{"e", 1}, {"x", 0}, {"b", "bar"}, {"d", 0}, {"a", "qux"}}, 5.0)
- .add({{"e", 2}, {"x", 0}, {"b", "qux"}, {"d", 1}, {"a", "foo"}}, 6.0);
- EXPECT_EQ(output, expect.normalize());
+ .add({{"e", 2}, {"x", 0}, {"b", "qux"}, {"d", 1}, {"a", "foo"}}, 6.0)
+ .normalize();
+ EXPECT_EQ(output, expect);
}
//-----------------------------------------------------------------------------