mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
Serialisation of an object containing an Eigen::Tensor works for Hdf5. Still quite a lot of tidying up to do.
This commit is contained in:
parent
d5024bd07e
commit
6f2663edf6
@ -378,8 +378,20 @@ namespace Grid {
|
|||||||
{
|
{
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static inline bool CompareMember(const T &lhs, const T &rhs) {
|
||||||
|
return lhs == rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Scalar_, int NumIndices_, int Options_, typename Index_>
|
||||||
|
static inline bool CompareMember(const Eigen::Tensor<Scalar_, NumIndices_, Options_, Index_> &lhs,
|
||||||
|
const Eigen::Tensor<Scalar_, NumIndices_, Options_, Index_> &rhs) {
|
||||||
|
Eigen::Tensor<bool, 0, Options_, Index_> bResult = (lhs == rhs).all();
|
||||||
|
return bResult(0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generic writer interface //////////////////////////////////////////////////
|
// Generic writer interface //////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void push(Writer<T> &w, const std::string &s) {
|
inline void push(Writer<T> &w, const std::string &s) {
|
||||||
|
@ -109,7 +109,7 @@ THE SOFTWARE.
|
|||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#define GRID_MACRO_MEMBER(A,B) A B;
|
#define GRID_MACRO_MEMBER(A,B) A B;
|
||||||
#define GRID_MACRO_COMP_MEMBER(A,B) result = (result and (lhs. B == rhs. B));
|
#define GRID_MACRO_COMP_MEMBER(A,B) result = (result and CompareMember(lhs. B, rhs. B));
|
||||||
#define GRID_MACRO_OS_WRITE_MEMBER(A,B) os<< #A <<" " #B << " = " << obj. B << " ; " <<std::endl;
|
#define GRID_MACRO_OS_WRITE_MEMBER(A,B) os<< #A <<" " #B << " = " << obj. B << " ; " <<std::endl;
|
||||||
#define GRID_MACRO_READ_MEMBER(A,B) Grid::read(RD,#B,obj. B);
|
#define GRID_MACRO_READ_MEMBER(A,B) Grid::read(RD,#B,obj. B);
|
||||||
#define GRID_MACRO_WRITE_MEMBER(A,B) Grid::write(WR,#B,obj. B);
|
#define GRID_MACRO_WRITE_MEMBER(A,B) Grid::write(WR,#B,obj. B);
|
||||||
|
@ -441,21 +441,21 @@ bool DebugEigenTest()
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef iMatrix<Complex,7> OddBall;
|
typedef iMatrix<Complex,7> OddBall;
|
||||||
typedef Eigen::Tensor<OddBall, 3, Eigen::RowMajor> TensorOddBall;
|
typedef Eigen::Tensor<OddBall, 3> TensorOddBall;
|
||||||
|
|
||||||
typedef int TestScalar;
|
//typedef int TestScalar;
|
||||||
//typedef std::complex<double> TestScalar;
|
typedef std::complex<double> TestScalar;
|
||||||
typedef Eigen::Tensor<TestScalar, 3, Eigen::RowMajor> TestTensor;
|
typedef Eigen::Tensor<TestScalar, 3> TestTensor;
|
||||||
|
|
||||||
// From Test_serialisation.cc
|
// From Test_serialisation.cc
|
||||||
class myclass: Serializable {
|
class myclass: Serializable {
|
||||||
public:
|
public:
|
||||||
GRID_SERIALIZABLE_CLASS_MEMBERS(myclass
|
GRID_SERIALIZABLE_CLASS_MEMBERS(myclass
|
||||||
//, TestTensor, critter
|
, TestTensor, critter
|
||||||
, SpinColourVector, scv
|
, SpinColourVector, scv
|
||||||
, SpinColourMatrix, scm
|
, SpinColourMatrix, scm
|
||||||
);
|
);
|
||||||
//myclass() : critter(7,3,2) {}
|
myclass() : critter(7,3,2) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename W, typename R, typename O>
|
template <typename W, typename R, typename O>
|
||||||
@ -479,6 +479,30 @@ bool ioTest(const std::string &filename, const O &object, const std::string &nam
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
template <typename Scalar_, int NumIndices_, int Options_, typename IndexType_>
|
||||||
|
eval Eigen::TensorForcedEvalOp<const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_cmp_op<Scalar_, Scalar_, Eigen::internal::cmp_EQ>, const Eigen::Tensor<Scalar_, NumIndices_, Options_, IndexType_>, const Eigen::Tensor<Scalar_, NumIndices_, Options_, IndexType_> >, Eigen::MakePointer>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::ostream& operator << (std::ostream& os, const TensorBase<T, ReadOnlyAccessors>& expr) {
|
||||||
|
typedef TensorEvaluator<const TensorForcedEvalOp<const T>, DefaultDevice> Evaluator;
|
||||||
|
typedef typename Evaluator::Dimensions Dimensions;
|
||||||
|
|
||||||
|
// Evaluate the expression if needed
|
||||||
|
TensorForcedEvalOp<const T> eval = expr.eval();
|
||||||
|
Evaluator tensor(eval, DefaultDevice());
|
||||||
|
tensor.evalSubExprsIfNeeded(NULL);
|
||||||
|
|
||||||
|
// Print the result
|
||||||
|
static const int rank = internal::array_size<Dimensions>::value;
|
||||||
|
internal::TensorPrinter<Evaluator, rank>::run(os, tensor);
|
||||||
|
|
||||||
|
// Cleanup.
|
||||||
|
tensor.cleanup();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
bool DebugIOTest(void) {
|
bool DebugIOTest(void) {
|
||||||
OddBall critter;
|
OddBall critter;
|
||||||
ioTest<Hdf5Writer, Hdf5Reader, OddBall>("iotest_oddball.h5", critter, "OddBall");
|
ioTest<Hdf5Writer, Hdf5Reader, OddBall>("iotest_oddball.h5", critter, "OddBall");
|
||||||
@ -499,12 +523,13 @@ bool DebugIOTest(void) {
|
|||||||
ioTest<Hdf5Writer, Hdf5Reader, TestTensor>("iotest_tensor.h5", t, "eigen_tensor_instance_name");
|
ioTest<Hdf5Writer, Hdf5Reader, TestTensor>("iotest_tensor.h5", t, "eigen_tensor_instance_name");
|
||||||
|
|
||||||
TestTensor t2(t);
|
TestTensor t2(t);
|
||||||
auto bEqual = (t == t2).all();
|
t2(1,1,1) += Inc;
|
||||||
std::cout << "(t2 == t) = " << bEqual << std::endl;
|
Eigen::Tensor<bool, 0> rResult = (t == t2).all();
|
||||||
//if( * bEqual.data() != 0 )
|
if( rResult(0) )
|
||||||
//std::cout << "t2 == t" << std::endl;
|
std::cout << "t2 == t" << std::endl;
|
||||||
//else
|
else
|
||||||
//std::cout << "t2 != t" << std::endl;
|
std::cout << "t2 != t" << std::endl;
|
||||||
|
//std::cout << "(t == t2) : " << (t == t2).all()(0) << std::endl;
|
||||||
|
|
||||||
myclass o;
|
myclass o;
|
||||||
ioTest<Hdf5Writer, Hdf5Reader, myclass>("iotest_object.h5", o, "myclass_object_instance_name");
|
ioTest<Hdf5Writer, Hdf5Reader, myclass>("iotest_object.h5", o, "myclass_object_instance_name");
|
||||||
|
Loading…
Reference in New Issue
Block a user