Blaze 3.9
Classes
Serialization

Classes

class  blaze::MatrixSerializer
 Serializer for dense and sparse matrices. More...
 
struct  blaze::TypeValueMapping< T >
 Conversion from a data type to a serial representation. More...
 
class  blaze::VectorSerializer
 Serializer for dense and sparse vectors. More...
 

Detailed Description

The math serialization module provides the functionality to create platform independent, portable, binary representations of vectors and matrices. The resulting data structures can be used to reconstitute the vectors and matrices in a different context, on another platform, etc.

The following example demonstrates the functionality of this module by means of vectors:

// Serialization of both vectors
{
// ... Resizing and initialization
// Creating an archive that writes into a the file "vectors.blaze"
blaze::Archive<std::ofstream> archive( "vectors.blaze" );
// Serialization of both vectors into the same archive. Note that d lies before s!
archive << d << s;
}
// Reconstitution of both vectors
{
// Creating an archive that reads from the file "vectors.blaze"
blaze::Archive<std::ofstream> archive( "vectors.blaze" );
// Reconstituting the former d vector into d1. Note that it is possible to reconstitute
// the vector into a differrent kind of vector (StaticVector -> DynamicVector), but that
// the type of elements has to be the same.
archive >> d1;
// Reconstituting the former s vector into d2. Note that is is even possible to reconstitute
// a sparse vector as a dense vector (also the reverse is possible) and that a column vector
// can be reconstituted as row vector (and vice versa). Note however that also in this case
// the type of elements is the same!
archive >> d2
}
Binary archive for the portable serialization of data.
Definition: Archive.h:140
Efficient implementation of an arbitrary sized sparse vector.
Definition: CompressedVector.h:220
Efficient implementation of an arbitrary sized vector.
Definition: DynamicVector.h:223
Efficient implementation of a fixed-sized vector.
Definition: StaticVector.h:230
constexpr bool columnVector
Transpose flag for column vectors.
Definition: TransposeFlag.h:58
constexpr bool rowVector
Transpose flag for row vectors.
Definition: TransposeFlag.h:73

The (de-)serialization of vectors is not restricted to vectors of built-in data type, but can also be used for vectors with vector or matrix element type:

// Serialization
{
// ... Resizing and initialization
// Creating an archive that writes into a the file "vector.blaze"
blaze::Archive<std::ofstream> archive( "vector.blaze" );
// Serialization of the vector into the archive
archive << vec;
}
// Deserialization
{
// Creating an archive that reads from the file "vector.blaze"
blaze::Archive<std::ofstream> archive( "vector.blaze" );
// Reconstitution of the vector from the archive
archive >> vec;
}