aboutsummaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-11-11 17:41:57 +0000
committerArne Juul <arnej@verizonmedia.com>2020-11-11 17:42:17 +0000
commit1594fe98bd25586887cb5ea2f395fcd12cc01912 (patch)
tree7d12c49d03baa6f6d1f7217943a40e8a6d705b45 /eval
parent3968f683fd4a6883d896cda698a34729e7338148 (diff)
try adding a utility and more tests
Diffstat (limited to 'eval')
-rw-r--r--eval/src/tests/instruction/join_with_number/join_with_number_function_test.cpp38
-rw-r--r--eval/src/vespa/eval/eval/test/param_variants.h23
2 files changed, 52 insertions, 9 deletions
diff --git a/eval/src/tests/instruction/join_with_number/join_with_number_function_test.cpp b/eval/src/tests/instruction/join_with_number/join_with_number_function_test.cpp
index a67fc3725ca..7f41ffe5bf3 100644
--- a/eval/src/tests/instruction/join_with_number/join_with_number_function_test.cpp
+++ b/eval/src/tests/instruction/join_with_number/join_with_number_function_test.cpp
@@ -5,6 +5,7 @@
#include <vespa/eval/eval/tensor_function.h>
#include <vespa/eval/eval/test/eval_fixture.h>
#include <vespa/eval/eval/test/tensor_model.hpp>
+#include <vespa/eval/eval/test/param_variants.h>
#include <vespa/eval/instruction/join_with_number_function.h>
#include <vespa/vespalib/util/stringfmt.h>
@@ -34,16 +35,17 @@ std::ostream &operator<<(std::ostream &os, Primary primary)
const ValueBuilderFactory &prod_factory = FastValueBuilderFactory::get();
EvalFixture::ParamRepo make_params() {
- return EvalFixture::ParamRepo()
+ auto repo = EvalFixture::ParamRepo()
.add("a", spec(1.5))
.add("number", spec(2.5))
- .add("sparse", spec({x({"a"})}, N()))
.add("dense", spec({y(5)}, N()))
- .add("mixed", spec({x({"a"}),y(5)}, N()))
- .add("mixed_float", spec(float_cells({x({"a"}),y(5)}), N()))
- .add("mixed_inplace", spec({x({"a"}),y(5)}, N()), true)
.add_matrix("x", 3, "y", 5);
+
+ add_variants(repo, "mixed", {x({"a"}),y(5),z({"d","e"})}, N());
+ add_variants(repo, "sparse", {x({"a","b","c"}),z({"d","e","f"})}, N());
+ return repo;
}
+
EvalFixture::ParamRepo param_repo = make_params();
void verify_optimized(const vespalib::string &expr, Primary primary, bool inplace) {
@@ -97,6 +99,24 @@ TEST("require that asymmetric operations work") {
TEST_DO(verify_optimized("a-x3y5f", Primary::RHS, false));
}
+TEST("require that sparse number join can be optimized") {
+ TEST_DO(verify_optimized("sparse+a", Primary::LHS, false));
+ TEST_DO(verify_optimized("a+sparse", Primary::RHS, false));
+ TEST_DO(verify_optimized("sparse<a", Primary::LHS, false));
+ TEST_DO(verify_optimized("a<sparse", Primary::RHS, false));
+ TEST_DO(verify_optimized("sparse_float+a", Primary::LHS, false));
+ TEST_DO(verify_optimized("a+sparse_float", Primary::RHS, false));
+ TEST_DO(verify_optimized("sparse_float<a", Primary::LHS, false));
+ TEST_DO(verify_optimized("a<sparse_float", Primary::RHS, false));
+}
+
+TEST("require that sparse number join can be inplace") {
+ TEST_DO(verify_optimized("sparse_mutable+a", Primary::LHS, true));
+ TEST_DO(verify_optimized("a+sparse_mutable", Primary::RHS, true));
+ TEST_DO(verify_optimized("sparse_mutable<a", Primary::LHS, true));
+ TEST_DO(verify_optimized("a<sparse_mutable", Primary::RHS, true));
+}
+
TEST("require that mixed number join can be optimized") {
TEST_DO(verify_optimized("mixed+a", Primary::LHS, false));
TEST_DO(verify_optimized("a+mixed", Primary::RHS, false));
@@ -109,10 +129,10 @@ TEST("require that mixed number join can be optimized") {
}
TEST("require that mixed number join can be inplace") {
- TEST_DO(verify_optimized("mixed_inplace+a", Primary::LHS, true));
- TEST_DO(verify_optimized("a+mixed_inplace", Primary::RHS, true));
- TEST_DO(verify_optimized("mixed_inplace<a", Primary::LHS, true));
- TEST_DO(verify_optimized("a<mixed_inplace", Primary::RHS, true));
+ TEST_DO(verify_optimized("mixed_mutable+a", Primary::LHS, true));
+ TEST_DO(verify_optimized("a+mixed_mutable", Primary::RHS, true));
+ TEST_DO(verify_optimized("mixed_mutable<a", Primary::LHS, true));
+ TEST_DO(verify_optimized("a<mixed_mutable", Primary::RHS, true));
}
TEST("require that all appropriate cases are optimized, others not") {
diff --git a/eval/src/vespa/eval/eval/test/param_variants.h b/eval/src/vespa/eval/eval/test/param_variants.h
new file mode 100644
index 00000000000..880199b42ff
--- /dev/null
+++ b/eval/src/vespa/eval/eval/test/param_variants.h
@@ -0,0 +1,23 @@
+#include "eval_fixture.h"
+#include "tensor_model.hpp"
+
+namespace vespalib::eval::test {
+
+// for testing of optimizers / tensor functions
+// we produce the same param three times:
+// as-is, with float cells, and tagged as mutable.
+EvalFixture::ParamRepo &
+add_variants(EvalFixture::ParamRepo &repo,
+ const vespalib::string &name_base,
+ const Layout &base_layout,
+ const Sequence &seq)
+{
+ auto name_f = name_base + "_float";
+ auto name_m = name_base + "_mutable";
+ repo.add(name_base, spec(base_layout, seq), false);
+ repo.add(name_f, spec(float_cells(base_layout), seq), false);
+ repo.add(name_m, spec(base_layout, seq), true);
+ return repo;
+}
+
+} // namespace