aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/test/cxx11_tensor_map.cpp
diff options
context:
space:
mode:
authorGravatar Eugene Zhulenev <ezhulenev@google.com>2019-09-03 11:38:39 -0700
committerGravatar Eugene Zhulenev <ezhulenev@google.com>2019-09-03 11:38:39 -0700
commita8d264fa9c56e42f77e2129d4e504f5c854821c2 (patch)
tree43fa648412bec3bc05307d5fa254f046d361d9f5 /unsupported/test/cxx11_tensor_map.cpp
parentf68f2bba09b556d98e314600676304193e60cfcb (diff)
Add test for const TensorMap underlying data mutation
Diffstat (limited to 'unsupported/test/cxx11_tensor_map.cpp')
-rw-r--r--unsupported/test/cxx11_tensor_map.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/unsupported/test/cxx11_tensor_map.cpp b/unsupported/test/cxx11_tensor_map.cpp
index dc8532f5c..4d4f68911 100644
--- a/unsupported/test/cxx11_tensor_map.cpp
+++ b/unsupported/test/cxx11_tensor_map.cpp
@@ -288,6 +288,30 @@ static void test_0d_const_tensor()
VERIFY_IS_EQUAL(scalar4(), 13);
}
+static void test_0d_const_tensor_map()
+{
+ Tensor<int, 0> scalar1;
+ Tensor<int, 0, RowMajor> scalar2;
+
+ const TensorMap<Tensor<int, 0> > scalar3(scalar1.data());
+ const TensorMap<Tensor<int, 0, RowMajor> > scalar4(scalar2.data());
+
+ // Although TensorMap is constant, we still can write to the underlying
+ // storage, because we map over non-constant Tensor.
+ scalar3() = 7;
+ scalar4() = 13;
+
+ VERIFY_IS_EQUAL(scalar1(), 7);
+ VERIFY_IS_EQUAL(scalar2(), 13);
+
+ // Pointer to the underlying storage is also non-const.
+ scalar3.data()[0] = 8;
+ scalar4.data()[0] = 14;
+
+ VERIFY_IS_EQUAL(scalar1(), 8);
+ VERIFY_IS_EQUAL(scalar2(), 14);
+}
+
EIGEN_DECLARE_TEST(cxx11_tensor_map)
{
CALL_SUBTEST(test_0d());
@@ -299,4 +323,5 @@ EIGEN_DECLARE_TEST(cxx11_tensor_map)
CALL_SUBTEST(test_casting());
CALL_SUBTEST(test_0d_const_tensor());
+ CALL_SUBTEST(test_0d_const_tensor_map());
}