Public Member Functions | List of all members
blaze::VectorSerializer Class Reference

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

#include <VectorSerializer.h>

Public Member Functions

template<typename Archive , typename VT , bool TF>
DisableIfTrue< VT::simdEnabled >::Type deserializeDenseVector (Archive &archive, DenseVector< VT, TF > &vec)
 Deserializes a dense vector from the archive. More...
 
Constructor
 VectorSerializer ()
 The default constructor of the VectorSerializer class.
 

Private Attributes

Member variables
uint8_t version_
 The version of the archive.
 
uint8_t type_
 The type of the vector.
 
uint8_t elementType_
 The type of an element.
 
uint8_t elementSize_
 The size in bytes of a single element of the vector.
 
uint64_t size_
 The size of the vector.
 
uint64_t number_
 The total number of elements contained in the vector.
 

Serialization functions

template<typename Archive , typename VT , bool TF>
void serialize (Archive &archive, const Vector< VT, TF > &vec)
 Serializes the given vector and writes it to the archive. More...
 
template<typename Archive , typename VT >
void serializeHeader (Archive &archive, const VT &vec)
 Serializes all meta information about the given vector. More...
 
template<typename Archive , typename VT , bool TF>
void serializeVector (Archive &archive, const DenseVector< VT, TF > &vec)
 Serializes the elements of a dense vector. More...
 
template<typename Archive , typename VT , bool TF>
void serializeVector (Archive &archive, const SparseVector< VT, TF > &vec)
 Serializes the elements of a sparse vector. More...
 

Deserialization functions

template<typename Archive , typename VT , bool TF>
void deserialize (Archive &archive, Vector< VT, TF > &vec)
 Deserializes a vector from the given archive. More...
 
template<typename Archive , typename VT >
void deserializeHeader (Archive &archive, const VT &vec)
 Deserializes all meta information about the given vector. More...
 
template<typename VT , bool TF>
DisableIf_< IsResizable< VT > > prepareVector (DenseVector< VT, TF > &vec)
 Prepares the given non-resizable dense vector for the deserialization process. More...
 
template<typename VT , bool TF>
DisableIf_< IsResizable< VT > > prepareVector (SparseVector< VT, TF > &vec)
 Prepares the given non-resizable sparse vector for the deserialization process. More...
 
template<typename VT >
EnableIf_< IsResizable< VT > > prepareVector (VT &vec)
 Prepares the given resizable vector for the deserialization process. More...
 
template<typename Archive , typename VT >
void deserializeVector (Archive &archive, VT &vec)
 Deserializes a vector from the archive. More...
 
template<typename Archive , typename VT , bool TF>
DisableIfTrue< VT::simdEnabled >::Type deserializeDenseVector (Archive &archive, DenseVector< VT, TF > &vec)
 
template<typename Archive , typename VT , bool TF>
EnableIfTrue_< VT::simdEnabled > deserializeDenseVector (Archive &archive, DenseVector< VT, TF > &vec)
 Deserializes a dense vector from the archive. More...
 
template<typename Archive , typename VT , bool TF>
void deserializeDenseVector (Archive &archive, SparseVector< VT, TF > &vec)
 Deserializes a dense vector from the archive. More...
 
template<typename Archive , typename VT , bool TF>
void deserializeSparseVector (Archive &archive, DenseVector< VT, TF > &vec)
 Deserializes a sparse vector from the archive. More...
 
template<typename Archive , typename VT , bool TF>
void deserializeSparseVector (Archive &archive, SparseVector< VT, TF > &vec)
 Deserializes a sparse vector from the archive. More...
 

Detailed Description

Serializer for dense and sparse vectors.

The VectorSerializer implements the necessary logic to serialize dense and sparse vectors, i.e. to convert them into a portable, binary representation. The following example demonstrates the (de-)serialization process 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
}

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

// 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;
}

As the examples demonstrates, the vector 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

template<typename Archive , typename VT , bool TF>
void blaze::VectorSerializer::deserialize ( Archive archive,
Vector< VT, TF > &  vec 
)

