mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
Fixed existing bug in Hdf5Reader::readDefault for std::vector<U>
This commit is contained in:
parent
00e9416e0a
commit
74a3a5b825
@ -213,13 +213,42 @@ namespace Grid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper to dump a tensor
|
||||||
|
#ifdef DEBUG
|
||||||
|
template <typename T>
|
||||||
|
typename std::enable_if<EigenIO::is_tensor<T>::value, void>::type
|
||||||
|
dump_tensor_func(T &t, const char * pName = nullptr)
|
||||||
|
{
|
||||||
|
using Traits = typename EigenIO::Traits<typename T::Scalar>;
|
||||||
|
const auto rank{T::NumIndices};
|
||||||
|
const auto &dims = t.dimensions();
|
||||||
|
std::cout << "Dumping rank " << rank << ((T::Options & Eigen::RowMajor) ? ", row" : ", column") << "-major tensor ";
|
||||||
|
if( pName )
|
||||||
|
std::cout << pName;
|
||||||
|
for( auto i = 0 ; i < rank; i++ ) std::cout << "[" << dims[i] << "]";
|
||||||
|
std::cout << " in memory order:" << std::endl;
|
||||||
|
for_all( t, [&](typename Traits::scalar_type &c, typename T::Index index, const std::array<size_t, T::NumIndices + Traits::rank_non_trivial> Dims ){
|
||||||
|
std::cout << " ";
|
||||||
|
for( auto dim : Dims )
|
||||||
|
std::cout << "[" << dim << "]";
|
||||||
|
std::cout << " = " << c << std::endl;
|
||||||
|
} );
|
||||||
|
std::cout << "========================================" << std::endl;
|
||||||
|
}
|
||||||
|
#define dump_tensor(args...) dump_tensor_func(args)
|
||||||
|
#else
|
||||||
|
#define dump_tensor(args...)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Helper to dump a tensor in memory order
|
// Helper to dump a tensor in memory order
|
||||||
|
// Kind of superfluous given the above
|
||||||
|
#ifdef DEBUG
|
||||||
template <typename T>
|
template <typename T>
|
||||||
typename std::enable_if<EigenIO::is_tensor_of_scalar<T>::value, void>::type
|
typename std::enable_if<EigenIO::is_tensor_of_scalar<T>::value, void>::type
|
||||||
DumpMemoryOrder(T t, const char * pName = nullptr)
|
DumpMemoryOrder(T &t, const char * pName = nullptr)
|
||||||
{
|
{
|
||||||
const auto dims = t.dimensions();
|
|
||||||
const auto rank = t.rank();
|
const auto rank = t.rank();
|
||||||
|
const auto &dims = t.dimensions();
|
||||||
std::cout << "Dumping rank " << rank << ((T::Options & Eigen::RowMajor) ? ", row" : ", column") << "-major tensor ";
|
std::cout << "Dumping rank " << rank << ((T::Options & Eigen::RowMajor) ? ", row" : ", column") << "-major tensor ";
|
||||||
if( pName )
|
if( pName )
|
||||||
std::cout << pName;
|
std::cout << pName;
|
||||||
@ -258,6 +287,7 @@ namespace Grid {
|
|||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Abstract writer/reader classes ////////////////////////////////////////////
|
// Abstract writer/reader classes ////////////////////////////////////////////
|
||||||
// static polymorphism implemented using CRTP idiom
|
// static polymorphism implemented using CRTP idiom
|
||||||
|
@ -215,7 +215,7 @@ namespace Grid
|
|||||||
// read the flat vector
|
// read the flat vector
|
||||||
std::vector<Element> buf(size);
|
std::vector<Element> buf(size);
|
||||||
|
|
||||||
if (size > dataSetThres_)
|
if (size * sizeof(Element) > dataSetThres_)
|
||||||
{
|
{
|
||||||
H5NS::DataSet dataSet;
|
H5NS::DataSet dataSet;
|
||||||
|
|
||||||
|
@ -101,20 +101,6 @@ void ioTest(const std::string &filename, const O &object, const std::string &nam
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
template <typename T>
|
|
||||||
//typename std::enable_if<EigenIO::is_tensor<T>::value, void>::type
|
|
||||||
void dump_tensor(T & t)
|
|
||||||
{
|
|
||||||
using Traits = typename EigenIO::Traits<typename T::Scalar>;
|
|
||||||
for_all( t, [&](typename Traits::scalar_type &c, typename T::Index index, const std::size_t * pDims ){
|
|
||||||
std::cout << " ";
|
|
||||||
for( int i = 0 ; i < t.NumDimensions + Traits::rank_non_trivial; i++ )
|
|
||||||
std::cout << "[" << pDims[i] << "]";
|
|
||||||
std::cout << " = " << c << std::endl;
|
|
||||||
} );
|
|
||||||
std::cout << "========================================" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
//typedef int TestScalar;
|
//typedef int TestScalar;
|
||||||
typedef std::complex<double> TestScalar;
|
typedef std::complex<double> TestScalar;
|
||||||
typedef Eigen::Tensor<iMatrix<TestScalar,1>, 6> TestTensorSingle;
|
typedef Eigen::Tensor<iMatrix<TestScalar,1>, 6> TestTensorSingle;
|
||||||
@ -159,8 +145,7 @@ bool EigenIOTest(void) {
|
|||||||
Val += Inc;
|
Val += Inc;
|
||||||
}
|
}
|
||||||
ioTest<Hdf5Writer, Hdf5Reader, TestTensor>("iotest_tensor.h5", t, "eigen_tensor_instance_name");
|
ioTest<Hdf5Writer, Hdf5Reader, TestTensor>("iotest_tensor.h5", t, "eigen_tensor_instance_name");
|
||||||
std::cout << "t:";
|
dump_tensor(t, "t");
|
||||||
dump_tensor(t);
|
|
||||||
|
|
||||||
// Now serialise a fixed size tensor
|
// Now serialise a fixed size tensor
|
||||||
using FixedTensor = Eigen::TensorFixedSize<TestScalar, Eigen::Sizes<8,4,3>>;
|
using FixedTensor = Eigen::TensorFixedSize<TestScalar, Eigen::Sizes<8,4,3>>;
|
||||||
@ -173,8 +158,7 @@ bool EigenIOTest(void) {
|
|||||||
Val += Inc;
|
Val += Inc;
|
||||||
}
|
}
|
||||||
ioTest<Hdf5Writer, Hdf5Reader, FixedTensor>("iotest_tensor_fixed.h5", tf, "eigen_tensor_fixed_name");
|
ioTest<Hdf5Writer, Hdf5Reader, FixedTensor>("iotest_tensor_fixed.h5", tf, "eigen_tensor_fixed_name");
|
||||||
std::cout << "tf:";
|
dump_tensor(tf, "tf");
|
||||||
dump_tensor(tf);
|
|
||||||
|
|
||||||
ETSerClass o;
|
ETSerClass o;
|
||||||
ioTest<Hdf5Writer, Hdf5Reader, ETSerClass>("iotest_object.h5", o, "ETSerClass_object_instance_name");
|
ioTest<Hdf5Writer, Hdf5Reader, ETSerClass>("iotest_object.h5", o, "ETSerClass_object_instance_name");
|
||||||
@ -192,8 +176,7 @@ bool EigenIOTest(void) {
|
|||||||
Val += Inc;
|
Val += Inc;
|
||||||
}
|
}
|
||||||
ioTest<Hdf5Writer, Hdf5Reader, LSCTensor>("iotest_LSCTensor.h5", l, "LSCTensor_object_instance_name");
|
ioTest<Hdf5Writer, Hdf5Reader, LSCTensor>("iotest_LSCTensor.h5", l, "LSCTensor_object_instance_name");
|
||||||
std::cout << "l:";
|
dump_tensor(l, "l");
|
||||||
dump_tensor(l);
|
|
||||||
|
|
||||||
// Tensor of spin colour
|
// Tensor of spin colour
|
||||||
LCMTensor l2;
|
LCMTensor l2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user