summaryrefslogtreecommitdiffstats
path: root/eval/src/tests/instruction/generic_join
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-11-25 08:09:53 +0000
committerArne Juul <arnej@verizonmedia.com>2020-11-25 10:05:14 +0000
commitb8387e5455c63a39ae62795f2484217ad7480b12 (patch)
tree22f21f3015c773d8d57c7fa6eb35951ecb47af92 /eval/src/tests/instruction/generic_join
parente5a873f35ba72592c747e4c6eb9e7eafb0a0b462 (diff)
move reference operations to a common place
* lift reference implementations from unit tests * write a reference TensorCreate implementation * use these from unit tests * some minor cosmetic changes with structured bindings
Diffstat (limited to 'eval/src/tests/instruction/generic_join')
-rw-r--r--eval/src/tests/instruction/generic_join/generic_join_test.cpp22
1 files changed, 3 insertions, 19 deletions
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 558f20d2e10..a81294c8d25 100644
--- a/eval/src/tests/instruction/generic_join/generic_join_test.cpp
+++ b/eval/src/tests/instruction/generic_join/generic_join_test.cpp
@@ -5,6 +5,7 @@
#include <vespa/eval/eval/value_codec.h>
#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/vespalib/util/stringfmt.h>
#include <vespa/vespalib/gtest/gtest.h>
@@ -53,23 +54,6 @@ bool join_address(const TensorSpec::Address &a, const TensorSpec::Address &b, Te
return true;
}
-TensorSpec reference_join(const TensorSpec &a, const TensorSpec &b, join_fun_t function) {
- ValueType res_type = ValueType::join(ValueType::from_spec(a.type()), ValueType::from_spec(b.type()));
- EXPECT_FALSE(res_type.is_error());
- TensorSpec result(res_type.to_spec());
- for (const auto &cell_a: a.cells()) {
- for (const auto &cell_b: b.cells()) {
- TensorSpec::Address addr;
- if (join_address(cell_a.first, cell_b.first, addr) &&
- join_address(cell_b.first, cell_a.first, addr))
- {
- result.add(addr, function(cell_a.second, cell_b.second));
- }
- }
- }
- return result;
-}
-
TensorSpec perform_generic_join(const TensorSpec &a, const TensorSpec &b,
join_fun_t function, const ValueBuilderFactory &factory)
{
@@ -130,7 +114,7 @@ TEST(GenericJoinTest, generic_join_works_for_simple_and_fast_values) {
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 = reference_join(lhs, rhs, fun);
+ 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);
@@ -154,7 +138,7 @@ TEST(GenericJoinTest, immediate_generic_join_works) {
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 = reference_join(lhs, rhs, fun);
+ auto expect = ReferenceOperations::join(lhs, rhs, fun);
auto actual = immediate_generic_join(lhs, rhs, fun);
EXPECT_EQ(actual, expect);
}