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
190 enum { value = MatrixValueMappingHelper< IsDenseMatrix_v<T>, IsRowMajorMatrix_v<T> >::value };
207 template<
typename Archive,
typename MT,
bool SO >
215 template<
typename Archive,
typename MT,
bool SO >
224 template<
typename Archive,
typename MT >
227 template<
typename Archive,
typename MT,
bool SO >
230 template<
typename Archive,
typename MT,
bool SO >
238 template<
typename Archive,
typename MT >
241 template<
typename MT,
bool SO >
244 template<
typename MT,
bool SO >
247 template<
typename MT >
250 template<
typename Archive,
typename MT >
253 template<
typename Archive,
typename MT >
257 template<
typename Archive,
typename MT,
bool SO >
260 template<
typename Archive,
typename MT,
bool SO >
264 template<
typename Archive,
typename MT,
bool SO >
268 template<
typename Archive,
typename MT >
272 template<
typename Archive,
typename MT,
bool SO >
275 template<
typename Archive,
typename MT,
bool SO >
279 template<
typename Archive,
typename MT,
bool SO >
283 template<
typename Archive,
typename MT,
bool SO >
286 template<
typename Archive,
typename MT >
289 template<
typename Archive,
typename MT >
292 template<
typename Archive,
typename MT,
bool SO >
295 template<
typename Archive,
typename MT >
298 template<
typename Archive,
typename MT >
387 archive << uint8_t ( 1U );
388 archive << uint8_t ( MatrixValueMapping<MT>::value );
390 archive << uint8_t (
sizeof( ET ) );
391 archive << uint64_t( mat.rows() );
392 archive << uint64_t( mat.columns() );
393 archive << uint64_t( ( IsDenseMatrix_v<MT> ) ? ( mat.rows()*mat.columns() ) : ( mat.nonZeros() ) );
415 if( IsRowMajorMatrix_v<MT> ) {
416 for(
size_t i=0UL; i<(*mat).rows(); ++i ) {
417 for(
size_t j=0UL; j<(*mat).columns(); ++j ) {
418 archive << (*mat)(i,j);
423 for(
size_t j=0UL; j<(*mat).columns(); ++j ) {
424 for(
size_t i=0UL; i<(*mat).rows(); ++i ) {
425 archive << (*mat)(i,j);
450 if( IsRowMajorMatrix_v<MT> ) {
451 for(
size_t i=0UL; i<(*mat).rows(); ++i ) {
452 archive << uint64_t( (*mat).nonZeros( i ) );
453 for(
auto element=(*mat).begin(i); element!=(*mat).end(i); ++element ) {
454 archive << element->index() << element->value();
459 for(
size_t j=0UL; j<(*mat).columns(); ++j ) {
460 archive << uint64_t( (*mat).nonZeros( j ) );
461 for(
auto element=(*mat).begin(j); element!=(*mat).end(j); ++element ) {
462 archive << element->index() << element->value();
526 else if( (
type_ & 1U ) != 1U || (
type_ & (~7U) ) != 0U ) {
535 else if( !IsResizable_v<MT> && (
rows_ != mat.rows() ||
columns_ != mat.columns() ) ) {
582template<
typename MT >
610 else if(
type_ == 5UL ) {
613 else if(
type_ == 3UL ) {
616 else if(
type_ == 7UL ) {
645 for(
size_t i=0UL; i<
rows_; ++i ) {
646 archive.read( &(*mat)(i,0),
columns_ );
677 for(
size_t i=0UL; i<
rows_; ++i ) {
679 while( ( j !=
columns_ ) && ( archive >> value ) ) {
746 for(
size_t i=0UL; i<dim1; ++i ) {
747 (*mat).reserve( i, dim2 );
750 for(
size_t i=0UL; i<
rows_; ++i ) {
752 while( ( j !=
columns_ ) && ( archive >> value ) ) {
753 (*mat).append( i, j, value,
false );
782 if(
rows_ == 0UL )
return;
784 for(
size_t j=0UL; j<
columns_; ++j ) {
785 archive.read( &(*mat)(0,j),
rows_ );
816 for(
size_t j=0UL; j<
columns_; ++j ) {
818 while( ( i !=
rows_ ) && ( archive >> value ) ) {
885 for(
size_t i=0UL; i<dim1; ++i ) {
886 (*mat).reserve( i, dim2 );
889 for(
size_t j=0UL; j<
columns_; ++j ) {
891 while( ( i !=
rows_ ) && ( archive >> value ) ) {
892 (*mat).append( i, j, value,
false );
923 uint64_t number( 0UL );
924 size_t index ( 0UL );
927 for(
size_t i=0UL; i<
rows_; ++i ) {
930 while( ( j != number ) && ( archive >> index >> value ) ) {
931 (*mat)(i,index) = value;
961 uint64_t number( 0UL );
962 size_t index ( 0UL );
965 for(
size_t i=0UL; i<
rows_; ++i )
970 while( ( j != number ) && ( archive >> index >> value ) ) {
971 (*mat).append( i, index, value,
false );
975 (*mat).finalize( i );
1031 uint64_t number( 0UL );
1032 size_t index ( 0UL );
1035 for(
size_t j=0UL; j<
columns_; ++j ) {
1038 while( ( i != number ) && ( archive >> index >> value ) ) {
1039 (*mat)(index,j) = value;
1096 uint64_t number( 0UL );
1097 size_t index ( 0UL );
1100 for(
size_t j=0UL; j<
columns_; ++j )
1105 while( ( i != number ) && ( archive >> index >> value ) ) {
1106 (*mat).append( index, j, value,
false );
1110 (*mat).finalize( j );
1133struct MatrixSerializer::MatrixValueMappingHelper<true,true>
1146struct MatrixSerializer::MatrixValueMappingHelper<true,false>
1159struct MatrixSerializer::MatrixValueMappingHelper<false,true>
1172struct MatrixSerializer::MatrixValueMappingHelper<false,false>
1253template<
typename Archive
1275template<
typename Archive
Header file for auxiliary alias declarations.
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
Header file for run time assertion macros.
Header file for the EnableIf class template.
Header file for the IsDenseMatrix type trait.
Header file for the IsNumeric type trait.
Header file for the IsResizable type trait.
Header file for the IsRowMajorMatrix type trait.
void serialize(Archive &archive, const Matrix< MT, SO > &mat)
Serializes the given matrix and writes it to the archive.
Definition: MatrixSerializer.h:1256
void deserialize(Archive &archive, Matrix< MT, SO > &mat)
Deserializes a matrix from the given archive.
Definition: MatrixSerializer.h:1278
Header file for the TypeValueMapping class template.
Binary archive for the portable serialization of data.
Definition: Archive.h:140
Efficient implementation of a compressed matrix.
Definition: CompressedMatrix.h:239
Base class for dense matrices.
Definition: DenseMatrix.h:82
Efficient implementation of a dynamic matrix.
Definition: DynamicMatrix.h:242
Serializer for dense and sparse matrices.
Definition: MatrixSerializer.h:158
DisableIf_t< IsResizable_v< MT > > prepareMatrix(DenseMatrix< MT, SO > &mat)
Prepares the given non-resizable dense matrix for the deserialization process.
Definition: MatrixSerializer.h:553
EnableIf_t< MT::simdEnabled > deserializeDenseRowMatrix(Archive &archive, DenseMatrix< MT, rowMajor > &mat)
Deserializes a row-major dense matrix from the archive.
Definition: MatrixSerializer.h:641
void serializeHeader(Archive &archive, const MT &mat)
Serializes all meta information about the given matrix.
Definition: MatrixSerializer.h:383
uint64_t columns_
The number of columns of the matrix.
Definition: MatrixSerializer.h:311
uint8_t elementType_
The type of an element.
Definition: MatrixSerializer.h:308
void deserialize(Archive &archive, Matrix< MT, SO > &mat)
Deserializes a matrix from the given archive.
Definition: MatrixSerializer.h:493
uint8_t elementSize_
The size in bytes of a single element of the matrix.
Definition: MatrixSerializer.h:309
uint64_t rows_
The number of rows of the matrix.
Definition: MatrixSerializer.h:310
EnableIf_t< MT::simdEnabled > deserializeDenseColumnMatrix(Archive &archive, DenseMatrix< MT, columnMajor > &mat)
Deserializes a column-major dense matrix from the archive.
Definition: MatrixSerializer.h:780
uint8_t type_
The type of the matrix.
Definition: MatrixSerializer.h:307
void serialize(Archive &archive, const Matrix< MT, SO > &mat)
Serializes the given matrix and writes it to the archive.
Definition: MatrixSerializer.h:361
uint8_t version_
The version of the archive.
Definition: MatrixSerializer.h:306
MatrixSerializer()
The default constructor of the MatrixSerializer class.
Definition: MatrixSerializer.h:330
void deserializeHeader(Archive &archive, const MT &mat)
Deserializes all meta information about the given matrix.
Definition: MatrixSerializer.h:516
void deserializeSparseRowMatrix(Archive &archive, DenseMatrix< MT, SO > &mat)
Deserializes a row-major sparse matrix from the archive.
Definition: MatrixSerializer.h:919
void deserializeSparseColumnMatrix(Archive &archive, DenseMatrix< MT, SO > &mat)
Deserializes a column-major sparse matrix from the archive.
Definition: MatrixSerializer.h:1027
void serializeMatrix(Archive &archive, const DenseMatrix< MT, SO > &mat)
Serializes the elements of a dense matrix.
Definition: MatrixSerializer.h:413
void deserializeMatrix(Archive &archive, MT &mat)
Deserializes a matrix from the archive.
Definition: MatrixSerializer.h:605
uint64_t number_
The total number of elements contained in the matrix.
Definition: MatrixSerializer.h:312
Base class for matrices.
Definition: Matrix.h:85
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Constraint on the data type.
Header file for the implementation of a dynamic MxN matrix.
Header file for the DenseMatrix base class.
Header file for the Matrix base class.
Header file for the SparseMatrix base class.
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Matrix.h:61
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
#define BLAZE_THROW_RUNTIME_ERROR(MESSAGE)
Macro for the emission of a std::runtime_error exception.
Definition: Exception.h:379
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:175
Header file for the exception macros of the math module.
constexpr bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
constexpr bool columnMajor
Storage order flag for column-major matrices.
Definition: StorageOrder.h:99
Implementation of a compressed MxN matrix.
Conversion from a data type to a serial representation.
Definition: TypeValueMapping.h:164
Header file for basic type definitions.