From e5f25622e20563d35d51de356379bdfd257f1d67 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Mon, 7 Mar 2016 09:04:27 -0800 Subject: Added a test to validate the behavior of some of the tensor syntactic sugar. --- unsupported/test/cxx11_tensor_sugar.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'unsupported/test/cxx11_tensor_sugar.cpp') diff --git a/unsupported/test/cxx11_tensor_sugar.cpp b/unsupported/test/cxx11_tensor_sugar.cpp index adac472cf..a03f75cfe 100644 --- a/unsupported/test/cxx11_tensor_sugar.cpp +++ b/unsupported/test/cxx11_tensor_sugar.cpp @@ -32,7 +32,30 @@ static void test_comparison_sugar() { #undef TEST_TENSOR_EQUAL } + +static void test_scalar_sugar() { + Tensor A(6, 7, 5); + Tensor B(6, 7, 5); + A.setRandom(); + B.setRandom(); + + const float alpha = 0.43f; + const float beta = 0.21f; + + Tensor R = A * A.constant(alpha) + B * B.constant(beta); + Tensor S = A * alpha + B * beta; + + // TODO: add enough syntactic sugar to support this + // Tensor T = alpha * A + beta * B; + + for (int i = 0; i < 6*7*5; ++i) { + VERIFY_IS_APPROX(R(i), S(i)); + } +} + + void test_cxx11_tensor_sugar() { CALL_SUBTEST(test_comparison_sugar()); + CALL_SUBTEST(test_scalar_sugar()); } -- cgit v1.2.3