35 #ifndef _BLAZE_MATH_SERIALIZATION_MATRIXSERIALIZER_H_
36 #define _BLAZE_MATH_SERIALIZATION_MATRIXSERIALIZER_H_
175 template<
bool IsDenseMatrix,
bool IsRowMajorMatrix >
176 struct MatrixValueMappingHelper;
188 template<
typename T >
189 struct MatrixValueMapping
217 template<
typename Archive,
typename MT,
bool SO >
225 template<
typename Archive,
typename MT,
bool SO >
234 template<
typename Archive,
typename MT >
237 template<
typename Archive,
typename MT,
bool SO >
240 template<
typename Archive,
typename MT,
bool SO >
248 template<
typename Archive,
typename MT >
251 template<
typename MT >
254 template<
typename MT >
257 template<
typename Archive,
typename MT >
260 template<
typename Archive,
typename MT >
264 template<
typename Archive,
typename MT,
bool SO >
267 template<
typename Archive,
typename MT,
bool SO >
271 template<
typename Archive,
typename MT,
bool SO >
275 template<
typename Archive,
typename MT >
279 template<
typename Archive,
typename MT,
bool SO >
282 template<
typename Archive,
typename MT,
bool SO >
286 template<
typename Archive,
typename MT,
bool SO >
290 template<
typename Archive,
typename MT,
bool SO >
293 template<
typename Archive,
typename MT >
296 template<
typename Archive,
typename MT >
299 template<
typename Archive,
typename MT,
bool SO >
302 template<
typename Archive,
typename MT >
305 template<
typename Archive,
typename MT >
371 throw std::runtime_error(
"Faulty archive detected" );
395 archive << uint8_t ( MatrixValueMapping<MT>::value );
396 archive << uint8_t ( TypeValueMapping<ET>::value );
397 archive << uint8_t (
sizeof( ET ) );
399 archive <<
uint64_t( mat.columns() );
400 archive << uint64_t( ( IsDenseMatrix<MT>::value ) ? ( mat.rows()*mat.columns() ) : ( mat.nonZeros() ) );
403 throw std::runtime_error(
"File header could not be serialized" );
423 for(
size_t i=0UL; i<(~mat).
rows(); ++i ) {
424 for(
size_t j=0UL; j<(~mat).
columns(); ++j ) {
425 archive << (~mat)(i,j);
430 for(
size_t j=0UL; j<(~mat).
columns(); ++j ) {
431 for(
size_t i=0UL; i<(~mat).
rows(); ++i ) {
432 archive << (~mat)(i,j);
438 throw std::runtime_error(
"Dense matrix could not be serialized" );
460 for(
size_t i=0UL; i<(~mat).
rows(); ++i ) {
461 archive <<
uint64_t( (~mat).nonZeros( i ) );
462 for( ConstIterator element=(~mat).begin(i); element!=(~mat).end(i); ++element ) {
463 archive << element->index() << element->value();
468 for(
size_t j=0UL; j<(~mat).
columns(); ++j ) {
469 archive <<
uint64_t( (~mat).nonZeros( j ) );
470 for( ConstIterator element=(~mat).begin(j); element!=(~mat).end(j); ++element ) {
471 archive << element->index() << element->value();
477 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 >
576 template<
typename MT >
604 else if(
type_ == 5UL ) {
607 else if(
type_ == 3UL ) {
610 else if(
type_ == 7UL ) {
639 for(
size_t i=0UL; i<
rows_; ++i ) {
640 archive.read( &(~mat)(i,0),
columns_ );
644 throw std::runtime_error(
"Dense matrix could not be deserialized" );
671 for(
size_t i=0UL; i<
rows_; ++i ) {
673 while( ( j !=
columns_ ) && ( archive >> value ) ) {
680 throw std::runtime_error(
"Dense matrix could not be deserialized" );
709 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
740 for(
size_t i=0UL; i<dim1; ++i ) {
741 (~mat).reserve( i, dim2 );
744 for(
size_t i=0UL; i<
rows_; ++i ) {
746 while( ( j !=
columns_ ) && ( archive >> value ) ) {
747 (~mat).append( i, j, value,
false );
753 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
776 if(
rows_ == 0UL )
return;
778 for(
size_t j=0UL; j<
columns_; ++j ) {
779 archive.read( &(~mat)(0,j),
rows_ );
783 throw std::runtime_error(
"Dense matrix could not be deserialized" );
810 for(
size_t j=0UL; j<
columns_; ++j ) {
812 while( ( i !=
rows_ ) && ( archive >> value ) ) {
819 throw std::runtime_error(
"Dense matrix could not be deserialized" );
848 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
879 for(
size_t i=0UL; i<dim1; ++i ) {
880 (~mat).reserve( i, dim2 );
883 for(
size_t j=0UL; j<
columns_; ++j ) {
885 while( ( i !=
rows_ ) && ( archive >> value ) ) {
886 (~mat).append( i, j, value,
false );
892 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
918 size_t index ( 0UL );
921 for(
size_t i=0UL; i<
rows_; ++i ) {
924 while( ( j != number ) && ( archive >> index >> value ) ) {
925 (~mat)(i,index) = value;
931 throw std::runtime_error(
"Dense matrix could not be deserialized" );
956 size_t index ( 0UL );
959 for(
size_t i=0UL; i<
rows_; ++i )
962 (~mat).reserve( i, number );
965 while( ( j != number ) && ( archive >> index >> value ) ) {
966 (~mat).append( i, index, value,
false );
972 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
999 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
1025 size_t index ( 0UL );
1028 for(
size_t j=0UL; j<
columns_; ++j ) {
1031 while( ( i != number ) && ( archive >> index >> value ) ) {
1032 (~mat)(index,j) = value;
1038 throw std::runtime_error(
"Dense matrix could not be deserialized" );
1065 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
1090 size_t index ( 0UL );
1093 for(
size_t j=0UL; j<
columns_; ++j )
1096 (~mat).reserve( j, number );
1099 while( ( i != number ) && ( archive >> index >> value ) ) {
1100 (~mat).append( index, j, value,
false );
1106 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
1125 struct MatrixSerializer::MatrixValueMappingHelper<true,true>
1138 struct MatrixSerializer::MatrixValueMappingHelper<true,false>
1151 struct MatrixSerializer::MatrixValueMappingHelper<false,true>
1164 struct MatrixSerializer::MatrixValueMappingHelper<false,false>
1245 template<
typename Archive
1267 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:4512
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:635
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:196
Constraint on the data type.
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:176
EnableIfTrue< MT::vectorizable >::Type deserializeDenseColumnMatrix(Archive &archive, DenseMatrix< MT, columnMajor > &mat)
Deserializes a column-major dense matrix from the archive.
Definition: MatrixSerializer.h:774
void serializeHeader(Archive &archive, const MT &mat)
Serializes all meta information about the given matrix.
Definition: MatrixSerializer.h:390
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:337
DisableIf< IsResizable< MT > >::Type prepareMatrix(MT &mat)
Prepares the given non-resizable matrix for the deserialization process.
Definition: MatrixSerializer.h:563
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:1020
void deserializeMatrix(Archive &archive, MT &mat)
Deserializes a matrix from the archive.
Definition: MatrixSerializer.h:599
Header file for the DisableIf class template.
uint8_t type_
The type of the matrix.
Definition: MatrixSerializer.h:314
uint8_t elementType_
The type of an element.
Definition: MatrixSerializer.h:315
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:420
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2379
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:1248
Header file for the DenseMatrix base class.
uint64_t rows_
The number of rows of the matrix.
Definition: MatrixSerializer.h:317
Header file for the implementation of a dynamic MxN matrix.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2373
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:158
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:913
uint64_t columns_
The number of columns of the matrix.
Definition: MatrixSerializer.h:318
void deserialize(Archive &archive, Matrix< MT, SO > &mat)
Deserializes a matrix from the given archive.
Definition: MatrixSerializer.h:502
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:1270
Header file for the TypeValueMapping class template.
uint8_t version_
The version of the archive.
Definition: MatrixSerializer.h:313
void serialize(Archive &archive, const Matrix< MT, SO > &mat)
Serializes the given matrix and writes it to the archive.
Definition: MatrixSerializer.h:368
uint8_t elementSize_
The size in bytes of a single element of the matrix.
Definition: MatrixSerializer.h:316
Header file for the IsRowMajorMatrix type trait.
const bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
#define BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE(T)
Constraint on the data type.In case the given data type T is an expression (i.e. a type derived from ...
Definition: Expression.h:118
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:319
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