mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Add a simple serialization mechanism.
The `Serializer<T>` class implements a binary serialization that can write to (`serialize`) and read from (`deserialize`) a byte buffer. Also added convenience routines for serializing a list of arguments. This will mainly be for testing, specifically to transfer data to and from the GPU.
This commit is contained in:
25
test/main.h
25
test/main.h
@@ -391,6 +391,8 @@ inline void verify_impl(bool condition, const char *testname, const char *file,
|
||||
#define VERIFY_IS_NOT_MUCH_SMALLER_THAN(a, b) VERIFY(!test_isMuchSmallerThan(a, b))
|
||||
#define VERIFY_IS_APPROX_OR_LESS_THAN(a, b) VERIFY(test_isApproxOrLessThan(a, b))
|
||||
#define VERIFY_IS_NOT_APPROX_OR_LESS_THAN(a, b) VERIFY(!test_isApproxOrLessThan(a, b))
|
||||
#define VERIFY_IS_CWISE_EQUAL(a, b) VERIFY(test_isCwiseApprox(a, b, true))
|
||||
#define VERIFY_IS_CWISE_APPROX(a, b) VERIFY(test_isCwiseApprox(a, b, false))
|
||||
|
||||
#define VERIFY_IS_UNITARY(a) VERIFY(test_isUnitary(a))
|
||||
|
||||
@@ -655,6 +657,29 @@ inline bool test_isUnitary(const MatrixBase<Derived>& m)
|
||||
return m.isUnitary(test_precision<typename internal::traits<Derived>::Scalar>());
|
||||
}
|
||||
|
||||
// Checks component-wise, works with infs and nans.
|
||||
template<typename Derived1, typename Derived2>
|
||||
bool test_isCwiseApprox(const DenseBase<Derived1>& m1,
|
||||
const DenseBase<Derived2>& m2,
|
||||
bool exact) {
|
||||
if (m1.rows() != m2.rows()) {
|
||||
return false;
|
||||
}
|
||||
if (m1.cols() != m2.cols()) {
|
||||
return false;
|
||||
}
|
||||
for (Index r = 0; r < m1.rows(); ++r) {
|
||||
for (Index c = 0; c < m1.cols(); ++c) {
|
||||
if (m1(r, c) != m2(r, c)
|
||||
&& !((numext::isnan)(m1(r, c)) && (numext::isnan)(m2(r, c)))
|
||||
&& (exact || !test_isApprox(m1(r, c), m2(r, c)))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
bool test_is_equal(const T& actual, const U& expected, bool expect_equal)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user