mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
Make sure Grid::Serializable can write Eigen Tensors to output streams. NB:
1) The Eigen package defines operator<< for Eigen tensors, but this format is different, hence Grid::Serializable::WriteMember 2) For simplification, the contents are written in memory order. I.e. Different results will be obtained depending on whether the tensor is row- or column-major
This commit is contained in:
parent
82a77f9960
commit
f7b4fd0f69
@ -583,7 +583,27 @@ namespace Grid {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
static inline typename std::enable_if<EigenIO::is_tensor<T>::value, void>::type
|
static inline typename std::enable_if<EigenIO::is_tensor<T>::value, void>::type
|
||||||
WriteMember(std::ostream &os, const T &object) {
|
WriteMember(std::ostream &os, const T &object) {
|
||||||
os << "Eigen::Tensor";
|
using Index = typename T::Index;
|
||||||
|
const Index NumElements{object.size()};
|
||||||
|
assert( NumElements > 0 );
|
||||||
|
Index count = 1;
|
||||||
|
os << "T<";
|
||||||
|
for( int i = 0; i < T::NumIndices; i++ ) {
|
||||||
|
Index dim = object.dimension(i);
|
||||||
|
count *= dim;
|
||||||
|
if( i )
|
||||||
|
os << ",";
|
||||||
|
os << dim;
|
||||||
|
}
|
||||||
|
assert( count == NumElements && "Number of elements doesn't match tensor dimensions" );
|
||||||
|
os << ">{";
|
||||||
|
const typename T::Scalar * p = object.data();
|
||||||
|
for( Index i = 0; i < count; i++ ) {
|
||||||
|
if( i )
|
||||||
|
os << ",";
|
||||||
|
os << *p++;
|
||||||
|
}
|
||||||
|
os << "}";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user