1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-06-18 15:57:05 +01:00

Can write both fixed and dynamic sized tensors (small tidy)

This commit is contained in:
2019-02-11 17:15:38 +00:00
parent dff7d9261d
commit 9a225235b6
2 changed files with 51 additions and 85 deletions

View File

@ -62,9 +62,6 @@ namespace Grid {
void write(const std::string &s, const iVector<U, N> &output);
template <typename U, int N>
void write(const std::string &s, const iMatrix<U, N> &output);
/*template <typename Scalar_, int NumIndices_, int Options_, typename IndexType_>
typename std::enable_if<std::is_arithmetic<Scalar_>::value || Grid::is_complex<Scalar_>::value, void>::type
write(const std::string &s, const Eigen::Tensor<Scalar_, NumIndices_, Options_, IndexType_> &output);*/
template <typename ETensor>
typename std::enable_if<std::is_base_of<Eigen::TensorBase<ETensor, Eigen::ReadOnlyAccessors>, ETensor>::value && (std::is_arithmetic<typename ETensor::Scalar>::value || Grid::is_complex<typename ETensor::Scalar>::value), void>::type
write(const std::string &s, const ETensor &output);
@ -181,15 +178,10 @@ namespace Grid {
// Eigen::Tensors of arithmetic/complex base type
template <typename T>
/*template <typename Scalar_, int NumIndices_, int Options_, typename IndexType_>
typename std::enable_if<std::is_arithmetic<Scalar_>::value || Grid::is_complex<Scalar_>::value, void>::type
Writer<T>::write(const std::string &s, const Eigen::Tensor<Scalar_, NumIndices_, Options_, IndexType_> &output)*/
template <typename ETensor>
typename std::enable_if<std::is_base_of<Eigen::TensorBase<ETensor, Eigen::ReadOnlyAccessors>, ETensor>::value && (std::is_arithmetic<typename ETensor::Scalar>::value || Grid::is_complex<typename ETensor::Scalar>::value), void>::type
Writer<T>::write(const std::string &s, const ETensor &output)
{
//typedef Eigen::Tensor<Scalar_, NumIndices_, Options_, IndexType_> Tensor;
//typedef Eigen::TensorBase<ETensor, Eigen::ReadOnlyAccessors> Tensor;
const typename ETensor::Index NumElements{output.size()};
assert( NumElements > 0 );
if( NumElements == 1 )
@ -394,6 +386,18 @@ namespace Grid {
Eigen::Tensor<bool, 0> bResult = (lhs == rhs).all();
return bResult(0);
}
template <typename T>
static inline typename std::enable_if<std::is_base_of<Eigen::TensorBase<T, Eigen::ReadOnlyAccessors>, T>::value, bool>::type
CompareMember(const std::vector<T> &lhs, const std::vector<T> &rhs) {
const auto NumElements{lhs.size()};
bool bResult = ( NumElements == rhs.size() );
for( auto i = 0 ; i < NumElements && bResult ; i++ ) {
Eigen::Tensor<bool, 0> b = (lhs[i] == rhs[i]).all();
bResult = b(0);
}
return bResult;
}
};
// Generic writer interface //////////////////////////////////////////////////