summaryrefslogtreecommitdiffstats
path: root/vespalib/src
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@gmail.com>2016-10-10 15:58:49 +0200
committerGitHub <noreply@github.com>2016-10-10 15:58:49 +0200
commit1afa5f14fbaf6ca722abdd8562a44b0bde7b4368 (patch)
tree87604f48a3b89da731fa8b652a7f68ef22b9cb91 /vespalib/src
parent6abdd3d8960ce01422e0cc902cba7e2fa9facc67 (diff)
parentb8adfd0e81908054dacba530ad7f8e2af6e7bab7 (diff)
Merge pull request #827 from yahoo/toregge/test-fixed-sparse-cases-in-tensor-conformance-test
Copy relevant tests from tensor operation tests (sparse tensors) to t…
Diffstat (limited to 'vespalib/src')
-rw-r--r--vespalib/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp4
-rw-r--r--vespalib/src/vespa/vespalib/eval/test/tensor_conformance.cpp176
-rw-r--r--vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor.cpp4
3 files changed, 179 insertions, 5 deletions
diff --git a/vespalib/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp b/vespalib/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp
index 39e82abec7d..0d157012a90 100644
--- a/vespalib/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp
+++ b/vespalib/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp
@@ -66,8 +66,8 @@ TEST("require that tensor can be converted to tensor spec")
{
Tensor::UP tensor = buildTensor();
TensorSpec expSpec("tensor(a{},b{},c{},d{})");
- expSpec.add({{"a", "1"}, {"b", "2"}}, 10).
- add({{"c", "3"}, {"d", "4"}}, 20);
+ expSpec.add({{"a", "1"}, {"b", "2"}, {"c", ""}, {"d", ""}}, 10).
+ add({{"a", ""},{"b",""},{"c", "3"}, {"d", "4"}}, 20);
TensorSpec actSpec = tensor->toSpec();
EXPECT_EQUAL(expSpec, actSpec);
}
diff --git a/vespalib/src/vespa/vespalib/eval/test/tensor_conformance.cpp b/vespalib/src/vespa/vespalib/eval/test/tensor_conformance.cpp
index 00aee32b99a..3b0a0359b43 100644
--- a/vespalib/src/vespa/vespalib/eval/test/tensor_conformance.cpp
+++ b/vespalib/src/vespa/vespalib/eval/test/tensor_conformance.cpp
@@ -231,6 +231,16 @@ TensorSpec spec() {
return spec(Layout({}));
}
+TensorSpec spec(const vespalib::string &type,
+ const std::vector<std::pair<TensorSpec::Address, TensorSpec::Value>> &cells) {
+ TensorSpec spec("tensor(" + type + ")");
+
+ for (const auto &cell : cells) {
+ spec.add(cell.first, cell.second);
+ }
+ return spec;
+}
+
// abstract evaluation wrapper
struct Eval {
// typed result wrapper
@@ -711,6 +721,171 @@ struct TestContext {
//-------------------------------------------------------------------------
+ void test_apply_op(const Eval &eval,
+ const TensorSpec &expect,
+ const TensorSpec &lhs,
+ const TensorSpec &rhs) {
+ EXPECT_EQUAL(safe(eval).eval(engine, lhs, rhs).tensor(), expect);
+ }
+
+ void test_fixed_sparse_cases_apply_op(const Eval &eval,
+ const BinaryOperation &op)
+ {
+ TEST_DO(test_apply_op(eval,
+ spec("x{}", {}),
+ spec("x{}", { { {{"x","1"}}, 3 } }),
+ spec("x{}", { { {{"x","2"}}, 5 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{}", { { {{"x","1"}}, op.eval(3,5) } }),
+ spec("x{}", { { {{"x","1"}}, 3 } }),
+ spec("x{}", { { {{"x","1"}}, 5 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{}", { { {{"x","1"}}, op.eval(3,-5) } }),
+ spec("x{}", { { {{"x","1"}}, 3 } }),
+ spec("x{}", { { {{"x","1"}}, -5 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{},y{},z{}",
+ { { {{"x","-"},{"y","2"},{"z","-"}},
+ op.eval(5,7) },
+ { {{"x","1"},{"y","-"},{"z","3"}},
+ op.eval(3,11) } }),
+ spec("x{},y{}",
+ { { {{"x","-"},{"y","2"}}, 5 },
+ { {{"x","1"},{"y","-"}}, 3 } }),
+ spec("y{},z{}",
+ { { {{"y","-"},{"z","3"}}, 11 },
+ { {{"y","2"},{"z","-"}}, 7 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{},y{},z{}",
+ { { {{"x","-"},{"y","2"},{"z","-"}},
+ op.eval(7,5) },
+ { {{"x","1"},{"y","-"},{"z","3"}},
+ op.eval(11,3) } }),
+ spec("y{},z{}",
+ { { {{"y","-"},{"z","3"}}, 11 },
+ { {{"y","2"},{"z","-"}}, 7 } }),
+ spec("x{},y{}",
+ { { {{"x","-"},{"y","2"}}, 5 },
+ { {{"x","1"},{"y","-"}}, 3 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("y{},z{}",
+ { { {{"y","2"},{"z","-"}},
+ op.eval(5,7) } }),
+ spec("y{}", { { {{"y","2"}}, 5 } }),
+ spec("y{},z{}",
+ { { {{"y","-"},{"z","3"}}, 11 },
+ { {{"y","2"},{"z","-"}}, 7 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("y{},z{}",
+ { { {{"y","2"},{"z","-"}},
+ op.eval(7,5) } }),
+ spec("y{},z{}",
+ { { {{"y","-"},{"z","3"}}, 11 },
+ { {{"y","2"},{"z","-"}}, 7 } }),
+ spec("y{}", { { {{"y","2"}}, 5 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{},y{}",
+ { { {{"x","-"},{"y","2"}},
+ op.eval(5,7) } }),
+ spec("x{},y{}",
+ { { {{"x","-"},{"y","2"}}, 5 },
+ { {{"x","1"},{"y","-"}}, 3 } }),
+ spec("y{}", { { {{"y","2"}}, 7 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{},y{}",
+ { { {{"x","-"},{"y","2"}},
+ op.eval(7,5) } }),
+ spec("y{}", { { {{"y","2"}}, 7 } }),
+ spec("x{},y{}",
+ { { {{"x","-"},{"y","2"}}, 5 },
+ { {{"x","1"},{"y","-"}}, 3 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{},z{}",
+ { { {{"x","1"},{"z","3"}},
+ op.eval(3,11) } }),
+ spec("x{}", { { {{"x","1"}}, 3 } }),
+ spec("z{}", { { {{"z","3"}}, 11 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{},z{}",
+ { { {{"x","1"},{"z","3"}},
+ op.eval(11,3) } }),
+ spec("z{}",{ { {{"z","3"}}, 11 } }),
+ spec("x{}",{ { {{"x","1"}}, 3 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{},y{}",
+ { { {{"x","1"},{"y","1"}},
+ op.eval(3,5) },
+ { {{"x","2"},{"y","1"}},
+ op.eval(7,5) } }),
+ spec("x{}",
+ { { {{"x","1"}}, 3 },
+ { {{"x","2"}}, 7 } }),
+ spec("y{}",
+ { { {{"y","1"}}, 5 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{},y{},z{}",
+ { { {{"x","1"},{"y","1"},{"z","1"}},
+ op.eval(1,7) },
+ { {{"x","1"},{"y","1"},{"z","2"}},
+ op.eval(1,13) },
+ { {{"x","1"},{"y","2"},{"z","1"}},
+ op.eval(5,11) },
+ { {{"x","2"},{"y","1"},{"z","1"}},
+ op.eval(3,7) },
+ { {{"x","2"},{"y","1"},{"z","2"}},
+ op.eval(3,13) } }),
+ spec("x{},y{}",
+ { { {{"x","1"},{"y","1"}}, 1 },
+ { {{"x","1"},{"y","2"}}, 5 },
+ { {{"x","2"},{"y","1"}}, 3 } }),
+ spec("y{},z{}",
+ { { {{"y","1"},{"z","1"}}, 7 },
+ { {{"y","1"},{"z","2"}}, 13 },
+ { {{"y","2"},{"z","1"}}, 11 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{},y{},z{}",
+ { { {{"x","1"},{"y","1"},{"z","1"}},
+ op.eval(1,7) } }),
+ spec("x{},y{}",
+ { { {{"x","1"},{"y","-"}}, 5 },
+ { {{"x","1"},{"y","1"}}, 1 } }),
+ spec("y{},z{}",
+ { { {{"y","1"},{"z","1"}}, 7 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{},y{},z{}",
+ { { {{"x","1"},{"y","-"},{"z","1"}},
+ op.eval(5,11) },
+ { {{"x","1"},{"y","1"},{"z","1"}},
+ op.eval(1,7) } }),
+ spec("x{},y{}",
+ { { {{"x","1"},{"y","-"}}, 5 },
+ { {{"x","1"},{"y","1"}}, 1 } }),
+ spec("y{},z{}",
+ { { {{"y","-"},{"z","1"}}, 11 },
+ { {{"y","1"},{"z","1"}}, 7 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{},y{},z{}",
+ { { {{"x","1"},{"y","1"},{"z","1"}},
+ op.eval(1,7) } }),
+ spec("x{},y{}",
+ { { {{"x","-"},{"y","-"}}, 5 },
+ { {{"x","1"},{"y","1"}}, 1 } }),
+ spec("y{},z{}",
+ { { {{"y","1"},{"z","1"}}, 7 } })));
+ TEST_DO(test_apply_op(eval,
+ spec("x{},y{},z{}",
+ { { {{"x","-"},{"y","-"},{"z", "-"}},
+ op.eval(5,11) },
+ { {{"x","1"},{"y","1"},{"z","1"}},
+ op.eval(1,7) } }),
+ spec("x{},y{}",
+ { { {{"x","-"},{"y","-"}}, 5 },
+ { {{"x","1"},{"y","1"}}, 1 } }),
+ spec("y{},z{}",
+ { { {{"y","-"},{"z","-"}}, 11 },
+ { {{"y","1"},{"z","1"}}, 7 } })));
+ }
+
void test_apply_op(const Eval &eval, const BinaryOperation &op, const Sequence &seq) {
std::vector<Layout> layouts = {
{}, {},
@@ -743,6 +918,7 @@ struct TestContext {
TensorSpec expect = ImmediateApply(op).eval(ref_engine, lhs_input, rhs_input).tensor();
EXPECT_EQUAL(safe(eval).eval(engine, lhs_input, rhs_input).tensor(), expect);
}
+ TEST_DO(test_fixed_sparse_cases_apply_op(eval, op));
}
void test_apply_op(const vespalib::string &expr, const BinaryOperation &op, const Sequence &seq) {
diff --git a/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor.cpp b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor.cpp
index 5e7ec5b1db3..024d63572c6 100644
--- a/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor.cpp
+++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor.cpp
@@ -223,9 +223,7 @@ buildAddress(const SparseTensor::Dimensions &dimensions,
{
for (const auto &dimension : dimensions) {
auto label = decoder.decodeLabel();
- if (!label.empty()) {
- address.emplace(std::make_pair(dimension, TensorSpec::Label(label)));
- }
+ address.emplace(std::make_pair(dimension, TensorSpec::Label(label)));
}
assert(!decoder.valid());
}