diff options
author | Tor Egge <Tor.Egge@yahoo-inc.com> | 2016-10-11 11:49:57 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@yahoo-inc.com> | 2016-10-11 11:49:57 +0000 |
commit | a7bf4f274f35cde713b6a591211a0ea7b724df53 (patch) | |
tree | 58bee630fbae6230d6c42186faf8fc9d0c4346f4 /vespalib/src | |
parent | 11e2a463f017e734bfdb32433dec45510a42aeb6 (diff) |
Copy relevant tests from operation tests (dense tensors) to
tensor conformance test.
Consider tensor spec cell values to be equal if both are nans.
Diffstat (limited to 'vespalib/src')
-rw-r--r-- | vespalib/src/vespa/vespalib/eval/tensor_spec.h | 4 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/eval/test/tensor_conformance.cpp | 45 |
2 files changed, 48 insertions, 1 deletions
diff --git a/vespalib/src/vespa/vespalib/eval/tensor_spec.h b/vespalib/src/vespa/vespalib/eval/tensor_spec.h index 41c1f8d4f3c..e66b494c92f 100644 --- a/vespalib/src/vespa/vespalib/eval/tensor_spec.h +++ b/vespalib/src/vespa/vespalib/eval/tensor_spec.h @@ -41,7 +41,9 @@ public: double value; Value(double value_in) : value(value_in) {} operator double() const { return value; } - bool operator==(const Value &rhs) const { return approx_equal(value, rhs.value); } + bool isNan() const { return std::isnan(value); } + bool isNans(const Value &rhs) const { return isNan() && rhs.isNan(); } + bool operator==(const Value &rhs) const { return isNans(rhs) || approx_equal(value, rhs.value); } }; using Address = std::map<vespalib::string,Label>; using Cells = std::map<Address,Value>; diff --git a/vespalib/src/vespa/vespalib/eval/test/tensor_conformance.cpp b/vespalib/src/vespa/vespalib/eval/test/tensor_conformance.cpp index 3b0a0359b43..3be8cb048a0 100644 --- a/vespalib/src/vespa/vespalib/eval/test/tensor_conformance.cpp +++ b/vespalib/src/vespa/vespalib/eval/test/tensor_conformance.cpp @@ -886,6 +886,50 @@ struct TestContext { { {{"y","1"},{"z","1"}}, 7 } }))); } + void test_fixed_dense_cases_apply_op(const Eval &eval, + const BinaryOperation &op) + { + TEST_DO(test_apply_op(eval, + spec(op.eval(0,0)), spec(0.0), spec(0.0))); + TEST_DO(test_apply_op(eval, + spec(x(1), Seq({ op.eval(3,5) })), + spec(x(1), Seq({ 3 })), + spec(x(1), Seq({ 5 })))); + TEST_DO(test_apply_op(eval, + spec(x(1), Seq({ op.eval(3,-5) })), + spec(x(1), Seq({ 3 })), + spec(x(1), Seq({ -5 })))); + TEST_DO(test_apply_op(eval, + spec(x(2), Seq({ op.eval(3,7), op.eval(5,11) })), + spec(x(2), Seq({ 3, 5 })), + spec(x(2), Seq({ 7, 11 })))); + TEST_DO(test_apply_op(eval, + spec({x(1),y(1)}, Seq({ op.eval(3,5) })), + spec({x(1),y(1)}, Seq({ 3 })), + spec({x(1),y(1)}, Seq({ 5 })))); + TEST_DO(test_apply_op(eval, + spec(x(1), Seq({ op.eval(3, 0) })), + spec(x(1), Seq({ 3 })), + spec(x(2), Seq({ 0, 7 })))); + TEST_DO(test_apply_op(eval, + spec(x(1), Seq({ op.eval(0, 5) })), + spec(x(2), Seq({ 0, 3 })), + spec(x(1), Seq({ 5 })))); + TEST_DO(test_apply_op(eval, + spec({x(2),y(2),z(2)}, + Seq({ op.eval(1, 7), op.eval(1, 11), + op.eval(2, 13), op.eval(2, 17), + op.eval(3, 7), op.eval(3, 11), + op.eval(5, 13), op.eval(5, 17) + })), + spec({x(2),y(2)}, + Seq({ 1, 2, + 3, 5 })), + spec({y(2),z(2)}, + Seq({ 7, 11, + 13, 17 })))); + } + void test_apply_op(const Eval &eval, const BinaryOperation &op, const Sequence &seq) { std::vector<Layout> layouts = { {}, {}, @@ -919,6 +963,7 @@ struct TestContext { EXPECT_EQUAL(safe(eval).eval(engine, lhs_input, rhs_input).tensor(), expect); } TEST_DO(test_fixed_sparse_cases_apply_op(eval, op)); + TEST_DO(test_fixed_dense_cases_apply_op(eval, op)); } void test_apply_op(const vespalib::string &expr, const BinaryOperation &op, const Sequence &seq) { |