List of all members
blaze::MatrixSerializer Class Reference

Serializer for dense and sparse matrices.The MatrixSerializer implements the necessary logic to serialize dense and sparse matrices, i.e. to convert them into a portable, binary representation. The following example demonstrates the (de-)serialization process of matrices: More...

#include <MatrixSerializer.h>

Public Member Functions

Constructor
 MatrixSerializer ()
 The default constructor of the MatrixSerializer class.
 

Private Attributes

Member variables
uint8_t version_
 The version of the archive.
 
uint8_t type_
 The type of the matrix.
 
uint8_t elementType_
 The type of an element.
 
uint8_t elementSize_
 The size in bytes of a single element of the matrix.
 
uint64_t rows_
 The number of rows of the matrix.
 
uint64_t columns_
 The number of columns of the matrix.
 
uint64_t number_
 The total number of elements contained in the matrix.
 

Serialization functions

template<typename Archive , typename MT , bool SO>
void serialize (Archive &archive, const Matrix< MT, SO > &mat)
 Serializes the given matrix and writes it to the archive. More...
 
template<typename Archive , typename MT >
void serializeHeader (Archive &archive, const MT &mat)
 Serializes all meta information about the given matrix. More...
 
template<typename Archive , typename MT , bool SO>
void serializeMatrix (Archive &archive, const DenseMatrix< MT, SO > &mat)
 Serializes the elements of a dense matrix. More...
 
template<typename Archive , typename MT , bool SO>
void serializeMatrix (Archive &archive, const SparseMatrix< MT, SO > &mat)
 Serializes the elements of a sparse matrix. More...
 

Deserialization functions

template<typename Archive , typename MT , bool SO>
void deserialize (Archive &archive, Matrix< MT, SO > &mat)
 Deserializes a matrix from the given archive. More...
 
template<typename Archive , typename MT >
void deserializeHeader (Archive &archive, const MT &mat)
 Deserializes all meta information about the given matrix. More...
 
template<typename MT , bool SO>
DisableIf_< IsResizable< MT > > prepareMatrix (DenseMatrix< MT, SO > &mat)
 Prepares the given non-resizable dense matrix for the deserialization process. More...
 
template<typename MT , bool SO>
DisableIf_< IsResizable< MT > > prepareMatrix (SparseMatrix< MT, SO > &mat)
 Prepares the given non-resizable sparse matrix for the deserialization process. More...
 
template<typename MT >
EnableIf_< IsResizable< MT > > prepareMatrix (MT &mat)
 Prepares the given resizable matrix for the deserialization process. More...
 
template<typename Archive , typename MT >
void deserializeMatrix (Archive &archive, MT &mat)
 Deserializes a matrix from the archive. More...
 
template<typename Archive , typename MT >
EnableIfTrue_< MT::simdEnabled > deserializeDenseRowMatrix (Archive &archive, DenseMatrix< MT, rowMajor > &mat)
 Deserializes a row-major dense matrix from the archive. More...
 
template<typename Archive , typename MT , bool SO>
void deserializeDenseRowMatrix (Archive &archive, DenseMatrix< MT, SO > &mat)
 Deserializes a row-major dense matrix from the archive. More...
 
template<typename Archive , typename MT , bool SO>
DisableIf_< IsNumeric< ElementType_< MT > > > deserializeDenseRowMatrix (Archive &archive, SparseMatrix< MT, SO > &mat)
 Deserializes a row-major dense matrix from the archive. More...
 
template<typename Archive , typename MT , bool SO>
EnableIf_< IsNumeric< ElementType_< MT > > > deserializeDenseRowMatrix (Archive &archive, SparseMatrix< MT, SO > &mat)
 Deserializes a row-major dense matrix from the archive. More...
 
template<typename Archive , typename MT >
EnableIfTrue_< MT::simdEnabled > deserializeDenseColumnMatrix (Archive &archive, DenseMatrix< MT, columnMajor > &mat)
 Deserializes a column-major dense matrix from the archive. More...
 
template<typename Archive , typename MT , bool SO>
void deserializeDenseColumnMatrix (Archive &archive, DenseMatrix< MT, SO > &mat)
 Deserializes a column-major dense matrix from the archive. More...
 
template<typename Archive , typename MT , bool SO>
DisableIf_< IsNumeric< ElementType_< MT > > > deserializeDenseColumnMatrix (Archive &archive, SparseMatrix< MT, SO > &mat)
 Deserializes a column-major dense matrix from the archive. More...
 
