diff options
author | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2015-01-14 15:46:04 -0800 |
---|---|---|
committer | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2015-01-14 15:46:04 -0800 |
commit | b5124e7cfda27ed99dcfcec8cb1b674efa1ef4a3 (patch) | |
tree | 7f8378843a756af14785e563689b4765e062a953 /unsupported/test/cxx11_tensor_striding.cpp | |
parent | 54e3633b437e44ed4d370c9f8868535192308ca3 (diff) |
Created many additional tests
Diffstat (limited to 'unsupported/test/cxx11_tensor_striding.cpp')
-rw-r--r-- | unsupported/test/cxx11_tensor_striding.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/unsupported/test/cxx11_tensor_striding.cpp b/unsupported/test/cxx11_tensor_striding.cpp index 502569d1d..1feb39dca 100644 --- a/unsupported/test/cxx11_tensor_striding.cpp +++ b/unsupported/test/cxx11_tensor_striding.cpp @@ -13,9 +13,10 @@ using Eigen::Tensor; +template<int DataLayout> static void test_simple_striding() { - Tensor<float, 4> tensor(2,3,5,7); + Tensor<float, 4, DataLayout> tensor(2,3,5,7); tensor.setRandom(); array<ptrdiff_t, 4> strides; strides[0] = 1; @@ -23,7 +24,7 @@ static void test_simple_striding() strides[2] = 1; strides[3] = 1; - Tensor<float, 4> no_stride; + Tensor<float, 4, DataLayout> no_stride; no_stride = tensor.stride(strides); VERIFY_IS_EQUAL(no_stride.dimension(0), 2); @@ -45,7 +46,7 @@ static void test_simple_striding() strides[1] = 4; strides[2] = 2; strides[3] = 3; - Tensor<float, 4> stride; + Tensor<float, 4, DataLayout> stride; stride = tensor.stride(strides); VERIFY_IS_EQUAL(stride.dimension(0), 1); @@ -65,7 +66,36 @@ static void test_simple_striding() } +template<int DataLayout> +static void test_striding_as_lvalue() +{ + Tensor<float, 4, DataLayout> tensor(2,3,5,7); + tensor.setRandom(); + array<ptrdiff_t, 4> strides; + strides[0] = 2; + strides[1] = 4; + strides[2] = 2; + strides[3] = 3; + + Tensor<float, 4, DataLayout> result(3, 12, 10, 21); + result.stride(strides) = tensor; + + for (int i = 0; i < 2; ++i) { + for (int j = 0; j < 3; ++j) { + for (int k = 0; k < 5; ++k) { + for (int l = 0; l < 7; ++l) { + VERIFY_IS_EQUAL(tensor(i,j,k,l), result(2*i,4*j,2*k,3*l)); + } + } + } + } +} + + void test_cxx11_tensor_striding() { - CALL_SUBTEST(test_simple_striding()); + CALL_SUBTEST(test_simple_striding<ColMajor>()); + CALL_SUBTEST(test_simple_striding<RowMajor>()); + CALL_SUBTEST(test_striding_as_lvalue<ColMajor>()); + CALL_SUBTEST(test_striding_as_lvalue<RowMajor>()); } |