35 #ifndef _BLAZE_MATH_SERIALIZATION_VECTORSERIALIZER_H_
36 #define _BLAZE_MATH_SERIALIZATION_VECTORSERIALIZER_H_
170 template<
bool IsDenseVector >
171 struct VectorValueMappingHelper;
183 template<
typename T >
184 struct VectorValueMapping
186 enum { value = VectorValueMappingHelper< IsDenseVector<T>::value >::value };
212 template<
typename Archive,
typename VT,
bool TF >
220 template<
typename Archive,
typename VT,
bool TF >
229 template<
typename Archive,
typename VT >
232 template<
typename Archive,
typename VT,
bool TF >
235 template<
typename Archive,
typename VT,
bool TF >
243 template<
typename Archive,
typename VT >
246 template<
typename VT,
bool TF >
249 template<
typename VT,
bool TF >
252 template<
typename VT >
255 template<
typename Archive,
typename VT >
258 template<
typename Archive,
typename VT,
bool TF >
262 template<
typename Archive,
typename VT,
bool TF >
266 template<
typename Archive,
typename VT,
bool TF >
269 template<
typename Archive,
typename VT,
bool TF >
272 template<
typename Archive,
typename VT,
bool TF >
339 throw std::runtime_error(
"Faulty archive detected" );
363 archive << uint8_t ( VectorValueMapping<VT>::value );
364 archive << uint8_t ( TypeValueMapping<ET>::value );
365 archive << uint8_t (
sizeof( ET ) );
367 archive << uint64_t( IsDenseVector<VT>::value ? vec.size() : vec.nonZeros() );
370 throw std::runtime_error(
"File header could not be serialized" );
390 while( ( i < (~vec).size() ) && ( archive << (~vec)[i] ) ) {
395 throw std::runtime_error(
"Dense vector could not be serialized" );
416 ConstIterator element( (~vec).begin() );
417 while( ( element != (~vec).end() ) &&
418 ( archive << element->index() << element->value() ) ) {
423 throw std::runtime_error(
"Sparse vector could not be serialized" );
451 throw std::invalid_argument(
"Faulty archive detected" );
481 throw std::runtime_error(
"Corrupt archive detected" );
484 throw std::runtime_error(
"Invalid version detected" );
486 else if( (
type_ & 1U ) != 0U || (
type_ & (~3U) ) != 0U ) {
487 throw std::runtime_error(
"Invalid vector type detected" );
490 throw std::runtime_error(
"Invalid element type detected" );
493 throw std::runtime_error(
"Invalid element size detected" );
496 throw std::runtime_error(
"Invalid vector size detected" );
499 throw std::runtime_error(
"Invalid number of elements detected" );
511 template<
typename VT
526 template<
typename VT
542 template<
typename VT >
545 vec.resize (
size_,
false );
570 else if(
type_ == 2U ) {
603 while( ( i !=
size_ ) && ( archive >> value ) ) {
609 throw std::runtime_error(
"Dense vector could not be deserialized" );
633 if(
size_ == 0UL )
return;
634 archive.read( &(~vec)[0],
size_ );
637 throw std::runtime_error(
"Dense vector could not be deserialized" );
665 while( ( i !=
size_ ) && ( archive >> value ) ) {
671 throw std::runtime_error(
"Sparse vector could not be deserialized" );
700 while( ( i !=
number_ ) && ( archive >> index >> value ) ) {
701 (~vec)[index] = value;
706 throw std::runtime_error(
"Dense vector could not be deserialized" );
735 while( ( i !=
number_ ) && ( archive >> index >> value ) ) {
736 (~vec).append( index, value,
false );
741 throw std::runtime_error(
"Sparse vector could not be deserialized" );
760 struct VectorSerializer::VectorValueMappingHelper<true>
773 struct VectorSerializer::VectorValueMappingHelper<false>
853 template<
typename Archive
875 template<
typename Archive
void serialize(Archive &archive, const Vector< VT, TF > &vec)
Serializes the given vector and writes it to the archive.
Definition: VectorSerializer.h:336
DisableIf< IsResizable< VT > >::Type prepareVector(DenseVector< VT, TF > &vec)
Prepares the given non-resizable dense vector for the deserialization process.
Definition: VectorSerializer.h:513
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4599
uint64_t size_
The size of the vector.
Definition: VectorSerializer.h:284
Binary archive for the portable serialization of data.The Archive class implements the functionality ...
Definition: Archive.h:141
Header file for the SparseVector base class.
Serializer for dense and sparse vectors.The VectorSerializer implements the necessary logic to serial...
Definition: VectorSerializer.h:153
DisableIfTrue< VT::vectorizable >::Type deserializeDenseVector(Archive &archive, DenseVector< VT, TF > &vec)
Deserializes a dense vector from the archive.
Definition: VectorSerializer.h:596
T Type
The instantiated type.
Definition: EnableIf.h:99
8-bit unsigned integer type of the Blaze library.
Header file for the DenseVector base class.
void deserializeVector(Archive &archive, VT &vec)
Deserializes a vector from the archive.
Definition: VectorSerializer.h:565
void deserializeHeader(Archive &archive, const VT &vec)
Deserializes all meta information about the given vector.
Definition: VectorSerializer.h:476
void serializeVector(Archive &archive, const DenseVector< VT, TF > &vec)
Serializes the elements of a dense vector.
Definition: VectorSerializer.h:387
uint8_t version_
The version of the archive.
Definition: VectorSerializer.h:280
Header file for the DisableIf class template.
void serializeHeader(Archive &archive, const VT &vec)
Serializes all meta information about the given vector.
Definition: VectorSerializer.h:358
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2412
void serialize(Archive &archive, const Matrix< MT, SO > &mat)
Serializes the given matrix and writes it to the archive.
Definition: MatrixSerializer.h:1265
uint8_t elementSize_
The size in bytes of a single element of the vector.
Definition: VectorSerializer.h:283
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2406
Header file for the EnableIf class template.
64-bit unsigned integer type of the Blaze library.
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
void deserialize(Archive &archive, Vector< VT, TF > &vec)
Deserializes a vector from the given archive.
Definition: VectorSerializer.h:448
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a N-dimensional vector type...
Definition: Vector.h:79
Header file for run time assertion macros.
VectorSerializer()
The default constructor of the VectorSerializer class.
Definition: VectorSerializer.h:303
Conversion from a data type to a serial representation.This class template converts the given data ty...
Definition: TypeValueMapping.h:163
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
uint64_t number_
The total number of elements contained in the vector.
Definition: VectorSerializer.h:285
uint8_t type_
The type of the vector.
Definition: VectorSerializer.h:281
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
Header file for the IsDenseVector type trait.
void deserialize(Archive &archive, Matrix< MT, SO > &mat)
Deserializes a matrix from the given archive.
Definition: MatrixSerializer.h:1287
void deserializeSparseVector(Archive &archive, DenseVector< VT, TF > &vec)
Deserializes a sparse vector from the archive.
Definition: VectorSerializer.h:692
Header file for the TypeValueMapping class template.
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
Header file for basic type definitions.
Constraint on the data type.
T Type
The instantiated type.
Definition: DisableIf.h:99
Header file for the IsResizable type trait.
Header file for the Vector CRTP base class.
#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
uint8_t elementType_
The type of an element.
Definition: VectorSerializer.h:282