The serialization of matrices works in the same manner as the serialization of vectors. The following example demonstrates the (de-)serialization of dense and sparse matrices:
{
archive << D << S;
}
{
archive >> D1;
archive >> D2
}
Binary archive for the portable serialization of data.
Definition: Archive.h:140
Efficient implementation of a compressed matrix.
Definition: CompressedMatrix.h:239
Efficient implementation of a dynamic matrix.
Definition: DynamicMatrix.h:242
Efficient implementation of a fixed-sized matrix.
Definition: StaticMatrix.h:249
constexpr bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
constexpr bool columnMajor
Storage order flag for column-major matrices.
Definition: StorageOrder.h:99
Note that also in case of matrices it is possible to (de-)serialize matrices with vector or matrix elements:
{
archive << mat;
}
{
archive >> mat;
}
Note that just as the vector serialization, the matrix serialization is restricted by a few important rules:
- matrices cannot be reconstituted as vectors (and vice versa)
- the element type of the serialized and reconstituted matrix must match, which means that on the source and destination platform the general type (signed/unsigned integral or floating point) and the size of the type must be exactly the same
- when reconstituting a
StaticMatrix
, the number of rows and columns must match those of the serialized matrix
In case an error is encountered during (de-)serialization, a std::runtime_exception
is thrown.
Previous: Vector Serialization Next: Customization