MatrixSerializer.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SERIALIZATION_MATRIXSERIALIZER_H_
36 #define _BLAZE_MATH_SERIALIZATION_MATRIXSERIALIZER_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
46 #include <blaze/math/Exception.h>
55 #include <blaze/util/Assert.h>
56 #include <blaze/util/DisableIf.h>
57 #include <blaze/util/EnableIf.h>
58 #include <blaze/util/Types.h>
60 
61 
62 namespace blaze {
63 
64 //=================================================================================================
65 //
66 // CLASS DEFINITION
67 //
68 //=================================================================================================
69 
70 //*************************************************************************************************
159 {
160  private:
161  //**Private class MatrixValueMappingHelper******************************************************
175  template< bool IsDenseMatrix, bool IsRowMajorMatrix >
176  struct MatrixValueMappingHelper;
178  //**********************************************************************************************
179 
180  //**Private class MatrixValueMapping************************************************************
188  template< typename T >
189  struct MatrixValueMapping
190  {
191  enum { value = MatrixValueMappingHelper< IsDenseMatrix_v<T>, IsRowMajorMatrix_v<T> >::value };
193  };
195  //**********************************************************************************************
196 
197  public:
198  //**Constructors********************************************************************************
201  explicit inline MatrixSerializer();
203  //**********************************************************************************************
204 
205  //**Serialization functions*********************************************************************
208  template< typename Archive, typename MT, bool SO >
209  void serialize( Archive& archive, const Matrix<MT,SO>& mat );
211  //**********************************************************************************************
212 
213  //**Deserialization functions*******************************************************************
216  template< typename Archive, typename MT, bool SO >
217  void deserialize( Archive& archive, Matrix<MT,SO>& mat );
219  //**********************************************************************************************
220 
221  private:
222  //**Serialization functions*********************************************************************
225  template< typename Archive, typename MT >
226  void serializeHeader( Archive& archive, const MT& mat );
227 
228  template< typename Archive, typename MT, bool SO >
229  void serializeMatrix( Archive& archive, const DenseMatrix<MT,SO>& mat );
230 
231  template< typename Archive, typename MT, bool SO >
232  void serializeMatrix( Archive& archive, const SparseMatrix<MT,SO>& mat );
234  //**********************************************************************************************
235 
236  //**Deserialization functions*******************************************************************
239  template< typename Archive, typename MT >
240  void deserializeHeader( Archive& archive, const MT& mat );
241 
242  template< typename MT, bool SO >
244 
245  template< typename MT, bool SO >
247 
248  template< typename MT >
250 
251  template< typename Archive, typename MT >
252  void deserializeMatrix( Archive& archive, MT& mat );
253 
254  template< typename Archive, typename MT >
257 
258  template< typename Archive, typename MT, bool SO >
260 
261  template< typename Archive, typename MT, bool SO >
264 
265  template< typename Archive, typename MT, bool SO >
268 
269  template< typename Archive, typename MT >
272 
273  template< typename Archive, typename MT, bool SO >
275 
276  template< typename Archive, typename MT, bool SO >
279 
280  template< typename Archive, typename MT, bool SO >
283 
284  template< typename Archive, typename MT, bool SO >
286 
287  template< typename Archive, typename MT >
289 
290  template< typename Archive, typename MT >
292 
293  template< typename Archive, typename MT, bool SO >
295 
296  template< typename Archive, typename MT >
298 
299  template< typename Archive, typename MT >
302  //**********************************************************************************************
303 
304  //**Member variables****************************************************************************
314 
315  //**********************************************************************************************
316 };
317 //*************************************************************************************************
318 
319 
320 
321 
322 //=================================================================================================
323 //
324 // CONSTRUCTORS
325 //
326 //=================================================================================================
327 
328 //*************************************************************************************************
332  : version_ ( 0U ) // The version of the archive
333  , type_ ( 0U ) // The type of the matrix
334  , elementType_( 0U ) // The type of an element
335  , elementSize_( 0U ) // The size in bytes of a single element of the matrix
336  , rows_ ( 0UL ) // The number of rows of the matrix
337  , columns_ ( 0UL ) // The number of columns of the matrix
338  , number_ ( 0UL ) // The total number of elements contained in the matrix
339 {}
340 //*************************************************************************************************
341 
342 
343 
344 
345 //=================================================================================================
346 //
347 // SERIALIZATION FUNCTIONS
348 //
349 //=================================================================================================
350 
351 //*************************************************************************************************
359 template< typename Archive // Type of the archive
360  , typename MT // Type of the matrix
361  , bool SO > // Storage order
363 {
364  if( !archive ) {
365  BLAZE_THROW_RUNTIME_ERROR( "Faulty archive detected" );
366  }
367 
368  serializeHeader( archive, ~mat );
369  serializeMatrix( archive, ~mat );
370 }
371 //*************************************************************************************************
372 
373 
374 //*************************************************************************************************
382 template< typename Archive // Type of the archive
383  , typename MT > // Type of the matrix
384 void MatrixSerializer::serializeHeader( Archive& archive, const MT& mat )
385 {
386  using ET = ElementType_t<MT>;
387 
388  archive << uint8_t ( 1U );
389  archive << uint8_t ( MatrixValueMapping<MT>::value );
390  archive << uint8_t ( TypeValueMapping<ET>::value );
391  archive << uint8_t ( sizeof( ET ) );
392  archive << uint64_t( mat.rows() );
393  archive << uint64_t( mat.columns() );
394  archive << uint64_t( ( IsDenseMatrix_v<MT> ) ? ( mat.rows()*mat.columns() ) : ( mat.nonZeros() ) );
395 
396  if( !archive ) {
397  BLAZE_THROW_RUNTIME_ERROR( "File header could not be serialized" );
398  }
399 }
400 //*************************************************************************************************
401 
402 
403 //*************************************************************************************************
411 template< typename Archive // Type of the archive
412  , typename MT // Type of the matrix
413  , bool SO > // Storage order
415 {
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);
420  }
421  }
422  }
423  else {
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);
427  }
428  }
429  }
430 
431  if( !archive ) {
432  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be serialized" );
433  }
434 }
435 //*************************************************************************************************
436 
437 
438 //*************************************************************************************************
446 template< typename Archive // Type of the archive
447  , typename MT // Type of the matrix
448  , bool SO > // Storage order
450 {
451  if( IsRowMajorMatrix_v<MT> ) {
452  for( size_t i=0UL; i<(~mat).rows(); ++i ) {
453  archive << uint64_t( (~mat).nonZeros( i ) );
454  for( auto element=(~mat).begin(i); element!=(~mat).end(i); ++element ) {
455  archive << element->index() << element->value();
456  }
457  }
458  }
459  else {
460  for( size_t j=0UL; j<(~mat).columns(); ++j ) {
461  archive << uint64_t( (~mat).nonZeros( j ) );
462  for( auto element=(~mat).begin(j); element!=(~mat).end(j); ++element ) {
463  archive << element->index() << element->value();
464  }
465  }
466  }
467 
468  if( !archive ) {
469  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be serialized" );
470  }
471 }
472 //*************************************************************************************************
473 
474 
475 
476 
477 //=================================================================================================
478 //
479 // DESERIALIZATION FUNCTIONS
480 //
481 //=================================================================================================
482 
483 //*************************************************************************************************
491 template< typename Archive // Type of the archive
492  , typename MT // Type of the matrix
493  , bool SO > // Storage order
495 {
496  if( !archive ) {
497  BLAZE_THROW_INVALID_ARGUMENT( "Faulty archive detected" );
498  }
499 
500  deserializeHeader( archive, ~mat );
501  prepareMatrix( ~mat );
502  deserializeMatrix( archive, ~mat );
503 }
504 //*************************************************************************************************
505 
506 
507 //*************************************************************************************************
515 template< typename Archive // Type of the archive
516  , typename MT > // Type of the matrix
517 void MatrixSerializer::deserializeHeader( Archive& archive, const MT& mat )
518 {
519  using ET = ElementType_t<MT>;
520 
521  if( !( archive >> version_ >> type_ >> elementType_ >> elementSize_ >> rows_ >> columns_ >> number_ ) ) {
522  BLAZE_THROW_RUNTIME_ERROR( "Corrupt archive detected" );
523  }
524  else if( version_ != 1UL ) {
525  BLAZE_THROW_RUNTIME_ERROR( "Invalid version detected" );
526  }
527  else if( ( type_ & 1U ) != 1U || ( type_ & (~7U) ) != 0U ) {
528  BLAZE_THROW_RUNTIME_ERROR( "Invalid matrix type detected" );
529  }
531  BLAZE_THROW_RUNTIME_ERROR( "Invalid element type detected" );
532  }
533  else if( elementSize_ != sizeof( ET ) ) {
534  BLAZE_THROW_RUNTIME_ERROR( "Invalid element size detected" );
535  }
536  else if( !IsResizable_v<MT> && ( rows_ != mat.rows() || columns_ != mat.columns() ) ) {
537  BLAZE_THROW_RUNTIME_ERROR( "Invalid matrix size detected" );
538  }
539  else if( number_ > rows_*columns_ ) {
540  BLAZE_THROW_RUNTIME_ERROR( "Invalid number of elements detected" );
541  }
542 }
543 //*************************************************************************************************
544 
545 
546 //*************************************************************************************************
552 template< typename MT // Type of the dense matrix
553  , bool SO > // Storage order
555 {
556  reset( ~mat );
557 }
558 //*************************************************************************************************
559 
560 
561 //*************************************************************************************************
567 template< typename MT // Type of the sparse matrix
568  , bool SO > // Storage order
570 {
571  (~mat).reserve( number_ );
572  reset( ~mat );
573 }
574 //*************************************************************************************************
575 
576 
577 //*************************************************************************************************
583 template< typename MT > // Type of the matrix
585 {
586  mat.resize ( rows_, columns_, false );
587  mat.reserve( number_ );
588  reset( mat );
589 }
590 //*************************************************************************************************
591 
592 
593 //*************************************************************************************************
604 template< typename Archive // Type of the archive
605  , typename MT > // Type of the matrix
607 {
608  if( type_ == 1U ) {
609  deserializeDenseRowMatrix( archive, ~mat );
610  }
611  else if( type_ == 5UL ) {
612  deserializeDenseColumnMatrix( archive, ~mat );
613  }
614  else if( type_ == 3UL ) {
615  deserializeSparseRowMatrix( archive, ~mat );
616  }
617  else if( type_ == 7UL ) {
618  deserializeSparseColumnMatrix( archive, ~mat );
619  }
620  else {
621  BLAZE_INTERNAL_ASSERT( false, "Undefined type flag" );
622  }
623 }
624 //*************************************************************************************************
625 
626 
627 //*************************************************************************************************
639 template< typename Archive // Type of the archive
640  , typename MT > // Type of the matrix
643 {
644  if( columns_ == 0UL ) return;
645 
646  for( size_t i=0UL; i<rows_; ++i ) {
647  archive.read( &(~mat)(i,0), columns_ );
648  }
649 
650  if( !archive ) {
651  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be deserialized" );
652  }
653 }
654 //*************************************************************************************************
655 
656 
657 //*************************************************************************************************
669 template< typename Archive // Type of the archive
670  , typename MT // Type of the matrix
671  , bool SO > // Storage order
673 {
674  using ET = ElementType_t<MT>;
675 
676  ET value{};
677 
678  for( size_t i=0UL; i<rows_; ++i ) {
679  size_t j( 0UL );
680  while( ( j != columns_ ) && ( archive >> value ) ) {
681  (~mat)(i,j) = value;
682  ++j;
683  }
684  }
685 
686  if( !archive ) {
687  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be deserialized" );
688  }
689 }
690 //*************************************************************************************************
691 
692 
693 //*************************************************************************************************
705 template< typename Archive // Type of the archive
706  , typename MT // Type of the matrix
707  , bool SO > // Storage order
710 {
712  deserializeDenseRowMatrix( archive, tmp );
713  (~mat) = tmp;
714 
715  if( !archive ) {
716  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
717  }
718 }
719 //*************************************************************************************************
720 
721 
722 //*************************************************************************************************
734 template< typename Archive // Type of the archive
735  , typename MT // Type of the matrix
736  , bool SO > // Storage order
739 {
740  using ET = ElementType_t<MT>;
741 
742  ET value{};
743 
744  const size_t dim1( ( SO == rowMajor )?( rows_ ):( columns_ ) );
745  const size_t dim2( ( SO != rowMajor )?( rows_ ):( columns_ ) );
746 
747  for( size_t i=0UL; i<dim1; ++i ) {
748  (~mat).reserve( i, dim2 );
749  }
750 
751  for( size_t i=0UL; i<rows_; ++i ) {
752  size_t j( 0UL );
753  while( ( j != columns_ ) && ( archive >> value ) ) {
754  (~mat).append( i, j, value, false );
755  ++j;
756  }
757  }
758 
759  if( !archive ) {
760  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
761  }
762 }
763 //*************************************************************************************************
764 
765 
766 //*************************************************************************************************
778 template< typename Archive // Type of the archive
779  , typename MT > // Type of the matrix
782 {
783  if( rows_ == 0UL ) return;
784 
785  for( size_t j=0UL; j<columns_; ++j ) {
786  archive.read( &(~mat)(0,j), rows_ );
787  }
788 
789  if( !archive ) {
790  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be deserialized" );
791  }
792 }
793 //*************************************************************************************************
794 
795 
796 //*************************************************************************************************
808 template< typename Archive // Type of the archive
809  , typename MT // Type of the matrix
810  , bool SO > // Storage order
812 {
813  using ET = ElementType_t<MT>;
814 
815  ET value{};
816 
817  for( size_t j=0UL; j<columns_; ++j ) {
818  size_t i( 0UL );
819  while( ( i != rows_ ) && ( archive >> value ) ) {
820  (~mat)(i,j) = value;
821  ++i;
822  }
823  }
824 
825  if( !archive ) {
826  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be deserialized" );
827  }
828 }
829 //*************************************************************************************************
830 
831 
832 //*************************************************************************************************
844 template< typename Archive // Type of the archive
845  , typename MT // Type of the matrix
846  , bool SO > // Storage order
849 {
851  deserializeDenseColumnMatrix( archive, tmp );
852  (~mat) = tmp;
853 
854  if( !archive ) {
855  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
856  }
857 }
858 //*************************************************************************************************
859 
860 
861 //*************************************************************************************************
873 template< typename Archive // Type of the archive
874  , typename MT // Type of the matrix
875  , bool SO > // Storage order
878 {
879  using ET = ElementType_t<MT>;
880 
881  ET value{};
882 
883  const size_t dim1( ( SO == rowMajor )?( rows_ ):( columns_ ) );
884  const size_t dim2( ( SO != rowMajor )?( rows_ ):( columns_ ) );
885 
886  for( size_t i=0UL; i<dim1; ++i ) {
887  (~mat).reserve( i, dim2 );
888  }
889 
890  for( size_t j=0UL; j<columns_; ++j ) {
891  size_t i( 0UL );
892  while( ( i != rows_ ) && ( archive >> value ) ) {
893  (~mat).append( i, j, value, false );
894  ++i;
895  }
896  }
897 
898  if( !archive ) {
899  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
900  }
901 }
902 //*************************************************************************************************
903 
904 
905 //*************************************************************************************************
917 template< typename Archive // Type of the archive
918  , typename MT // Type of the matrix
919  , bool SO > // Storage order
921 {
922  using ET = ElementType_t<MT>;
923 
924  uint64_t number( 0UL );
925  size_t index ( 0UL );
926  ET value {};
927 
928  for( size_t i=0UL; i<rows_; ++i ) {
929  archive >> number;
930  size_t j( 0UL );
931  while( ( j != number ) && ( archive >> index >> value ) ) {
932  (~mat)(i,index) = value;
933  ++j;
934  }
935  }
936 
937  if( !archive ) {
938  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be deserialized" );
939  }
940 }
941 //*************************************************************************************************
942 
943 
944 //*************************************************************************************************
956 template< typename Archive // Type of the archive
957  , typename MT > // Type of the matrix
959 {
960  using ET = ElementType_t<MT>;
961 
962  uint64_t number( 0UL );
963  size_t index ( 0UL );
964  ET value {};
965 
966  for( size_t i=0UL; i<rows_; ++i )
967  {
968  archive >> number;
969 
970  size_t j( 0UL );
971  while( ( j != number ) && ( archive >> index >> value ) ) {
972  (~mat).append( i, index, value, false );
973  ++j;
974  }
975 
976  (~mat).finalize( i );
977  }
978 
979  if( !archive ) {
980  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
981  }
982 }
983 //*************************************************************************************************
984 
985 
986 //*************************************************************************************************
998 template< typename Archive // Type of the archive
999  , typename MT > // Type of the matrix
1001 {
1003  deserializeSparseRowMatrix( archive, tmp );
1004  (~mat) = tmp;
1005 
1006  if( !archive ) {
1007  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
1008  }
1009 }
1010 //*************************************************************************************************
1011 
1012 
1013 //*************************************************************************************************
1025 template< typename Archive // Type of the archive
1026  , typename MT // Type of the matrix
1027  , bool SO > // Storage order
1029 {
1030  using ET = ElementType_t<MT>;
1031 
1032  uint64_t number( 0UL );
1033  size_t index ( 0UL );
1034  ET value {};
1035 
1036  for( size_t j=0UL; j<columns_; ++j ) {
1037  archive >> number;
1038  size_t i( 0UL );
1039  while( ( i != number ) && ( archive >> index >> value ) ) {
1040  (~mat)(index,j) = value;
1041  ++i;
1042  }
1043  }
1044 
1045  if( !archive ) {
1046  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be deserialized" );
1047  }
1048 }
1049 //*************************************************************************************************
1050 
1051 
1052 //*************************************************************************************************
1064 template< typename Archive // Type of the archive
1065  , typename MT > // Type of the matrix
1067 {
1069  deserializeSparseColumnMatrix( archive, tmp );
1070  (~mat) = tmp;
1071 
1072  if( !archive ) {
1073  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
1074  }
1075 }
1076 //*************************************************************************************************
1077 
1078 
1079 //*************************************************************************************************
1091 template< typename Archive // Type of the archive
1092  , typename MT > // Type of the matrix
1094 {
1095  using ET = ElementType_t<MT>;
1096 
1097  uint64_t number( 0UL );
1098  size_t index ( 0UL );
1099  ET value {};
1100 
1101  for( size_t j=0UL; j<columns_; ++j )
1102  {
1103  archive >> number;
1104 
1105  size_t i( 0UL );
1106  while( ( i != number ) && ( archive >> index >> value ) ) {
1107  (~mat).append( index, j, value, false );
1108  ++i;
1109  }
1110 
1111  (~mat).finalize( j );
1112  }
1113 
1114  if( !archive ) {
1115  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
1116  }
1117 }
1118 //*************************************************************************************************
1119 
1120 
1121 
1122 
1123 //=================================================================================================
1124 //
1125 // MATRIXVALUEMAPPINGHELPER SPECIALIZATIONS
1126 //
1127 //=================================================================================================
1128 
1129 //*************************************************************************************************
1133 template<>
1134 struct MatrixSerializer::MatrixValueMappingHelper<true,true>
1135 {
1136  enum { value = 1 };
1137 };
1139 //*************************************************************************************************
1140 
1141 
1142 //*************************************************************************************************
1146 template<>
1147 struct MatrixSerializer::MatrixValueMappingHelper<true,false>
1148 {
1149  enum { value = 5 };
1150 };
1152 //*************************************************************************************************
1153 
1154 
1155 //*************************************************************************************************
1159 template<>
1160 struct MatrixSerializer::MatrixValueMappingHelper<false,true>
1161 {
1162  enum { value = 3 };
1163 };
1165 //*************************************************************************************************
1166 
1167 
1168 //*************************************************************************************************
1172 template<>
1173 struct MatrixSerializer::MatrixValueMappingHelper<false,false>
1174 {
1175  enum { value = 7 };
1176 };
1178 //*************************************************************************************************
1179 
1180 
1181 
1182 
1183 //=================================================================================================
1184 //
1185 // GLOBAL FUNCTIONS
1186 //
1187 //=================================================================================================
1188 
1189 //*************************************************************************************************
1254 template< typename Archive // Type of the archive
1255  , typename MT // Type of the matrix
1256  , bool SO > // Storage order
1257 void serialize( Archive& archive, const Matrix<MT,SO>& mat )
1258 {
1259  MatrixSerializer().serialize( archive, ~mat );
1260 }
1261 //*************************************************************************************************
1262 
1263 
1264 //*************************************************************************************************
1276 template< typename Archive // Type of the archive
1277  , typename MT // Type of the matrix
1278  , bool SO > // Storage order
1279 void deserialize( Archive& archive, Matrix<MT,SO>& mat )
1280 {
1281  MatrixSerializer().deserialize( archive, ~mat );
1282 }
1283 //*************************************************************************************************
1284 
1285 } // namespace blaze
1286 
1287 #endif
#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