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
191 enum { value = MatrixValueMappingHelper< IsDenseMatrix_v<T>, IsRowMajorMatrix_v<T> >::value };
208 template<
typename Archive,
typename MT,
bool SO >
216 template<
typename Archive,
typename MT,
bool SO >
225 template<
typename Archive,
typename MT >
228 template<
typename Archive,
typename MT,
bool SO >
231 template<
typename Archive,
typename MT,
bool SO >
239 template<
typename Archive,
typename MT >
242 template<
typename MT,
bool SO >
245 template<
typename MT,
bool SO >
248 template<
typename MT >
251 template<
typename Archive,
typename MT >
254 template<
typename Archive,
typename MT >
258 template<
typename Archive,
typename MT,
bool SO >
261 template<
typename Archive,
typename MT,
bool SO >
265 template<
typename Archive,
typename MT,
bool SO >
269 template<
typename Archive,
typename MT >
273 template<
typename Archive,
typename MT,
bool SO >
276 template<
typename Archive,
typename MT,
bool SO >
280 template<
typename Archive,
typename MT,
bool SO >
284 template<
typename Archive,
typename MT,
bool SO >
287 template<
typename Archive,
typename MT >
290 template<
typename Archive,
typename MT >
293 template<
typename Archive,
typename MT,
bool SO >
296 template<
typename Archive,
typename MT >
299 template<
typename Archive,
typename MT >
389 archive << uint8_t ( MatrixValueMapping<MT>::value );
390 archive << uint8_t ( TypeValueMapping<ET>::value );
391 archive <<
uint8_t (
sizeof( ET ) );
393 archive <<
uint64_t( mat.columns() );
394 archive << uint64_t( ( IsDenseMatrix_v<MT> ) ? ( mat.rows()*mat.columns() ) : ( mat.nonZeros() ) );
416 if( IsRowMajorMatrix_v<MT> ) {
417 for(
size_t i=0UL; i<(~mat).
rows(); ++i ) {
418 for(
size_t j=0UL; j<(~mat).
columns(); ++j ) {
419 archive << (~mat)(i,j);
424 for(
size_t j=0UL; j<(~mat).
columns(); ++j ) {
425 for(
size_t i=0UL; i<(~mat).
rows(); ++i ) {
426 archive << (~mat)(i,j);
451 if( IsRowMajorMatrix_v<MT> ) {
452 for(
size_t i=0UL; i<(~mat).
rows(); ++i ) {
454 for(
auto element=(~mat).
begin(i); element!=(~mat).
end(i); ++element ) {
455 archive << element->index() << element->value();
460 for(
size_t j=0UL; j<(~mat).
columns(); ++j ) {
462 for(
auto element=(~mat).
begin(j); element!=(~mat).
end(j); ++element ) {
463 archive << element->index() << element->value();
527 else if( (
type_ & 1U ) != 1U || (
type_ & (~7U) ) != 0U ) {
536 else if( !IsResizable_v<MT> && (
rows_ != mat.rows() ||
columns_ != mat.columns() ) ) {
552 template<
typename MT
567 template<
typename MT
583 template<
typename MT >
611 else if(
type_ == 5UL ) {
614 else if(
type_ == 3UL ) {
617 else if(
type_ == 7UL ) {
646 for(
size_t i=0UL; i<
rows_; ++i ) {
647 archive.read( &(~mat)(i,0),
columns_ );
678 for(
size_t i=0UL; i<
rows_; ++i ) {
680 while( ( j !=
columns_ ) && ( archive >> value ) ) {
747 for(
size_t i=0UL; i<dim1; ++i ) {
748 (~mat).reserve( i, dim2 );
751 for(
size_t i=0UL; i<
rows_; ++i ) {
753 while( ( j !=
columns_ ) && ( archive >> value ) ) {
754 (~mat).append( i, j, value,
false );
783 if(
rows_ == 0UL )
return;
785 for(
size_t j=0UL; j<
columns_; ++j ) {
786 archive.read( &(~mat)(0,j),
rows_ );
817 for(
size_t j=0UL; j<
columns_; ++j ) {
819 while( ( i !=
rows_ ) && ( archive >> value ) ) {
886 for(
size_t i=0UL; i<dim1; ++i ) {
887 (~mat).reserve( i, dim2 );
890 for(
size_t j=0UL; j<
columns_; ++j ) {
892 while( ( i !=
rows_ ) && ( archive >> value ) ) {
893 (~mat).append( i, j, value,
false );
925 size_t index ( 0UL );
928 for(
size_t i=0UL; i<
rows_; ++i ) {
931 while( ( j != number ) && ( archive >> index >> value ) ) {
932 (~mat)(i,index) = value;
963 size_t index ( 0UL );
966 for(
size_t i=0UL; i<
rows_; ++i )
971 while( ( j != number ) && ( archive >> index >> value ) ) {
972 (~mat).append( i, index, value,
false );
976 (~mat).finalize( i );
1033 size_t index ( 0UL );
1036 for(
size_t j=0UL; j<
columns_; ++j ) {
1039 while( ( i != number ) && ( archive >> index >> value ) ) {
1040 (~mat)(index,j) = value;
1098 size_t index ( 0UL );
1101 for(
size_t j=0UL; j<
columns_; ++j )
1106 while( ( i != number ) && ( archive >> index >> value ) ) {
1107 (~mat).append( index, j, value,
false );
1111 (~mat).finalize( j );
1134 struct MatrixSerializer::MatrixValueMappingHelper<true,true>
1147 struct MatrixSerializer::MatrixValueMappingHelper<true,false>
1160 struct MatrixSerializer::MatrixValueMappingHelper<false,true>
1173 struct MatrixSerializer::MatrixValueMappingHelper<false,false>
1254 template<
typename Archive
1276 template<
typename Archive
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for auxiliary alias declarations.
void deserializeHeader(Archive &archive, const MT &mat)
Deserializes all meta information about the given matrix.
Definition: MatrixSerializer.h:517
Binary archive for the portable serialization of data.The Archive class implements the functionality ...
Definition: Archive.h:140
Header file for basic type definitions.
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:224
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:372
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
8-bit unsigned integer type of the Blaze library.
Implementation of a compressed MxN matrix.
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:584
Efficient implementation of a dynamic matrix.The DynamicMatrix class template is the representation ...
Definition: DynamicMatrix.h:220
void serializeHeader(Archive &archive, const MT &mat)
Serializes all meta information about the given matrix.
Definition: MatrixSerializer.h:384
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
constexpr bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:80
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:137
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
MatrixSerializer()
The default constructor of the MatrixSerializer class.
Definition: MatrixSerializer.h:331
Header file for the SparseMatrix base class.
#define BLAZE_THROW_RUNTIME_ERROR(MESSAGE)
Macro for the emission of a std::runtime_error exception.This macro encapsulates the default way of B...
Definition: Exception.h:379
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
void deserializeSparseColumnMatrix(Archive &archive, DenseMatrix< MT, SO > &mat)
Deserializes a column-major sparse matrix from the archive.
Definition: MatrixSerializer.h:1028
constexpr bool columnMajor
Storage order flag for column-major matrices.
Definition: StorageOrder.h:99
void deserializeMatrix(Archive &archive, MT &mat)
Deserializes a matrix from the archive.
Definition: MatrixSerializer.h:606
Header file for the DisableIf class template.
uint8_t type_
The type of the matrix.
Definition: MatrixSerializer.h:308
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
uint8_t elementType_
The type of an element.
Definition: MatrixSerializer.h:309
void serializeMatrix(Archive &archive, const DenseMatrix< MT, SO > &mat)
Serializes the elements of a dense matrix.
Definition: MatrixSerializer.h:414
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:1257
Header file for the DenseMatrix base class.
uint64_t rows_
The number of rows of the matrix.
Definition: MatrixSerializer.h:311
Header file for the exception macros of the math module.
Header file for the implementation of a dynamic MxN matrix.
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:438
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.
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:920
uint64_t columns_
The number of columns of the matrix.
Definition: MatrixSerializer.h:312
void deserialize(Archive &archive, Matrix< MT, SO > &mat)
Deserializes a matrix from the given archive.
Definition: MatrixSerializer.h:494
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:109
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
void deserialize(Archive &archive, Matrix< MT, SO > &mat)
Deserializes a matrix from the given archive.
Definition: MatrixSerializer.h:1279
Header file for the TypeValueMapping class template.
uint8_t version_
The version of the archive.
Definition: MatrixSerializer.h:307
EnableIf_t< MT::simdEnabled > deserializeDenseColumnMatrix(Archive &archive, DenseMatrix< MT, columnMajor > &mat)
Deserializes a column-major dense matrix from the archive.
Definition: MatrixSerializer.h:781
void serialize(Archive &archive, const Matrix< MT, SO > &mat)
Serializes the given matrix and writes it to the archive.
Definition: MatrixSerializer.h:362
uint8_t elementSize_
The size in bytes of a single element of the matrix.
Definition: MatrixSerializer.h:310
Header file for the IsRowMajorMatrix type trait.
DisableIf_t< IsResizable_v< MT > > prepareMatrix(DenseMatrix< MT, SO > &mat)
Prepares the given non-resizable dense matrix for the deserialization process.
Definition: MatrixSerializer.h:554
EnableIf_t< MT::simdEnabled > deserializeDenseRowMatrix(Archive &archive, DenseMatrix< MT, rowMajor > &mat)
Deserializes a row-major dense matrix from the archive.
Definition: MatrixSerializer.h:642
#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:61
typename DisableIf< Condition, T >::Type DisableIf_t
Auxiliary type for the DisableIf class template.The DisableIf_t alias declaration provides a convenie...
Definition: DisableIf.h:138
Header file for the IsResizable type trait.
uint64_t number_
The total number of elements contained in the matrix.
Definition: MatrixSerializer.h:313
#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