template<typename Archive , typename MT , bool SO>
EnableIf_< IsNumeric< ElementType_< MT > > > deserializeDenseColumnMatrix (Archive &archive, SparseMatrix< MT, SO > &mat)
 Deserializes a column-major dense matrix from the archive. More...
 
template<typename Archive , typename MT , bool SO>
void deserializeSparseRowMatrix (Archive &archive, DenseMatrix< MT, SO > &mat)
 Deserializes a row-major sparse matrix from the archive. More...
 
template<typename Archive , typename MT >
void deserializeSparseRowMatrix (Archive &archive, SparseMatrix< MT, rowMajor > &mat)
 Deserializes a row-major sparse matrix from the archive. More...
 
template<typename Archive , typename MT >
void deserializeSparseRowMatrix (Archive &archive, SparseMatrix< MT, columnMajor > &mat)
 Deserializes a row-major sparse matrix from the archive. More...
 
template<typename Archive , typename MT , bool SO>
void deserializeSparseColumnMatrix (Archive &archive, DenseMatrix< MT, SO > &mat)
 Deserializes a column-major sparse matrix from the archive. More...
 
template<typename Archive , typename MT >
void deserializeSparseColumnMatrix (Archive &archive, SparseMatrix< MT, rowMajor > &mat)
 Deserializes a column-major sparse matrix from the archive. More...
 
template<typename Archive , typename MT >
void deserializeSparseColumnMatrix (Archive &archive, SparseMatrix< MT, columnMajor > &mat)
 Deserializes a column-major sparse matrix from the archive. More...
 

Detailed Description

Serializer for dense and sparse matrices.

The MatrixSerializer implements the necessary logic to serialize dense and sparse matrices, i.e. to convert them into a portable, binary representation. The following example demonstrates the (de-)serialization process of matrices:

// Serialization of both matrices
{
// ... Resizing and initialization
// Creating an archive that writes into a the file "matrices.blaze"
blaze::Archive<std::ofstream> archive( "matrices.blaze" );
// Serialization of both matrices into the same archive. Note that D lies before S!
archive << D << S;
}
// Reconstitution of both matrices
{
// Creating an archive that reads from the file "matrices.blaze"
blaze::Archive<std::ofstream> archive( "matrices.blaze" );
// Reconstituting the former D matrix into D1. Note that it is possible to reconstitute
// the matrix into a differrent kind of matrix (StaticMatrix -> DynamicMatrix), but that
// the type of elements has to be the same.
archive >> D1;
// Reconstituting the former S matrix into D2. Note that is is even possible to reconstitute
// a sparse matrix as a dense matrix (also the reverse is possible) and that a column-major
// matrix can be reconstituted as row-major matrix (and vice versa). Note however that also
// in this case the type of elements is the same!
archive >> D2
}

Note that it is even possible to (de-)serialize matrices with vector or matrix elements:

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

As the examples demonstrates, the matrix serialization offers an enormous flexibility. However, several actions result in errors:

In case an error is encountered during (de-)serialization, a std::runtime_exception is thrown.

Member Function Documentation

◆ deserialize()

template<typename Archive , typename MT , bool SO>
void blaze::MatrixSerializer::deserialize ( Archive archive,
Matrix< MT, SO > &  mat 
)

Deserializes a matrix from the given archive.

Parameters
archiveThe archive to be read from.
matThe matrix to be deserialized.
Returns
void
Exceptions
std::runtime_errorError during deserialization.

◆ deserializeDenseColumnMatrix() [1/4]

template<typename Archive , typename MT >
EnableIfTrue_< MT::simdEnabled > blaze::MatrixSerializer::deserializeDenseColumnMatrix ( Archive archive,
DenseMatrix< MT, columnMajor > &  mat 
)
private

Deserializes a column-major dense matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe dense matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorDense matrix could not be deserialized.

This function deserializes a column-major dense matrix from the archive and reconstitutes the given column-major dense matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeDenseColumnMatrix() [2/4]

template<typename Archive , typename MT , bool SO>
void blaze::MatrixSerializer::deserializeDenseColumnMatrix ( Archive archive,
DenseMatrix< MT, SO > &  mat 
)
private

Deserializes a column-major dense matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe dense matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorDense matrix could not be deserialized.

This function deserializes a column-major dense matrix from the archive and reconstitutes the given dense matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeDenseColumnMatrix() [3/4]