Deserializes a vector from the given archive.

Parameters
archiveThe archive to be read from.
vecThe vector to be deserialized.
Returns
void
Exceptions
std::runtime_errorError during deserialization.
template<typename Archive , typename VT , bool TF>
EnableIfTrue_< VT::simdEnabled > blaze::VectorSerializer::deserializeDenseVector ( Archive archive,
DenseVector< VT, TF > &  vec 
)
private

Deserializes a dense vector from the archive.

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

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

template<typename Archive , typename VT , bool TF>
void blaze::VectorSerializer::deserializeDenseVector ( Archive archive,
SparseVector< VT, TF > &  vec 
)
private

Deserializes a dense vector from the archive.

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

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

template<typename Archive , typename VT , bool TF>
DisableIfTrue< VT::simdEnabled >::Type blaze::VectorSerializer::deserializeDenseVector ( Archive archive,
DenseVector< VT, TF > &  vec 
)

Deserializes a dense vector from the archive.

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

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

template<typename Archive , typename VT >
void blaze::VectorSerializer::deserializeHeader ( Archive archive,
const VT &  vec 
)
private

Deserializes all meta information about the given vector.

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

This function deserializes all meta information about the given vector contained in the header of the given archive. In case any error is detected during the deserialization process (for instance an invalid type of vector, element type, element size, or vector size) a std::runtime_error is thrown.

template<typename Archive , typename VT , bool TF>
void blaze::VectorSerializer::deserializeSparseVector ( Archive archive,
DenseVector< VT, TF > &  vec 
)
private

Deserializes a sparse vector from the archive.

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

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

template<typename Archive , typename VT , bool TF>
void blaze::VectorSerializer::deserializeSparseVector ( Archive archive,
SparseVector< VT, TF > &  vec 
)
private

Deserializes a sparse vector from the archive.

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

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

template<typename Archive , typename VT >
void blaze::VectorSerializer::deserializeVector ( Archive archive,
VT &  vec 
)
private

Deserializes a vector from the archive.

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

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

template<typename VT , bool TF>
DisableIf_< IsResizable< VT > > blaze::VectorSerializer::prepareVector ( DenseVector< VT, TF > &  vec)
private

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

Parameters
vecThe dense vector to be prepared.
Returns
void
template<typename VT , bool TF>
DisableIf_< IsResizable< VT > > blaze::VectorSerializer::prepareVector ( SparseVector< VT, TF > &  vec)
private

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

Parameters
vecThe sparse vector to be prepared.
Returns
void
template<typename VT >
EnableIf_< IsResizable< VT > > blaze::VectorSerializer::prepareVector ( VT &  vec)
private

Prepares the given resizable vector for the deserialization process.

Parameters
vecThe vector to be prepared.
Returns
void
template<typename Archive , typename VT , bool TF>
void blaze::VectorSerializer::serialize ( Archive archive,
const Vector< VT, TF > &  vec 
)

Serializes the given vector and writes it to the archive.

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

This function serializes the given vector and writes it to the given archive. In case any error is detected during the serialization, a std::runtime_error is thrown.

template<typename Archive , typename VT >
void blaze::VectorSerializer::serializeHeader ( Archive archive,
const VT &  vec 
)
private

Serializes all meta information about the given vector.

Parameters
archiveThe archive to be written.
vecThe vector to be serialized.
Returns
void
Exceptions
std::runtime_errorFile header could not be serialized.
template<typename Archive , typename VT , bool TF>
void blaze::VectorSerializer::serializeVector ( Archive archive,
const DenseVector< VT, TF > &  vec 
)
private

Serializes the elements of a dense vector.

Parameters
archiveThe archive to be written.
vecThe vector to be serialized.
Returns
void
Exceptions
std::runtime_errorDense vector could not be serialized.
template<typename Archive , typename VT , bool TF>
void blaze::VectorSerializer::serializeVector ( Archive archive,
const SparseVector< VT, TF > &  vec 
)
private

Serializes the elements of a sparse vector.

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

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