Make the new TensorIO implementation work with TensorMap with const elements.

This commit is contained in:
Rasmus Munk Larsen
2021-11-17 18:16:04 -08:00
parent 824d06eb36
commit 96aeffb013
2 changed files with 15 additions and 2 deletions

View File

@@ -90,6 +90,16 @@ void test_tensor_ostream() {
test_tensor_ostream_impl<Scalar, rank, Layout>::run();
}
void test_const_tensor_ostream() {
Eigen::Tensor<float, 0> t;
t.setValues(1);
const Eigen::TensorMap<Eigen::Tensor<const float, 0, Eigen::RowMajor>, Eigen::Unaligned> t_const(
t.data(), Eigen::DSizes<Eigen::DenseIndex, 0>{});
std::ostringstream os;
os << t_const.format(Eigen::TensorIOFormat::Plain());
VERIFY(os.str() == "1");
}
EIGEN_DECLARE_TEST(cxx11_tensor_io) {
CALL_SUBTEST((test_tensor_ostream<float, 0, Eigen::ColMajor>()));
CALL_SUBTEST((test_tensor_ostream<float, 1, Eigen::ColMajor>()));
@@ -126,4 +136,7 @@ EIGEN_DECLARE_TEST(cxx11_tensor_io) {
CALL_SUBTEST((test_tensor_ostream<std::complex<double>, 2, Eigen::ColMajor>()));
CALL_SUBTEST((test_tensor_ostream<std::complex<float>, 2, Eigen::ColMajor>()));
// Test printing TensorMap with const elements.
CALL_SUBTEST((test_const_tensor_ostream()));
}