template<typename Archive , typename MT , bool SO>
DisableIf_< IsNumeric< ElementType_< MT > > > blaze::MatrixSerializer::deserializeDenseColumnMatrix ( Archive archive,
SparseMatrix< MT, SO > &  mat 
)
private

Deserializes a column-major dense matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe sparse matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorSparse matrix could not be deserialized.

This function deserializes a column-major dense matrix from the archive and reconstitutes the given sparse matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeDenseColumnMatrix() [4/4]

template<typename Archive , typename MT , bool SO>
EnableIf_< IsNumeric< ElementType_< MT > > > blaze::MatrixSerializer::deserializeDenseColumnMatrix ( Archive archive,
SparseMatrix< MT, SO > &  mat 
)
private

Deserializes a column-major dense matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe sparse matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorSparse matrix could not be deserialized.

This function deserializes a column-major dense matrix from the archive and reconstitutes the given sparse matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeDenseRowMatrix() [1/4]

template<typename Archive , typename MT >
EnableIfTrue_< MT::simdEnabled > blaze::MatrixSerializer::deserializeDenseRowMatrix ( Archive archive,
DenseMatrix< MT, rowMajor > &  mat 
)
private

Deserializes a row-major dense matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe dense matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorDense matrix could not be deserialized.

This function deserializes a row-major dense matrix from the archive and reconstitutes the given row-major dense matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeDenseRowMatrix() [2/4]

template<typename Archive , typename MT , bool SO>
void blaze::MatrixSerializer::deserializeDenseRowMatrix ( Archive archive,
DenseMatrix< MT, SO > &  mat 
)
private

Deserializes a row-major dense matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe dense matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorDense matrix could not be deserialized.

This function deserializes a row-major dense matrix from the archive and reconstitutes the given dense matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeDenseRowMatrix() [3/4]

template<typename Archive , typename MT , bool SO>
DisableIf_< IsNumeric< ElementType_< MT > > > blaze::MatrixSerializer::deserializeDenseRowMatrix ( Archive archive,
SparseMatrix< MT, SO > &  mat 
)
private

Deserializes a row-major dense matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe dense matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorSparse matrix could not be deserialized.

This function deserializes a row-major dense matrix from the archive and reconstitutes the given sparse matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeDenseRowMatrix() [4/4]

template<typename Archive , typename MT , bool SO>
EnableIf_< IsNumeric< ElementType_< MT > > > blaze::MatrixSerializer::deserializeDenseRowMatrix ( Archive archive,
SparseMatrix< MT, SO > &  mat 
)
private

Deserializes a row-major dense matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe dense matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorSparse matrix could not be deserialized.

This function deserializes a row-major dense matrix from the archive and reconstitutes the given sparse matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeHeader()

template<typename Archive , typename MT >
void blaze::MatrixSerializer::deserializeHeader ( Archive archive,
const MT &  mat 
)
private

Deserializes all meta information about the given matrix.

Parameters
archiveThe archive to be read from.
matThe matrix to be deserialized.
Returns
void
Exceptions
std::runtime_errorError during deserialization.

◆ deserializeMatrix()

template<typename Archive , typename MT >
void blaze::MatrixSerializer::deserializeMatrix ( Archive archive,
MT &  mat 
)
private

Deserializes a matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorError during deserialization.

This function deserializes the contents of the matrix from the archive and reconstitutes the given matrix.

◆ deserializeSparseColumnMatrix() [1/3]

template<typename Archive , typename MT , bool SO>
void blaze::MatrixSerializer::deserializeSparseColumnMatrix ( Archive archive,
DenseMatrix< MT, SO > &  mat 
)
private

Deserializes a column-major sparse matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorDense matrix could not be deserialized.

This function deserializes a column-major sparse matrix from the archive and reconstitutes the given dense matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeSparseColumnMatrix() [2/3]

template<typename Archive , typename MT >
void blaze::MatrixSerializer::deserializeSparseColumnMatrix ( Archive archive,
SparseMatrix< MT, rowMajor > &  mat 
)
private

Deserializes a column-major sparse matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorSparse matrix could not be deserialized.

This function deserializes a column-major sparse matrix from the archive and reconstitutes the given row-major sparse matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeSparseColumnMatrix() [3/3]

