22 #ifndef _BLAZE_MATH_SERIALIZATION_MATRIXSERIALIZER_H_
23 #define _BLAZE_MATH_SERIALIZATION_MATRIXSERIALIZER_H_
162 template<
bool IsDenseMatrix,
bool IsRowMajorMatrix >
163 struct MatrixValueMappingHelper;
175 template<
typename T >
176 struct MatrixValueMapping
204 template<
typename Archive,
typename MT,
bool SO >
212 template<
typename Archive,
typename MT,
bool SO >
221 template<
typename Archive,
typename MT >
224 template<
typename Archive,
typename MT,
bool SO >
227 template<
typename Archive,
typename MT,
bool SO >
235 template<
typename Archive,
typename MT >
238 template<
typename MT >
241 template<
typename MT >
244 template<
typename Archive,
typename MT >
247 template<
typename Archive,
typename MT >
251 template<
typename Archive,
typename MT,
bool SO >
254 template<
typename Archive,
typename MT,
bool SO >
258 template<
typename Archive,
typename MT,
bool SO >
262 template<
typename Archive,
typename MT >
266 template<
typename Archive,
typename MT,
bool SO >
269 template<
typename Archive,
typename MT,
bool SO >
273 template<
typename Archive,
typename MT,
bool SO >
277 template<
typename Archive,
typename MT,
bool SO >
280 template<
typename Archive,
typename MT >
283 template<
typename Archive,
typename MT >
286 template<
typename Archive,
typename MT,
bool SO >
289 template<
typename Archive,
typename MT >
292 template<
typename Archive,
typename MT >
358 throw std::runtime_error(
"Faulty archive detected" );
379 typedef typename MT::ElementType ET;
382 archive << uint8_t ( MatrixValueMapping<MT>::value );
383 archive << uint8_t ( TypeValueMapping<ET>::value );
384 archive << uint8_t (
sizeof( ET ) );
386 archive <<
uint64_t( mat.columns() );
387 archive << uint64_t( ( IsDenseMatrix<MT>::value ) ? ( mat.rows()*mat.columns() ) : ( mat.nonZeros() ) );
390 throw std::runtime_error(
"File header could not be serialized" );
410 for(
size_t i=0UL; i<(~mat).
rows(); ++i ) {
411 for(
size_t j=0UL; j<(~mat).
columns(); ++j ) {
412 archive << (~mat)(i,j);
417 for(
size_t j=0UL; j<(~mat).
columns(); ++j ) {
418 for(
size_t i=0UL; i<(~mat).
rows(); ++i ) {
419 archive << (~mat)(i,j);
425 throw std::runtime_error(
"Dense matrix could not be serialized" );
444 typedef typename MT::ConstIterator ConstIterator;
447 for(
size_t i=0UL; i<(~mat).
rows(); ++i ) {
448 archive <<
uint64_t( (~mat).nonZeros( i ) );
449 for( ConstIterator element=(~mat).begin(i); element!=(~mat).end(i); ++element ) {
450 archive << element->index() << element->value();
455 for(
size_t j=0UL; j<(~mat).
columns(); ++j ) {
456 archive <<
uint64_t( (~mat).nonZeros( j ) );
457 for( ConstIterator element=(~mat).begin(j); element!=(~mat).end(j); ++element ) {
458 archive << element->index() << element->value();
464 throw std::runtime_error(
"Sparse matrix could not be serialized" );
494 throw std::invalid_argument(
"Faulty archive detected" );
516 typedef typename MT::ElementType ET;
519 throw std::runtime_error(
"Corrupt archive detected" );
522 throw std::runtime_error(
"Invalid version detected" );
524 else if( (
type_ & 1U ) != 1U || (
type_ & (~7U) ) != 0U ) {
525 throw std::runtime_error(
"Invalid matrix type detected" );
528 throw std::runtime_error(
"Invalid element type detected" );
531 throw std::runtime_error(
"Invalid element size detected" );
534 throw std::runtime_error(
"Invalid matrix size detected" );
537 throw std::runtime_error(
"Invalid number of elements detected" );
549 template<
typename MT >
563 template<
typename MT >
591 else if(
type_ == 5UL ) {
594 else if(
type_ == 3UL ) {
597 else if(
type_ == 7UL ) {
626 for(
size_t i=0UL; i<
rows_; ++i ) {
627 archive.read( &(~mat)(i,0),
columns_ );
631 throw std::runtime_error(
"Dense matrix could not be deserialized" );
654 typedef typename MT::ElementType ET;
658 for(
size_t i=0UL; i<
rows_; ++i ) {
660 while( ( j !=
columns_ ) && ( archive >> value ) ) {
667 throw std::runtime_error(
"Dense matrix could not be deserialized" );
696 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
720 typedef typename MT::ElementType ET;
727 for(
size_t i=0UL; i<dim1; ++i ) {
728 (~mat).reserve( i, dim2 );
731 for(
size_t i=0UL; i<
rows_; ++i ) {
733 while( ( j !=
columns_ ) && ( archive >> value ) ) {
734 (~mat).append( i, j, value,
false );
740 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
763 if(
rows_ == 0UL )
return;
765 for(
size_t j=0UL; j<
columns_; ++j ) {
766 archive.read( &(~mat)(0,j),
rows_ );
770 throw std::runtime_error(
"Dense matrix could not be deserialized" );
793 typedef typename MT::ElementType ET;
797 for(
size_t j=0UL; j<
columns_; ++j ) {
799 while( ( i !=
rows_ ) && ( archive >> value ) ) {
806 throw std::runtime_error(
"Dense matrix could not be deserialized" );
835 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
859 typedef typename MT::ElementType ET;
866 for(
size_t i=0UL; i<dim1; ++i ) {
867 (~mat).reserve( i, dim2 );
870 for(
size_t j=0UL; j<
columns_; ++j ) {
872 while( ( i !=
rows_ ) && ( archive >> value ) ) {
873 (~mat).append( i, j, value,
false );
879 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
902 typedef typename MT::ElementType ET;
905 size_t index ( 0UL );
908 for(
size_t i=0UL; i<
rows_; ++i ) {
911 while( ( j != number ) && ( archive >> index >> value ) ) {
912 (~mat)(i,index) = value;
918 throw std::runtime_error(
"Dense matrix could not be deserialized" );
940 typedef typename MT::ElementType ET;
943 size_t index ( 0UL );
946 for(
size_t i=0UL; i<
rows_; ++i )
949 (~mat).reserve( i, number );
952 while( ( j != number ) && ( archive >> index >> value ) ) {
953 (~mat).append( i, index, value,
false );
959 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
986 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
1009 typedef typename MT::ElementType ET;
1012 size_t index ( 0UL );
1015 for(
size_t j=0UL; j<
columns_; ++j ) {
1018 while( ( i != number ) && ( archive >> index >> value ) ) {
1019 (~mat)(index,j) = value;
1025 throw std::runtime_error(
"Dense matrix could not be deserialized" );
1052 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
1074 typedef typename MT::ElementType ET;
1077 size_t index ( 0UL );
1080 for(
size_t j=0UL; j<
columns_; ++j )
1083 (~mat).reserve( j, number );
1086 while( ( i != number ) && ( archive >> index >> value ) ) {
1087 (~mat).append( index, j, value,
false );
1093 throw std::runtime_error(
"Sparse matrix could not be deserialized" );
1112 struct MatrixSerializer::MatrixValueMappingHelper<true,true>
1125 struct MatrixSerializer::MatrixValueMappingHelper<true,false>
1138 struct MatrixSerializer::MatrixValueMappingHelper<false,true>
1151 struct MatrixSerializer::MatrixValueMappingHelper<false,false>
1232 template<
typename Archive
1254 template<
typename Archive