diff options
author | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2015-10-21 11:28:28 -0700 |
---|---|---|
committer | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2015-10-21 11:28:28 -0700 |
commit | b178cc347968675bdae942dbdcb7de9ed9daa564 (patch) | |
tree | f2e931dd8bf7d8f6710264ac366f4673b01e736a /unsupported/test/cxx11_tensor_sugar.cpp | |
parent | 5ca2e25967ee82df3c2347223ad8a5cde5070eb6 (diff) |
Added some syntactic sugar to make it simpler to compare a tensor to a scalar.
Diffstat (limited to 'unsupported/test/cxx11_tensor_sugar.cpp')
-rw-r--r-- | unsupported/test/cxx11_tensor_sugar.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/unsupported/test/cxx11_tensor_sugar.cpp b/unsupported/test/cxx11_tensor_sugar.cpp new file mode 100644 index 000000000..7848acc8b --- /dev/null +++ b/unsupported/test/cxx11_tensor_sugar.cpp @@ -0,0 +1,38 @@ +#include "main.h" + +#include <Eigen/CXX11/Tensor> + +using Eigen::Tensor; +using Eigen::RowMajor; + +static void test_comparison_sugar() { + // we already trust comparisons between tensors, we're simply checking that + // the sugared versions are doing the same thing + Tensor<int, 3> t(6, 7, 5); + + t.setRandom(); + // make sure we have at least one value == 0 + t(0,0,0) = 0; + + Tensor<bool,1> b; + +#define TEST_TENSOR_EQUAL(e1, e2) \ + b = ((e1) == (e2)).all(); \ + VERIFY(b(0)) + +#define TEST_OP(op) TEST_TENSOR_EQUAL(t op 0, t op t.constant(0)) + + TEST_OP(==); + TEST_OP(!=); + TEST_OP(<=); + TEST_OP(>=); + TEST_OP(<); + TEST_OP(>); +#undef TEST_OP +#undef TEST_TENSOR_EQUAL +} + +void test_cxx11_tensor_sugar() +{ + CALL_SUBTEST(test_comparison_sugar()); +} |