template<typename Archive , typename MT >
void blaze::MatrixSerializer::deserializeSparseColumnMatrix ( Archive archive,
SparseMatrix< MT, columnMajor > &  mat 
)
private

Deserializes a column-major sparse matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorSparse matrix could not be deserialized.

This function deserializes a column-major sparse matrix from the archive and reconstitutes the given column-major sparse matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeSparseRowMatrix() [1/3]

template<typename Archive , typename MT , bool SO>
void blaze::MatrixSerializer::deserializeSparseRowMatrix ( Archive archive,
DenseMatrix< MT, SO > &  mat 
)
private

Deserializes a row-major sparse matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorDense matrix could not be deserialized.

This function deserializes a row-major sparse matrix from the archive and reconstitutes the given dense matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeSparseRowMatrix() [2/3]

template<typename Archive , typename MT >
void blaze::MatrixSerializer::deserializeSparseRowMatrix ( Archive archive,
SparseMatrix< MT, rowMajor > &  mat 
)
private

Deserializes a row-major sparse matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorSparse matrix could not be deserialized.

This function deserializes a row-major sparse matrix from the archive and reconstitutes the given row-major sparse matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ deserializeSparseRowMatrix() [3/3]

template<typename Archive , typename MT >
void blaze::MatrixSerializer::deserializeSparseRowMatrix ( Archive archive,
SparseMatrix< MT, columnMajor > &  mat 
)
private

Deserializes a row-major sparse matrix from the archive.

Parameters
archiveThe archive to be read from.
matThe matrix to be reconstituted.
Returns
void
Exceptions
std::runtime_errorSparse matrix could not be deserialized.

This function deserializes a row-major sparse matrix from the archive and reconstitutes the given column-major sparse matrix. In case any error is detected during the deserialization process, a std::runtime_error is thrown.

◆ prepareMatrix() [1/3]

template<typename MT , bool SO>
DisableIf_< IsResizable< MT > > blaze::MatrixSerializer::prepareMatrix ( DenseMatrix< MT, SO > &  mat)
private

Prepares the given non-resizable dense matrix for the deserialization process.

Parameters
matThe dense matrix to be prepared.
Returns
void

◆ prepareMatrix() [2/3]

template<typename MT , bool SO>
DisableIf_< IsResizable< MT > > blaze::MatrixSerializer::prepareMatrix ( SparseMatrix< MT, SO > &  mat)
private

Prepares the given non-resizable sparse matrix for the deserialization process.

Parameters
matThe sparse matrix to be prepared.
Returns
void

◆ prepareMatrix() [3/3]

template<typename MT >
EnableIf_< IsResizable< MT > > blaze::MatrixSerializer::prepareMatrix ( MT &  mat)
private

Prepares the given resizable matrix for the deserialization process.

Parameters
matThe matrix to be prepared.
Returns
void

◆ serialize()

template<typename Archive , typename MT , bool SO>
void blaze::MatrixSerializer::serialize ( Archive archive,
const Matrix< MT, SO > &  mat 
)

Serializes the given matrix and writes it to the archive.

Parameters
archiveThe archive to be written.
matThe matrix to be serialized.
Returns
void
Exceptions
std::runtime_errorError during serialization.

◆ serializeHeader()

template<typename Archive , typename MT >
void blaze::MatrixSerializer::serializeHeader ( Archive archive,
const MT &  mat 
)
private

Serializes all meta information about the given matrix.

Parameters
archiveThe archive to be written.
matThe matrix to be serialized.
Returns
void
Exceptions
std::runtime_errorFile header could not be serialized.

◆ serializeMatrix() [1/2]

template<typename Archive , typename MT , bool SO>
void blaze::MatrixSerializer::serializeMatrix ( Archive archive,
const DenseMatrix< MT, SO > &  mat 
)
private

Serializes the elements of a dense matrix.

Parameters
archiveThe archive to be written.
matThe matrix to be serialized.
Returns
void
Exceptions
std::runtime_errorDense matrix could not be serialized.

◆ serializeMatrix() [2/2]

template<typename Archive , typename MT , bool SO>
void blaze::MatrixSerializer::serializeMatrix ( Archive archive,
const SparseMatrix< MT, SO > &  mat 
)
private

Serializes the elements of a sparse matrix.

Parameters
archiveThe archive to be written.
matThe matrix to be serialized.
Returns
void
Exceptions
std::runtime_errorSparse matrix could not be serialized.

The documentation for this class was generated from the following file: