35 #ifndef _BLAZE_MATH_SERIALIZATION_MATRIXSERIALIZER_H_
36 #define _BLAZE_MATH_SERIALIZATION_MATRIXSERIALIZER_H_
174 template<
bool IsDenseMatrix,
bool IsRowMajorMatrix >
175 struct MatrixValueMappingHelper;
187 template<
typename T >
188 struct MatrixValueMapping
216 template<
typename Archive,
typename MT,
bool SO >
224 template<
typename Archive,
typename MT,
bool SO >
233 template<
typename Archive,
typename MT >
236 template<
typename Archive,
typename MT,
bool SO >
239 template<
typename Archive,
typename MT,
bool SO >
247 template<
typename Archive,
typename MT >
250 template<
typename MT,
bool SO >
253 template<
typename MT,
bool SO >
256 template<
typename MT >
259 template<
typename Archive,
typename MT >
262 template<
typename Archive,
typename MT >
266 template<
typename Archive,
typename MT,
bool SO >
269 template<
typename Archive,
typename MT,
bool SO >
273 template<
typename Archive,
typename MT,
bool SO >
277 template<
typename Archive,
typename MT >
281 template<
typename Archive,
typename MT,
bool SO >
284 template<
typename Archive,
typename MT,
bool SO >
288 template<
typename Archive,
typename MT,
bool SO >
292 template<
typename Archive,
typename MT,
bool SO >
295 template<
typename Archive,
typename MT >
298 template<
typename Archive,
typename MT >
301 template<
typename Archive,
typename MT,
bool SO >
304 template<
typename Archive,
typename MT >
307 template<
typename Archive,
typename MT >
373 throw std::runtime_error(
"Faulty archive detected" );
397 archive << uint8_t ( MatrixValueMapping<MT>::value );
398 archive << uint8_t ( TypeValueMapping<ET>::value );
399 archive << uint8_t (
sizeof( ET ) );
401 archive <<
uint64_t( mat.columns() );
402 archive << uint64_t( ( IsDenseMatrix<MT>::value ) ? ( mat.rows()*mat.columns() ) : ( mat.nonZeros() ) );
405 throw std::runtime_error(
"File header could not be serialized" );
425 for(
size_t i=0UL; i<(~mat).
rows(); ++i ) {
426 for(
size_t j=0UL; j<(~mat).
columns(); ++j ) {
427 archive << (~mat)(i,j);
432 for(
size_t j=0UL; j<(~mat).
columns(); ++j ) {
433 for(
size_t i=0UL; i<(~mat).
rows(); ++i ) {
434 archive << (~mat)(i,j);
440 throw std::runtime_error(
"Dense matrix could not be serialized" );
462 for(
size_t i=0UL; i<(~mat).
rows(); ++i ) {
463 archive <<
uint64_t( (~mat).nonZeros( i ) );
464 for( ConstIterator element=(~mat).begin(i); element!=(~mat).end(i); ++element ) {
465 archive << element->index() << element->value();
470 for(
size_t j=0UL; j<(~mat).
columns(); ++j ) {
471 archive <<
uint64_t( (~mat).nonZeros( j ) );
472 for( ConstIterator element=(~mat).begin(j); element!=(~mat).end(j); ++element ) {
473 archive << element->index() << element->value();
479 throw std::runtime_error(
"Sparse matrix could not be serialized" );
507 throw std::invalid_argument(
"Faulty archive detected" );
532 throw std::runtime_error(
"Corrupt archive detected" );
535 throw std::runtime_error(
"Invalid version detected" );
537 else if( (
type_ & 1U ) != 1U || (
type_ & (~7U) ) != 0U ) {
538 throw std::runtime_error(
"Invalid matrix type detected" );
541 throw std::runtime_error(
"Invalid element type detected" );
544 throw std::runtime_error(
"Invalid element size detected" );
547 throw std::runtime_error(
"Invalid matrix size detected" );
550 throw std::runtime_error(
"Invalid number of elements detected" );
562 template<
typename MT
577 template<
typename MT
593 template<
typename MT >
621 else if(
type_ == 5UL ) {
624 else if(
type_ == 3UL ) {
627 else if(
type_ == 7UL ) {
656 for(
size_t i=0UL; i<
rows_; ++i ) {
657 archive.read( &(~mat)(i,0),
columns_ );
661 throw std::runtime_error(
"Dense matrix could not be deserialized" );
688 for(
size_t i=0UL; i<
rows_; ++i ) {
690 while( ( j !=
columns_ ) && ( archive >> value ) ) {
697 throw std::runtime_error(
"Dense matrix could not be deserialized" );
726 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
757 for(
size_t i=0UL; i<dim1; ++i ) {
758 (~mat).reserve( i, dim2 );
761 for(
size_t i=0UL; i<
rows_; ++i ) {
763 while( ( j !=
columns_ ) && ( archive >> value ) ) {
764 (~mat).append( i, j, value,
false );
770 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
793 if(
rows_ == 0UL )
return;
795 for(
size_t j=0UL; j<
columns_; ++j ) {
796 archive.read( &(~mat)(0,j),
rows_ );
800 throw std::runtime_error(
"Dense matrix could not be deserialized" );
827 for(
size_t j=0UL; j<
columns_; ++j ) {
829 while( ( i !=
rows_ ) && ( archive >> value ) ) {
836 throw std::runtime_error(
"Dense matrix could not be deserialized" );
865 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
896 for(
size_t i=0UL; i<dim1; ++i ) {
897 (~mat).reserve( i, dim2 );
900 for(
size_t j=0UL; j<
columns_; ++j ) {
902 while( ( i !=
rows_ ) && ( archive >> value ) ) {
903 (~mat).append( i, j, value,
false );
909 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
935 size_t index ( 0UL );
938 for(
size_t i=0UL; i<
rows_; ++i ) {
941 while( ( j != number ) && ( archive >> index >> value ) ) {
942 (~mat)(i,index) = value;
948 throw std::runtime_error(
"Dense matrix could not be deserialized" );
973 size_t index ( 0UL );
976 for(
size_t i=0UL; i<
rows_; ++i )
979 (~mat).reserve( i, number );
982 while( ( j != number ) && ( archive >> index >> value ) ) {
983 (~mat).append( i, index, value,
false );
989 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
1016 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
1042 size_t index ( 0UL );
1045 for(
size_t j=0UL; j<
columns_; ++j ) {
1048 while( ( i != number ) && ( archive >> index >> value ) ) {
1049 (~mat)(index,j) = value;
1055 throw std::runtime_error(
"Dense matrix could not be deserialized" );
1082 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
1107 size_t index ( 0UL );
1110 for(
size_t j=0UL; j<
columns_; ++j )
1113 (~mat).reserve( j, number );
1116 while( ( i != number ) && ( archive >> index >> value ) ) {
1117 (~mat).append( index, j, value,
false );
1123 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
1142 struct MatrixSerializer::MatrixValueMappingHelper<true,true>
1155 struct MatrixSerializer::MatrixValueMappingHelper<true,false>
1168 struct MatrixSerializer::MatrixValueMappingHelper<false,true>
1181 struct MatrixSerializer::MatrixValueMappingHelper<false,false>
1262 template<
typename Archive
1284 template<
typename Archive
void deserializeHeader(Archive &archive, const MT &mat)
Deserializes all meta information about the given matrix.
Definition: MatrixSerializer.h:527
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4579
Binary archive for the portable serialization of data.The Archive class implements the functionality ...
Definition: Archive.h:141
EnableIfTrue< MT::vectorizable >::Type deserializeDenseRowMatrix(Archive &archive, DenseMatrix< MT, rowMajor > &mat)
Deserializes a row-major dense matrix from the archive.
Definition: MatrixSerializer.h:652
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:197
T Type
The instantiated type.
Definition: EnableIf.h:99
8-bit unsigned integer type of the Blaze library.
Implementation of a compressed MxN matrix.
Efficient implementation of a dynamic matrix.The DynamicMatrix class template is the representation ...
Definition: DynamicMatrix.h:179
EnableIfTrue< MT::vectorizable >::Type deserializeDenseColumnMatrix(Archive &archive, DenseMatrix< MT, columnMajor > &mat)
Deserializes a column-major dense matrix from the archive.
Definition: MatrixSerializer.h:791
void serializeHeader(Archive &archive, const MT &mat)
Serializes all meta information about the given matrix.
Definition: MatrixSerializer.h:392
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:104
MatrixSerializer()
The default constructor of the MatrixSerializer class.
Definition: MatrixSerializer.h:339
Header file for the SparseMatrix base class.
void deserializeSparseColumnMatrix(Archive &archive, DenseMatrix< MT, SO > &mat)
Deserializes a column-major sparse matrix from the archive.
Definition: MatrixSerializer.h:1037
void deserializeMatrix(Archive &archive, MT &mat)
Deserializes a matrix from the archive.
Definition: MatrixSerializer.h:616
Header file for the DisableIf class template.
uint8_t type_
The type of the matrix.
Definition: MatrixSerializer.h:316
uint8_t elementType_
The type of an element.
Definition: MatrixSerializer.h:317
Compile time check for row-major matrix types.This type trait tests whether or not the given template...
Definition: IsRowMajorMatrix.h:104
void serializeMatrix(Archive &archive, const DenseMatrix< MT, SO > &mat)
Serializes the elements of a dense matrix.
Definition: MatrixSerializer.h:422
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
Constraint on the data type.
void serialize(Archive &archive, const Matrix< MT, SO > &mat)
Serializes the given matrix and writes it to the archive.
Definition: MatrixSerializer.h:1265
Header file for the DenseMatrix base class.
DisableIf< IsResizable< MT > >::Type prepareMatrix(DenseMatrix< MT, SO > &mat)
Prepares the given non-resizable dense matrix for the deserialization process.
Definition: MatrixSerializer.h:564
uint64_t rows_
The number of rows of the matrix.
Definition: MatrixSerializer.h:319
Header file for the implementation of a dynamic MxN matrix.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2382
Header file for the IsDenseMatrix type trait.
Header file for the EnableIf class template.
64-bit unsigned integer type of the Blaze library.
Header file for the IsNumeric type trait.
Compile time check for resizable data types.This type trait tests whether the given data type is a re...
Definition: IsResizable.h:75
Header file for the Matrix base class.
Serializer for dense and sparse matrices.The MatrixSerializer implements the necessary logic to seria...
Definition: MatrixSerializer.h:157
Header file for run time assertion macros.
Conversion from a data type to a serial representation.This class template converts the given data ty...
Definition: TypeValueMapping.h:163
void deserializeSparseRowMatrix(Archive &archive, DenseMatrix< MT, SO > &mat)
Deserializes a row-major sparse matrix from the archive.
Definition: MatrixSerializer.h:930
uint64_t columns_
The number of columns of the matrix.
Definition: MatrixSerializer.h:320
void deserialize(Archive &archive, Matrix< MT, SO > &mat)
Deserializes a matrix from the given archive.
Definition: MatrixSerializer.h:504
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
void deserialize(Archive &archive, Matrix< MT, SO > &mat)
Deserializes a matrix from the given archive.
Definition: MatrixSerializer.h:1287
Header file for the TypeValueMapping class template.
uint8_t version_
The version of the archive.
Definition: MatrixSerializer.h:315
void serialize(Archive &archive, const Matrix< MT, SO > &mat)
Serializes the given matrix and writes it to the archive.
Definition: MatrixSerializer.h:370
uint8_t elementSize_
The size in bytes of a single element of the matrix.
Definition: MatrixSerializer.h:318
Header file for the IsRowMajorMatrix type trait.
const bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
size_t columns(const Matrix< MT, SO > &m)
Returns the current number of columns of the matrix.
Definition: Matrix.h:154
Header file for basic type definitions.
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a N-dimensional matrix type...
Definition: Matrix.h:79
Header file for the IsResizable type trait.
uint64_t number_
The total number of elements contained in the matrix.
Definition: MatrixSerializer.h:321
size_t rows(const Matrix< MT, SO > &m)
Returns the current number of rows of the matrix.
Definition: Matrix.h:138
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101