From 410070e5ab75aed3f4e35424a59f5ea385fdc2e3 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Wed, 25 Feb 2015 16:14:59 -0800 Subject: Added more tests to validate support for tensors laid out in RowMajor order. --- unsupported/test/cxx11_tensor_morphing.cpp | 33 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'unsupported/test/cxx11_tensor_morphing.cpp') diff --git a/unsupported/test/cxx11_tensor_morphing.cpp b/unsupported/test/cxx11_tensor_morphing.cpp index 7fd7a283a..cf9fd4803 100644 --- a/unsupported/test/cxx11_tensor_morphing.cpp +++ b/unsupported/test/cxx11_tensor_morphing.cpp @@ -114,18 +114,19 @@ static void test_simple_slice() } } -// TODO(andydavis) Add RowMajor support when TensorContract supports RowMajor. +template static void test_slice_in_expr() { - MatrixXf m1(7,7); - MatrixXf m2(3,3); + typedef Matrix Mtx; + Mtx m1(7,7); + Mtx m2(3,3); m1.setRandom(); m2.setRandom(); - MatrixXf m3 = m1.block(1, 2, 3, 3) * m2.block(0, 2, 3, 1); + Mtx m3 = m1.block(1, 2, 3, 3) * m2.block(0, 2, 3, 1); - TensorMap> tensor1(m1.data(), 7, 7); - TensorMap> tensor2(m2.data(), 3, 3); - Tensor tensor3(3,1); + TensorMap> tensor1(m1.data(), 7, 7); + TensorMap> tensor2(m2.data(), 3, 3); + Tensor tensor3(3,1); typedef Tensor::DimensionPair DimPair; array contract_along{{DimPair(1, 0)}}; @@ -135,7 +136,7 @@ static void test_slice_in_expr() { Eigen::DSizes sizes2(3,1); tensor3 = tensor1.slice(indices1, sizes1).contract(tensor2.slice(indices2, sizes2), contract_along); - Map res(tensor3.data(), 3, 1); + Map res(tensor3.data(), 3, 1); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 1; ++j) { VERIFY_IS_APPROX(res(i,j), m3(i,j)); @@ -143,8 +144,8 @@ static void test_slice_in_expr() { } // Take an arbitrary slice of an arbitrarily sized tensor. - TensorMap> tensor4(m1.data(), 7, 7); - Tensor tensor6 = tensor4.reshape(DSizes(7*7)).exp().slice(DSizes(0), DSizes(35)); + TensorMap> tensor4(m1.data(), 7, 7); + Tensor tensor6 = tensor4.reshape(DSizes(7*7)).exp().slice(DSizes(0), DSizes(35)); for (int i = 0; i < 35; ++i) { VERIFY_IS_APPROX(tensor6(i), expf(tensor4.data()[i])); } @@ -304,14 +305,14 @@ static void test_slice_raw_data() VERIFY_IS_EQUAL(slice6.data(), tensor.data()); } - +template static void test_composition() { - Eigen::Tensor matrix(7, 11); + Eigen::Tensor matrix(7, 11); matrix.setRandom(); const DSizes newDims{{1, 1, 11}}; - Eigen::Tensor tensor = + Eigen::Tensor tensor = matrix.slice(DSizes(2, 0), DSizes(1, 11)).reshape(newDims); VERIFY_IS_EQUAL(tensor.dimensions().TotalSize(), 11ul); @@ -332,11 +333,13 @@ void test_cxx11_tensor_morphing() CALL_SUBTEST(test_simple_slice()); CALL_SUBTEST(test_simple_slice()); - CALL_SUBTEST(test_slice_in_expr()); + CALL_SUBTEST(test_slice_in_expr()); + CALL_SUBTEST(test_slice_in_expr()); CALL_SUBTEST(test_slice_as_lvalue()); CALL_SUBTEST(test_slice_as_lvalue()); CALL_SUBTEST(test_slice_raw_data()); CALL_SUBTEST(test_slice_raw_data()); - CALL_SUBTEST(test_composition()); + CALL_SUBTEST(test_composition()); + CALL_SUBTEST(test_composition()); } -- cgit v1.2.3