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<T>::value, IsRowMajorMatrix<T>::value >::value };
193  };
195  //**********************************************************************************************
196 
197  public:
198  //**Constructor*********************************************************************************
201  explicit inline MatrixSerializer();
202  // No explicitly declared copy constructor.
204  //**********************************************************************************************
205 
206  //**Destructor**********************************************************************************
207  // No explicitly declared destructor.
208  //**********************************************************************************************
209 
210  //**Assignment operators************************************************************************
211  // No explicitly declared copy assignment operator.
212  //**********************************************************************************************
213 
214  //**Serialization functions*********************************************************************
217  template< typename Archive, typename MT, bool SO >
218  void serialize( Archive& archive, const Matrix<MT,SO>& mat );
220  //**********************************************************************************************
221 
222  //**Deserialization functions*******************************************************************
225  template< typename Archive, typename MT, bool SO >
226  void deserialize( Archive& archive, Matrix<MT,SO>& mat );
228  //**********************************************************************************************
229 
230  private:
231  //**Serialization functions*********************************************************************
234  template< typename Archive, typename MT >
235  void serializeHeader( Archive& archive, const MT& mat );
236 
237  template< typename Archive, typename MT, bool SO >
238  void serializeMatrix( Archive& archive, const DenseMatrix<MT,SO>& mat );
239 
240  template< typename Archive, typename MT, bool SO >
241  void serializeMatrix( Archive& archive, const SparseMatrix<MT,SO>& mat );
243  //**********************************************************************************************
244 
245  //**Deserialization functions*******************************************************************
248  template< typename Archive, typename MT >
249  void deserializeHeader( Archive& archive, const MT& mat );
250 
251  template< typename MT, bool SO >
253 
254  template< typename MT, bool SO >
256 
257  template< typename MT >
259 
260  template< typename Archive, typename MT >
261  void deserializeMatrix( Archive& archive, MT& mat );
262 
263  template< typename Archive, typename MT >
266 
267  template< typename Archive, typename MT, bool SO >
269 
270  template< typename Archive, typename MT, bool SO >
273 
274  template< typename Archive, typename MT, bool SO >
277 
278  template< typename Archive, typename MT >
281 
282  template< typename Archive, typename MT, bool SO >
284 
285  template< typename Archive, typename MT, bool SO >
288 
289  template< typename Archive, typename MT, bool SO >
292 
293  template< typename Archive, typename MT, bool SO >
295 
296  template< typename Archive, typename MT >
298 
299  template< typename Archive, typename MT >
301 
302  template< typename Archive, typename MT, bool SO >
304 
305  template< typename Archive, typename MT >
307 
308  template< typename Archive, typename MT >
311  //**********************************************************************************************
312 
313  //**Member variables****************************************************************************
323 
324  //**********************************************************************************************
325 };
326 //*************************************************************************************************
327 
328 
329 
330 
331 //=================================================================================================
332 //
333 // CONSTRUCTOR
334 //
335 //=================================================================================================
336 
337 //*************************************************************************************************
341  : version_ ( 0U ) // The version of the archive
342  , type_ ( 0U ) // The type of the matrix
343  , elementType_( 0U ) // The type of an element
344  , elementSize_( 0U ) // The size in bytes of a single element of the matrix
345  , rows_ ( 0UL ) // The number of rows of the matrix
346  , columns_ ( 0UL ) // The number of columns of the matrix
347  , number_ ( 0UL ) // The total number of elements contained in the matrix
348 {}
349 //*************************************************************************************************
350 
351 
352 
353 
354 //=================================================================================================
355 //
356 // SERIALIZATION FUNCTIONS
357 //
358 //=================================================================================================
359 
360 //*************************************************************************************************
368 template< typename Archive // Type of the archive
369  , typename MT // Type of the matrix
370  , bool SO > // Storage order
372 {
373  if( !archive ) {
374  BLAZE_THROW_RUNTIME_ERROR( "Faulty archive detected" );
375  }
376 
377  serializeHeader( archive, ~mat );
378  serializeMatrix( archive, ~mat );
379 }
380 //*************************************************************************************************
381 
382 
383 //*************************************************************************************************
391 template< typename Archive // Type of the archive
392  , typename MT > // Type of the matrix
393 void MatrixSerializer::serializeHeader( Archive& archive, const MT& mat )
394 {
395  typedef ElementType_<MT> ET;
396 
397  archive << uint8_t ( 1U );
398  archive << uint8_t ( MatrixValueMapping<MT>::value );
399  archive << uint8_t ( TypeValueMapping<ET>::value );
400  archive << uint8_t ( sizeof( ET ) );
401  archive << uint64_t( mat.rows() );
402  archive << uint64_t( mat.columns() );
403  archive << uint64_t( ( IsDenseMatrix<MT>::value ) ? ( mat.rows()*mat.columns() ) : ( mat.nonZeros() ) );
404 
405  if( !archive ) {
406  BLAZE_THROW_RUNTIME_ERROR( "File header could not be serialized" );
407  }
408 }
409 //*************************************************************************************************
410 
411 
412 //*************************************************************************************************
420 template< typename Archive // Type of the archive
421  , typename MT // Type of the matrix
422  , bool SO > // Storage order
424 {
426  for( size_t i=0UL; i<(~mat).rows(); ++i ) {
427  for( size_t j=0UL; j<(~mat).columns(); ++j ) {
428  archive << (~mat)(i,j);
429  }
430  }
431  }
432  else {
433  for( size_t j=0UL; j<(~mat).columns(); ++j ) {
434  for( size_t i=0UL; i<(~mat).rows(); ++i ) {
435  archive << (~mat)(i,j);
436  }
437  }
438  }
439 
440  if( !archive ) {
441  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be serialized" );
442  }
443 }
444 //*************************************************************************************************
445 
446 
447 //*************************************************************************************************
455 template< typename Archive // Type of the archive
456  , typename MT // Type of the matrix
457  , bool SO > // Storage order
459 {
461 
463  for( size_t i=0UL; i<(~mat).rows(); ++i ) {
464  archive << uint64_t( (~mat).nonZeros( i ) );
465  for( ConstIterator element=(~mat).begin(i); element!=(~mat).end(i); ++element ) {
466  archive << element->index() << element->value();
467  }
468  }
469  }
470  else {
471  for( size_t j=0UL; j<(~mat).columns(); ++j ) {
472  archive << uint64_t( (~mat).nonZeros( j ) );
473  for( ConstIterator element=(~mat).begin(j); element!=(~mat).end(j); ++element ) {
474  archive << element->index() << element->value();
475  }
476  }
477  }
478 
479  if( !archive ) {
480  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be serialized" );
481  }
482 }
483 //*************************************************************************************************
484 
485 
486 
487 
488 //=================================================================================================
489 //
490 // DESERIALIZATION FUNCTIONS
491 //
492 //=================================================================================================
493 
494 //*************************************************************************************************
502 template< typename Archive // Type of the archive
503  , typename MT // Type of the matrix
504  , bool SO > // Storage order
506 {
507  if( !archive ) {
508  BLAZE_THROW_INVALID_ARGUMENT( "Faulty archive detected" );
509  }
510 
511  deserializeHeader( archive, ~mat );
512  prepareMatrix( ~mat );
513  deserializeMatrix( archive, ~mat );
514 }
515 //*************************************************************************************************
516 
517 
518 //*************************************************************************************************
526 template< typename Archive // Type of the archive
527  , typename MT > // Type of the matrix
528 void MatrixSerializer::deserializeHeader( Archive& archive, const MT& mat )
529 {
530  typedef ElementType_<MT> ET;
531 
532  if( !( archive >> version_ >> type_ >> elementType_ >> elementSize_ >> rows_ >> columns_ >> number_ ) ) {
533  BLAZE_THROW_RUNTIME_ERROR( "Corrupt archive detected" );
534  }
535  else if( version_ != 1UL ) {
536  BLAZE_THROW_RUNTIME_ERROR( "Invalid version detected" );
537  }
538  else if( ( type_ & 1U ) != 1U || ( type_ & (~7U) ) != 0U ) {
539  BLAZE_THROW_RUNTIME_ERROR( "Invalid matrix type detected" );
540  }
542  BLAZE_THROW_RUNTIME_ERROR( "Invalid element type detected" );
543  }
544  else if( elementSize_ != sizeof( ET ) ) {
545  BLAZE_THROW_RUNTIME_ERROR( "Invalid element size detected" );
546  }
547  else if( !IsResizable<MT>::value && ( rows_ != mat.rows() || columns_ != mat.columns() ) ) {
548  BLAZE_THROW_RUNTIME_ERROR( "Invalid matrix size detected" );
549  }
550  else if( number_ > rows_*columns_ ) {
551  BLAZE_THROW_RUNTIME_ERROR( "Invalid number of elements detected" );
552  }
553 }
554 //*************************************************************************************************
555 
556 
557 //*************************************************************************************************
563 template< typename MT // Type of the dense matrix
564  , bool SO > // Storage order
566 {
567  reset( ~mat );
568 }
569 //*************************************************************************************************
570 
571 
572 //*************************************************************************************************
578 template< typename MT // Type of the sparse matrix
579  , bool SO > // Storage order
581 {
582  (~mat).reserve( number_ );
583  reset( ~mat );
584 }
585 //*************************************************************************************************
586 
587 
588 //*************************************************************************************************
594 template< typename MT > // Type of the matrix
596 {
597  mat.resize ( rows_, columns_, false );
598  mat.reserve( number_ );
599  reset( mat );
600 }
601 //*************************************************************************************************
602 
603 
604 //*************************************************************************************************
615 template< typename Archive // Type of the archive
616  , typename MT > // Type of the matrix
618 {
619  if( type_ == 1U ) {
620  deserializeDenseRowMatrix( archive, ~mat );
621  }
622  else if( type_ == 5UL ) {
623  deserializeDenseColumnMatrix( archive, ~mat );
624  }
625  else if( type_ == 3UL ) {
626  deserializeSparseRowMatrix( archive, ~mat );
627  }
628  else if( type_ == 7UL ) {
629  deserializeSparseColumnMatrix( archive, ~mat );
630  }
631  else {
632  BLAZE_INTERNAL_ASSERT( false, "Undefined type flag" );
633  }
634 }
635 //*************************************************************************************************
636 
637 
638 //*************************************************************************************************
650 template< typename Archive // Type of the archive
651  , typename MT > // Type of the matrix
654 {
655  if( columns_ == 0UL ) return;
656 
657  for( size_t i=0UL; i<rows_; ++i ) {
658  archive.read( &(~mat)(i,0), columns_ );
659  }
660 
661  if( !archive ) {
662  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be deserialized" );
663  }
664 }
665 //*************************************************************************************************
666 
667 
668 //*************************************************************************************************
680 template< typename Archive // Type of the archive
681  , typename MT // Type of the matrix
682  , bool SO > // Storage order
684 {
685  typedef ElementType_<MT> ET;
686 
687  ET value = ET();
688 
689  for( size_t i=0UL; i<rows_; ++i ) {
690  size_t j( 0UL );
691  while( ( j != columns_ ) && ( archive >> value ) ) {
692  (~mat)(i,j) = value;
693  ++j;
694  }
695  }
696 
697  if( !archive ) {
698  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be deserialized" );
699  }
700 }
701 //*************************************************************************************************
702 
703 
704 //*************************************************************************************************
716 template< typename Archive // Type of the archive
717  , typename MT // Type of the matrix
718  , bool SO > // Storage order
721 {
723  deserializeDenseRowMatrix( archive, tmp );
724  (~mat) = tmp;
725 
726  if( !archive ) {
727  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
728  }
729 }
730 //*************************************************************************************************
731 
732 
733 //*************************************************************************************************
745 template< typename Archive // Type of the archive
746  , typename MT // Type of the matrix
747  , bool SO > // Storage order
750 {
751  typedef ElementType_<MT> ET;
752 
753  ET value = ET();
754 
755  const size_t dim1( ( SO == rowMajor )?( rows_ ):( columns_ ) );
756  const size_t dim2( ( SO != rowMajor )?( rows_ ):( columns_ ) );
757 
758  for( size_t i=0UL; i<dim1; ++i ) {
759  (~mat).reserve( i, dim2 );
760  }
761 
762  for( size_t i=0UL; i<rows_; ++i ) {
763  size_t j( 0UL );
764  while( ( j != columns_ ) && ( archive >> value ) ) {
765  (~mat).append( i, j, value, false );
766  ++j;
767  }
768  }
769 
770  if( !archive ) {
771  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
772  }
773 }
774 //*************************************************************************************************
775 
776 
777 //*************************************************************************************************
789 template< typename Archive // Type of the archive
790  , typename MT > // Type of the matrix
793 {
794  if( rows_ == 0UL ) return;
795 
796  for( size_t j=0UL; j<columns_; ++j ) {
797  archive.read( &(~mat)(0,j), rows_ );
798  }
799 
800  if( !archive ) {
801  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be deserialized" );
802  }
803 }
804 //*************************************************************************************************
805 
806 
807 //*************************************************************************************************
819 template< typename Archive // Type of the archive
820  , typename MT // Type of the matrix
821  , bool SO > // Storage order
823 {
824  typedef ElementType_<MT> ET;
825 
826  ET value = ET();
827 
828  for( size_t j=0UL; j<columns_; ++j ) {
829  size_t i( 0UL );
830  while( ( i != rows_ ) && ( archive >> value ) ) {
831  (~mat)(i,j) = value;
832  ++i;
833  }
834  }
835 
836  if( !archive ) {
837  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be deserialized" );
838  }
839 }
840 //*************************************************************************************************
841 
842 
843 //*************************************************************************************************
855 template< typename Archive // Type of the archive
856  , typename MT // Type of the matrix
857  , bool SO > // Storage order
860 {
862  deserializeDenseColumnMatrix( archive, tmp );
863  (~mat) = tmp;
864 
865  if( !archive ) {
866  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
867  }
868 }
869 //*************************************************************************************************
870 
871 
872 //*************************************************************************************************
884 template< typename Archive // Type of the archive
885  , typename MT // Type of the matrix
886  , bool SO > // Storage order
889 {
890  typedef ElementType_<MT> ET;
891 
892  ET value = ET();
893 
894  const size_t dim1( ( SO == rowMajor )?( rows_ ):( columns_ ) );
895  const size_t dim2( ( SO != rowMajor )?( rows_ ):( columns_ ) );
896 
897  for( size_t i=0UL; i<dim1; ++i ) {
898  (~mat).reserve( i, dim2 );
899  }
900 
901  for( size_t j=0UL; j<columns_; ++j ) {
902  size_t i( 0UL );
903  while( ( i != rows_ ) && ( archive >> value ) ) {
904  (~mat).append( i, j, value, false );
905  ++i;
906  }
907  }
908 
909  if( !archive ) {
910  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
911  }
912 }
913 //*************************************************************************************************
914 
915 
916 //*************************************************************************************************
928 template< typename Archive // Type of the archive
929  , typename MT // Type of the matrix
930  , bool SO > // Storage order
932 {
933  typedef ElementType_<MT> ET;
934 
935  uint64_t number( 0UL );
936  size_t index ( 0UL );
937  ET value = ET();
938 
939  for( size_t i=0UL; i<rows_; ++i ) {
940  archive >> number;
941  size_t j( 0UL );
942  while( ( j != number ) && ( archive >> index >> value ) ) {
943  (~mat)(i,index) = value;
944  ++j;
945  }
946  }
947 
948  if( !archive ) {
949  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be deserialized" );
950  }
951 }
952 //*************************************************************************************************
953 
954 
955 //*************************************************************************************************
967 template< typename Archive // Type of the archive
968  , typename MT > // Type of the matrix
970 {
971  typedef ElementType_<MT> ET;
972 
973  uint64_t number( 0UL );
974  size_t index ( 0UL );
975  ET value = ET();
976 
977  for( size_t i=0UL; i<rows_; ++i )
978  {
979  archive >> number;
980 
981  size_t j( 0UL );
982  while( ( j != number ) && ( archive >> index >> value ) ) {
983  (~mat).append( i, index, value, false );
984  ++j;
985  }
986 
987  (~mat).finalize( i );
988  }
989 
990  if( !archive ) {
991  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
992  }
993 }
994 //*************************************************************************************************
995 
996 
997 //*************************************************************************************************
1009 template< typename Archive // Type of the archive
1010  , typename MT > // Type of the matrix
1012 {
1014  deserializeSparseRowMatrix( archive, tmp );
1015  (~mat) = tmp;
1016 
1017  if( !archive ) {
1018  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
1019  }
1020 }
1021 //*************************************************************************************************
1022 
1023 
1024 //*************************************************************************************************
1036 template< typename Archive // Type of the archive
1037  , typename MT // Type of the matrix
1038  , bool SO > // Storage order
1040 {
1041  typedef ElementType_<MT> ET;
1042 
1043  uint64_t number( 0UL );
1044  size_t index ( 0UL );
1045  ET value = ET();
1046 
1047  for( size_t j=0UL; j<columns_; ++j ) {
1048  archive >> number;
1049  size_t i( 0UL );
1050  while( ( i != number ) && ( archive >> index >> value ) ) {
1051  (~mat)(index,j) = value;
1052  ++i;
1053  }
1054  }
1055 
1056  if( !archive ) {
1057  BLAZE_THROW_RUNTIME_ERROR( "Dense matrix could not be deserialized" );
1058  }
1059 }
1060 //*************************************************************************************************
1061 
1062 
1063 //*************************************************************************************************
1075 template< typename Archive // Type of the archive
1076  , typename MT > // Type of the matrix
1078 {
1080  deserializeSparseColumnMatrix( archive, tmp );
1081  (~mat) = tmp;
1082 
1083  if( !archive ) {
1084  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
1085  }
1086 }
1087 //*************************************************************************************************
1088 
1089 
1090 //*************************************************************************************************
1102 template< typename Archive // Type of the archive
1103  , typename MT > // Type of the matrix
1105 {
1106  typedef ElementType_<MT> ET;
1107 
1108  uint64_t number( 0UL );
1109  size_t index ( 0UL );
1110  ET value = ET();
1111 
1112  for( size_t j=0UL; j<columns_; ++j )
1113  {
1114  archive >> number;
1115 
1116  size_t i( 0UL );
1117  while( ( i != number ) && ( archive >> index >> value ) ) {
1118  (~mat).append( index, j, value, false );
1119  ++i;
1120  }
1121 
1122  (~mat).finalize( j );
1123  }
1124 
1125  if( !archive ) {
1126  BLAZE_THROW_RUNTIME_ERROR( "Sparse matrix could not be deserialized" );
1127  }
1128 }
1129 //*************************************************************************************************
1130 
1131 
1132 
1133 
1134 //=================================================================================================
1135 //
1136 // MATRIXVALUEMAPPINGHELPER SPECIALIZATIONS
1137 //
1138 //=================================================================================================
1139 
1140 //*************************************************************************************************
1144 template<>
1145 struct MatrixSerializer::MatrixValueMappingHelper<true,true>
1146 {
1147  enum { value = 1 };
1148 };
1150 //*************************************************************************************************
1151 
1152 
1153 //*************************************************************************************************
1157 template<>
1158 struct MatrixSerializer::MatrixValueMappingHelper<true,false>
1159 {
1160  enum { value = 5 };
1161 };
1163 //*************************************************************************************************
1164 
1165 
1166 //*************************************************************************************************
1170 template<>
1171 struct MatrixSerializer::MatrixValueMappingHelper<false,true>
1172 {
1173  enum { value = 3 };
1174 };
1176 //*************************************************************************************************
1177 
1178 
1179 //*************************************************************************************************
1183 template<>
1184 struct MatrixSerializer::MatrixValueMappingHelper<false,false>
1185 {
1186  enum { value = 7 };
1187 };
1189 //*************************************************************************************************
1190 
1191 
1192 
1193 
1194 //=================================================================================================
1195 //
1196 // GLOBAL FUNCTIONS
1197 //
1198 //=================================================================================================
1199 
1200 //*************************************************************************************************
1265 template< typename Archive // Type of the archive
1266  , typename MT // Type of the matrix
1267  , bool SO > // Storage order
1268 void serialize( Archive& archive, const Matrix<MT,SO>& mat )
1269 {
1270  MatrixSerializer().serialize( archive, ~mat );
1271 }
1272 //*************************************************************************************************
1273 
1274 
1275 //*************************************************************************************************
1287 template< typename Archive // Type of the archive
1288  , typename MT // Type of the matrix
1289  , bool SO > // Storage order
1290 void deserialize( Archive& archive, Matrix<MT,SO>& mat )
1291 {
1292  MatrixSerializer().deserialize( archive, ~mat );
1293 }
1294 //*************************************************************************************************
1295 
1296 } // namespace blaze
1297 
1298 #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:528
Binary archive for the portable serialization of data.The Archive class implements the functionality ...
Definition: Archive.h:141
Header file for basic type definitions.
const bool columnMajor
Storage order flag for column-major matrices.
Definition: StorageOrder.h:99
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:207
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:188
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:223
8-bit unsigned integer type of the Blaze library.
Implementation of a compressed MxN matrix.
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:384
Efficient implementation of a dynamic matrix.The DynamicMatrix class template is the representation ...
Definition: DynamicMatrix.h:203
void serializeHeader(Archive &archive, const MT &mat)
Serializes all meta information about the given matrix.
Definition: MatrixSerializer.h:393
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:109
MatrixSerializer()
The default constructor of the MatrixSerializer class.
Definition: MatrixSerializer.h:340
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
void deserializeSparseColumnMatrix(Archive &archive, DenseMatrix< MT, SO > &mat)
Deserializes a column-major sparse matrix from the archive.
Definition: MatrixSerializer.h:1039
void deserializeMatrix(Archive &archive, MT &mat)
Deserializes a matrix from the archive.
Definition: MatrixSerializer.h:617
Header file for the DisableIf class template.
uint8_t type_
The type of the matrix.
Definition: MatrixSerializer.h:317
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
uint8_t elementType_
The type of an element.
Definition: MatrixSerializer.h:318
Compile time check for row-major matrix types.This type trait tests whether or not the given template...
Definition: IsRowMajorMatrix.h:83
void serializeMatrix(Archive &archive, const DenseMatrix< MT, SO > &mat)
Serializes the elements of a dense matrix.
Definition: MatrixSerializer.h:423
DisableIf_< IsResizable< MT > > prepareMatrix(DenseMatrix< MT, SO > &mat)
Prepares the given non-resizable dense matrix for the deserialization process.
Definition: MatrixSerializer.h:565
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2647
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:1268
Header file for the DenseMatrix base class.
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:330
uint64_t rows_
The number of rows of the matrix.
Definition: MatrixSerializer.h:320
Header file for the exception macros of the math module.
Header file for the implementation of a dynamic MxN matrix.
BLAZE_ALWAYS_INLINE 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:254
Header file for the IsDenseMatrix type trait.
Header file for the EnableIf class template.
64-bit unsigned integer type of the Blaze library.
EnableIfTrue_< MT::simdEnabled > deserializeDenseColumnMatrix(Archive &archive, DenseMatrix< MT, columnMajor > &mat)
Deserializes a column-major dense matrix from the archive.
Definition: MatrixSerializer.h:792
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.
typename EnableIfTrue< Condition, T >::Type EnableIfTrue_
Auxiliary type for the EnableIfTrue class template.The EnableIfTrue_ alias declaration provides a con...
Definition: EnableIf.h:138
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:931
uint64_t columns_
The number of columns of the matrix.
Definition: MatrixSerializer.h:321
void deserialize(Archive &archive, Matrix< MT, SO > &mat)
Deserializes a matrix from the given archive.
Definition: MatrixSerializer.h:505
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:89
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:223
void deserialize(Archive &archive, Matrix< MT, SO > &mat)
Deserializes a matrix from the given archive.
Definition: MatrixSerializer.h:1290
Header file for the TypeValueMapping class template.
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:314
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
uint8_t version_
The version of the archive.
Definition: MatrixSerializer.h:316
EnableIfTrue_< MT::simdEnabled > deserializeDenseRowMatrix(Archive &archive, DenseMatrix< MT, rowMajor > &mat)
Deserializes a row-major dense matrix from the archive.
Definition: MatrixSerializer.h:653
void serialize(Archive &archive, const Matrix< MT, SO > &mat)
Serializes the given matrix and writes it to the archive.
Definition: MatrixSerializer.h:371
uint8_t elementSize_
The size in bytes of a single element of the matrix.
Definition: MatrixSerializer.h:319
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_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
Header file for the IsResizable type trait.
uint64_t number_
The total number of elements contained in the matrix.
Definition: MatrixSerializer.h:322
#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