FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
FEAT::Pack Namespace Reference

Data Array Pack namespace. More...

Classes

struct  SwapHelper
 auxiliary helper class: swaps the bytes of an 8/16/32/64/128 byte type More...
 
struct  SwapHelper< 1 >
 
struct  SwapHelper< 16 >
 
struct  SwapHelper< 2 >
 
struct  SwapHelper< 4 >
 
struct  SwapHelper< 8 >
 
struct  TypeHelper
 
struct  TypeHelper< FEAT::Type::FloatingClass, true >
 
struct  TypeHelper< FEAT::Type::IntegralClass, false >
 
struct  TypeHelper< FEAT::Type::IntegralClass, true >
 

Typedefs

using f16 = Half
 16-bit floating point type More...
 
using f32 = float
 32-bit floating point type More...
 
using f64 = double
 64-bit floating point type More...
 
using i16 = std::int16_t
 16-bit signed integer type More...
 
using i32 = std::int32_t
 32-bit signed integer type More...
 
using i64 = std::int64_t
 64-bit signed integer type More...
 
using i8 = std::int8_t
 8-bit signed integer type More...
 
using u16 = std::uint16_t
 16-bit unsigned integer type More...
 
using u32 = std::uint32_t
 32-bit unsigned integer type More...
 
using u64 = std::uint64_t
 64-bit unsigned integer type More...
 
using u8 = std::uint8_t
 8-bit unsigned integer type More...
 

Enumerations

enum class  Type : u16 {
  None = 0x0000 , Mask_T = 0x0FFF , Mask_Z = 0x8000 , Mask_P = 0x2000 ,
  Type_I = 0x0010 , Type_U = 0x0020 , Type_F = 0x0030 , I8 = 0x0011 ,
  I16 = 0x0012 , I32 = 0x0013 , I64 = 0x0014 , U8 = 0x0021 ,
  U16 = 0x0022 , U32 = 0x0023 , U64 = 0x0024 , F16 = 0x0032 ,
  F32 = 0x0033 , F64 = 0x0034 , F128 = 0x0035 , ZI8 = 0x8011 ,
  ZI16 = 0x8012 , ZI32 = 0x8013 , ZI64 = 0x8014 , ZU8 = 0x8021 ,
  ZU16 = 0x8022 , ZU32 = 0x8023 , ZU64 = 0x8024 , ZF16 = 0x8032 ,
  ZF32 = 0x8033 , ZF64 = 0x8034 , ZF128 = 0x8035 , PF32 = 0x2033 ,
  PF64 = 0x2034
}
 bitmask for zfp header More...
 

Functions

template<typename T_ >
std::size_t decode (T_ *dst, void *buf, std::size_t count, std::size_t buf_size, Pack::Type pack_type, bool swap_bytes)
 Decodes an array from a packed buffer. More...
 
template std::size_t decode< f32 > (f32 *, void *, std::size_t, std::size_t, Pack::Type, bool)
 
template std::size_t decode< f64 > (f64 *, void *, std::size_t, std::size_t, Pack::Type, bool)
 
template std::size_t decode< i16 > (i16 *, void *, std::size_t, std::size_t, Pack::Type, bool)
 
template std::size_t decode< i32 > (i32 *, void *, std::size_t, std::size_t, Pack::Type, bool)
 
template std::size_t decode< i64 > (i64 *, void *, std::size_t, std::size_t, Pack::Type, bool)
 
template std::size_t decode< i8 > (i8 *, void *, std::size_t, std::size_t, Pack::Type, bool)
 
template std::size_t decode< long long > (long long *, void *, std::size_t, std::size_t, Pack::Type, bool)
 
template std::size_t decode< u16 > (u16 *, void *, std::size_t, std::size_t, Pack::Type, bool)
 
template std::size_t decode< u32 > (u32 *, void *, std::size_t, std::size_t, Pack::Type, bool)
 
template std::size_t decode< u64 > (u64 *, void *, std::size_t, std::size_t, Pack::Type, bool)
 
template std::size_t decode< u8 > (u8 *, void *, std::size_t, std::size_t, Pack::Type, bool)
 
template<typename T_ >
static std::size_t decode_raw (T_ *dst, const void *buf, const std::size_t count, const Pack::Type pack_type, bool swap_bytes)
 Decodes an array from a packed buffer without compression support. More...
 
template<typename T_ >
Pack::Type deduct_type ()
 Deduct the (raw) Pack::Type from a given data type T_. More...
 
template Pack::Type deduct_type< f32 > ()
 
template Pack::Type deduct_type< f64 > ()
 
template Pack::Type deduct_type< i16 > ()
 
template Pack::Type deduct_type< i32 > ()
 
template Pack::Type deduct_type< i64 > ()
 
template Pack::Type deduct_type< i8 > ()
 
template Pack::Type deduct_type< u16 > ()
 
template Pack::Type deduct_type< u32 > ()
 
template Pack::Type deduct_type< u64 > ()
 
template Pack::Type deduct_type< u8 > ()
 
std::size_t element_size (const Pack::Type type)
 Returns the size of a Pack::Type element in bytes. More...
 
template<typename T_ >
std::size_t encode (void *buf, const T_ *src, std::size_t buf_size, std::size_t count, Pack::Type pack_type, bool swap_bytes, double tolerance=1e-16)
 Encodes an array into a packed buffer. More...
 
template std::size_t encode< f32 > (void *, const f32 *, std::size_t, std::size_t, Pack::Type, bool, double)
 
template std::size_t encode< f64 > (void *, const f64 *, std::size_t, std::size_t, Pack::Type, bool, double)
 
template std::size_t encode< i16 > (void *, const i16 *, std::size_t, std::size_t, Pack::Type, bool, double)
 
template std::size_t encode< i32 > (void *, const i32 *, std::size_t, std::size_t, Pack::Type, bool, double)
 
template std::size_t encode< i64 > (void *, const i64 *, std::size_t, std::size_t, Pack::Type, bool, double)
 
template std::size_t encode< i8 > (void *, const i8 *, std::size_t, std::size_t, Pack::Type, bool, double)
 
template std::size_t encode< long long > (void *, const long long *, std::size_t, std::size_t, Pack::Type, bool, double)
 
template std::size_t encode< u16 > (void *, const u16 *, std::size_t, std::size_t, Pack::Type, bool, double)
 
template std::size_t encode< u32 > (void *, const u32 *, std::size_t, std::size_t, Pack::Type, bool, double)
 
template std::size_t encode< u64 > (void *, const u64 *, std::size_t, std::size_t, Pack::Type, bool, double)
 
template std::size_t encode< u8 > (void *, const u8 *, std::size_t, std::size_t, Pack::Type, bool, double)
 
template<typename T_ >
static std::size_t encode_raw (void *buf, const T_ *src, const std::size_t count, const Pack::Type pack_type, bool swap_bytes)
 Encodes an array into a packed buffer without compression support. More...
 
std::size_t estimate_size (std::size_t count, Pack::Type type, double tolerance=1e-16)
 Computes the estimated (upper bound) pack buffer size for an array. More...
 
template<typename T_ >
static std::size_t lossless_decode (T_ *dst, const void *buf, const std::size_t count, const std::size_t buf_size, const Pack::Type pack_type, bool swap_bytes)
 Decodes an array from a packed buffer. More...
 
template<typename T_ >
static std::size_t lossless_encode (void *buf, const T_ *src, const std::size_t buf_size, const std::size_t count, const Pack::Type pack_type, bool swap_bytes)
 Encodes an array into a packed buffer. More...
 
template<typename T_ >
static std::size_t lossy_decode (T_ *dst, void *buf, const std::size_t count, const std::size_t buf_size, const Pack::Type pack_type, bool swap_bytes)
 Decodes an array from a packed buffer with lossy saved compression data. More...
 
template<typename T_ >
static std::size_t lossy_encode (void *buf, T_ *src, const std::size_t buf_size, const std::size_t count, const Pack::Type pack_type, bool swap_bytes, const double tolerance)
 Encodes an array into a packed buffer. More...
 
static std::size_t lossy_estimate_size (const std::size_t count, const Pack::Type type, const double tolerance)
 Computes the estimated (upper bound) pack buffer size for an array for lossy compression. More...
 
Pack::Type operator& (Pack::Type a, Pack::Type b)
 bit-wise AND operator for Pack::Type More...
 
std::ostream & operator<< (std::ostream &os, Pack::Type t)
 stream output operator for Pack::Type More...
 
std::istream & operator>> (std::istream &is, Pack::Type &t)
 stream input operator for Pack::Type More...
 
Pack::Type operator| (Pack::Type a, Pack::Type b)
 bit-wise OR operator for Pack::Type More...
 
template<typename X_ , typename T_ >
static std::size_t xdecode (T_ *dest, const void *buf, const std::size_t count, bool swap_bytes)
 Encodes an array by converting each of its elements to a desired type. More...
 
template<typename X_ , typename T_ >
static std::size_t xencode (void *buf, const T_ *src, const std::size_t count, bool swap_bytes)
 Encodes an array by converting each of its elements to a desired type. More...
 
template<typename X_ >
X_ xswap (X_ x)
 Swaps the bytes of an object. More...
 

Detailed Description

Data Array Pack namespace.

This namespace encapsulates various functions than provide means of packing and unpacking data arrays as well as compression and decompression of buffers using the third-party library zlib or lossy compression and decompression of buffers using the third-party library zfp.

Typedef Documentation

◆ f16

using FEAT::Pack::f16 = typedef Half

16-bit floating point type

Definition at line 47 of file pack.hpp.

◆ f32

using FEAT::Pack::f32 = typedef float

32-bit floating point type

Definition at line 54 of file pack.hpp.

◆ f64

using FEAT::Pack::f64 = typedef double

64-bit floating point type

Definition at line 56 of file pack.hpp.

◆ i16

using FEAT::Pack::i16 = typedef std::int16_t

16-bit signed integer type

Definition at line 29 of file pack.hpp.

◆ i32

using FEAT::Pack::i32 = typedef std::int32_t

32-bit signed integer type

Definition at line 31 of file pack.hpp.

◆ i64

using FEAT::Pack::i64 = typedef std::int64_t

64-bit signed integer type

Definition at line 33 of file pack.hpp.

◆ i8

using FEAT::Pack::i8 = typedef std::int8_t

8-bit signed integer type

Definition at line 27 of file pack.hpp.

◆ u16

using FEAT::Pack::u16 = typedef std::uint16_t

16-bit unsigned integer type

Definition at line 38 of file pack.hpp.

◆ u32

using FEAT::Pack::u32 = typedef std::uint32_t

32-bit unsigned integer type

Definition at line 40 of file pack.hpp.

◆ u64

using FEAT::Pack::u64 = typedef std::uint64_t

64-bit unsigned integer type

Definition at line 42 of file pack.hpp.

◆ u8

using FEAT::Pack::u8 = typedef std::uint8_t

8-bit unsigned integer type

Definition at line 36 of file pack.hpp.

Enumeration Type Documentation

◆ Type

enum class FEAT::Pack::Type : u16
strong

bitmask for zfp header

//0x1u HEADER_MAGIC -> for version control--> only checks codec... in last 8 bits of first 32 bits... //0x2u HEADER_META //0x4u HEADER_MODE

Type enumeration

Definition at line 80 of file pack.hpp.

Function Documentation

◆ decode()

template<typename T_ >
std::size_t FEAT::Pack::decode ( T_ *  dst,
void *  buf,
std::size_t  count,
std::size_t  buf_size,
Pack::Type  pack_type,
bool  swap_bytes 
)

Decodes an array from a packed buffer.

Instantiated for i{8,16,32,64}, u{8,16,32,64}, f{16,32,64,128}.

Parameters
[out]dstA pointer to the output array that is to be unpacked. Must not be nullptr.
[in]bufA pointer to the input buffer. Must not be nullptr.
[in]countThe number of output array elements.
[in]buf_sizeThe size of the input buffer buf in bytes.
[in]pack_typeThe input buffer pack type.
[in]swap_bytesSpecifies whether to swap the pack type bytes.
Returns
The total number of bytes consumed from the input buffer.

Definition at line 680 of file pack.cpp.

References decode_raw(), lossless_decode(), lossy_decode(), and XASSERT.

Referenced by FEAT::LAFEM::Container< DT_, IT_ >::_deserialize().

◆ decode_raw()

template<typename T_ >
static std::size_t FEAT::Pack::decode_raw ( T_ *  dst,
const void *  buf,
const std::size_t  count,
const Pack::Type  pack_type,
bool  swap_bytes 
)
static

Decodes an array from a packed buffer without compression support.

Attention
This function does not decode compressed pack types.
Parameters
[out]dstA pointer to the output array that is to be unpacked. Must not be nullptr.
[in]bufA pointer to the input buffer. Must not be nullptr.
[in]countThe number of output array elements.
[in]pack_typeThe input buffer pack type.
[in]swap_bytesSpecifies whether to swap the pack type bytes.
Returns
The total number of bytes consumed from the input buffer.

Definition at line 443 of file pack.cpp.

References XASSERT, and XASSERTM.

Referenced by decode(), lossless_decode(), and lossy_decode().

◆ deduct_type()

template<typename T_ >
Pack::Type FEAT::Pack::deduct_type ( )

Deduct the (raw) Pack::Type from a given data type T_.

Instantiated for i{8,16,32,64}, u{8,16,32,64}, f{16,32,64,128}.

Template Parameters
T_The type whose Pack::Type value is to be determined.
Returns
The (raw) Pack::Type value for the given type T_ or Pack::Type::None, if T_ does not represent a type from the Pack::Type enum.

Definition at line 362 of file pack.cpp.

◆ element_size()

std::size_t FEAT::Pack::element_size ( const Pack::Type  type)
inline

Returns the size of a Pack::Type element in bytes.

Parameters
[in]typeThe type whose element size is to be determined
Returns
The size of the type in bytes or 0, if type is not a valid data type

Definition at line 267 of file pack.hpp.

Referenced by estimate_size(), lossless_decode(), lossless_encode(), lossy_decode(), and lossy_encode().

◆ encode()

template<typename T_ >
std::size_t FEAT::Pack::encode ( void *  buf,
const T_ *  src,
std::size_t  buf_size,
std::size_t  count,
Pack::Type  pack_type,
bool  swap_bytes,
double  tolerance = 1e-16 
)

Encodes an array into a packed buffer.

Instantiated for i{8,16,32,64}, u{8,16,32,64}, f{16,32,64,128}.

Parameters
[out]bufA pointer to the output buffer. Must not be nullptr.
[in]srcA pointer to the input array that is to be packed. Must not be nullptr.
[in]buf_sizeThe size of the output buffer buf in bytes. Must be at least as big as the estimated buffer size.
[in]countThe number of input array elements.
[in]pack_typeThe desired output buffer pack type.
[in]swap_bytesSpecifies whether to swap the pack type bytes.
[in]toleranceOptional paramter: The desired maximum error for lossy compression.
Returns
The total number of bytes written into the output buffer.

Definition at line 566 of file pack.cpp.

References encode_raw(), lossless_encode(), lossy_encode(), and XASSERT.

◆ encode_raw()

template<typename T_ >
static std::size_t FEAT::Pack::encode_raw ( void *  buf,
const T_ *  src,
const std::size_t  count,
const Pack::Type  pack_type,
bool  swap_bytes 
)
static

Encodes an array into a packed buffer without compression support.

Attention
This function does not encode compressed pack types.
Parameters
[out]bufA pointer to the output buffer. Must not be nullptr.
[in]srcA pointer to the input array that is to be packed. Must not be nullptr.
[in]countThe number of input array elements.
[in]pack_typeThe desired output buffer pack type.
[in]swap_bytesSpecifies whether to swap the pack type bytes.
Returns
The total number of bytes written into the output buffer.

Definition at line 394 of file pack.cpp.

References XASSERT, and XASSERTM.

Referenced by encode(), lossless_encode(), and lossy_encode().

◆ estimate_size()

std::size_t FEAT::Pack::estimate_size ( std::size_t  count,
Pack::Type  type,
double  tolerance = 1e-16 
)

Computes the estimated (upper bound) pack buffer size for an array.

Parameters
[in]countThe number of array elements to be packed.
[in]typeThe packed type of the array elements.
Returns
An estimated (upper bound) array buffer size.

Definition at line 543 of file pack.cpp.

References element_size(), lossy_estimate_size(), and XASSERTM.

Referenced by FEAT::LAFEM::Container< DT_, IT_ >::_serialize(), and FEAT::LAFEM::Container< DT_, IT_ >::_serialized_size().

◆ lossless_decode()

template<typename T_ >
static std::size_t FEAT::Pack::lossless_decode ( T_ *  dst,
const void *  buf,
const std::size_t  count,
const std::size_t  buf_size,
const Pack::Type  pack_type,
bool  swap_bytes 
)
static

Decodes an array from a packed buffer.

Parameters
[out]dstA pointer to the output array that is to be unpacked. Must not be nullptr.
[in]bufA pointer to the input buffer. Must not be nullptr.
[in]countThe number of output array elements.
[in]buf_sizeThe size of the input buffer buf in bytes.
[in]pack_typeThe input buffer pack type.
[in]swap_bytesSpecifies whether to swap the pack type bytes.
Returns
The total number of bytes consumed from the input buffer.

Definition at line 745 of file pack.cpp.

References decode_raw(), element_size(), and XABORTM.

Referenced by decode().

◆ lossless_encode()

template<typename T_ >
static std::size_t FEAT::Pack::lossless_encode ( void *  buf,
const T_ *  src,
const std::size_t  buf_size,
const std::size_t  count,
const Pack::Type  pack_type,
bool  swap_bytes 
)
static

Encodes an array into a packed buffer.

Parameters
[out]bufA pointer to the output buffer. Must not be nullptr.
[in]srcA pointer to the input array that is to be packed. Must not be nullptr.
[in]buf_sizeThe size of the output buffer buf in bytes. Must be at least as big as the estimated buffer size.
[in]countThe number of input array elements.
[in]pack_typeThe desired output buffer pack type.
[in]swap_bytesSpecifies whether to swap the pack type bytes.
Returns
The total number of bytes written into the output buffer.

Definition at line 633 of file pack.cpp.

References element_size(), encode_raw(), and XABORTM.

Referenced by encode().

◆ lossy_decode()

template<typename T_ >
static std::size_t FEAT::Pack::lossy_decode ( T_ *  dst,
void *  buf,
const std::size_t  count,
const std::size_t  buf_size,
const Pack::Type  pack_type,
bool  swap_bytes 
)
static

Decodes an array from a packed buffer with lossy saved compression data.

Parameters
[out]dstA pointer to the output array that is to be unpacked. Must not be nullptr.
[in]bufA pointer to the input buffer. Must not be nullptr.
[in]countThe number of output array elements.
[in]buf_sizeThe size of the input buffer buf in bytes.
[in]pack_typeThe input buffer pack type.
[in]swap_bytesSpecifies whether to swap the pack type bytes.
Returns
The total number of bytes consumed from the input buffer.

Definition at line 937 of file pack.cpp.

References decode_raw(), element_size(), FEAT::stringify(), XABORTM, XASSERT, and XASSERTM.

Referenced by decode().

◆ lossy_encode()

template<typename T_ >
static std::size_t FEAT::Pack::lossy_encode ( void *  buf,
T_ *  src,
const std::size_t  buf_size,
const std::size_t  count,
const Pack::Type  pack_type,
bool  swap_bytes,
const double  tolerance 
)
static

Encodes an array into a packed buffer.

Parameters
[out]bufA pointer to the output buffer. Must not be nullptr.
[in]srcA pointer to the input array that is to be packed. Must not be nullptr.
[in]buf_sizeThe size of the output buffer buf in bytes. Must be at least as big as the estimated buffer size.
[in]countThe number of input array elements.
[in]pack_typeThe desired output buffer pack type.
[in]swap_bytesSpecifies whether to swap the pack type bytes.
[in]toleranceThe desired maximum error of compressed data.
Warning
Tolerance can be exceeded in fringe cases. If data set is highly uncontinuous, error testing is recommended.
Returns
The total number of bytes written into the output buffer.

Definition at line 825 of file pack.cpp.

References element_size(), encode_raw(), XABORTM, and XASSERT.

Referenced by encode().

◆ lossy_estimate_size()

static std::size_t FEAT::Pack::lossy_estimate_size ( const std::size_t  count,
const Pack::Type  type,
const double  tolerance 
)
static

Computes the estimated (upper bound) pack buffer size for an array for lossy compression.

Warning
Lossless estimation and lossy estimation of buffer size are different!
Parameters
[in]srcA pointer to the input array that is to be packed. Must not be nullptr.
[in]countThe number of input array elements.
[in]toleranceThe desired maximum error of compressed data.
Returns
An estimated (upper bound) array buffer size.

Definition at line 486 of file pack.cpp.

References XABORTM, and XASSERT.

Referenced by estimate_size().

◆ operator&()

Pack::Type FEAT::Pack::operator& ( Pack::Type  a,
Pack::Type  b 
)
inline

bit-wise AND operator for Pack::Type

Definition at line 140 of file pack.hpp.

◆ operator<<()

std::ostream & FEAT::Pack::operator<< ( std::ostream &  os,
Pack::Type  t 
)
inline

stream output operator for Pack::Type

Definition at line 152 of file pack.hpp.

◆ operator>>()

std::istream & FEAT::Pack::operator>> ( std::istream &  is,
Pack::Type t 
)
inline

stream input operator for Pack::Type

Definition at line 189 of file pack.hpp.

References FEAT::String::compare_no_case().

◆ operator|()

Pack::Type FEAT::Pack::operator| ( Pack::Type  a,
Pack::Type  b 
)
inline

bit-wise OR operator for Pack::Type

Definition at line 146 of file pack.hpp.

◆ xdecode()

template<typename X_ , typename T_ >
static std::size_t FEAT::Pack::xdecode ( T_ *  dest,
const void *  buf,
const std::size_t  count,
bool  swap_bytes 
)
static

Encodes an array by converting each of its elements to a desired type.

Effectively, this function performs dest[i] = T_(((X_*)buf)[i]) for all i < count.

Template Parameters
X_The type of the encoded source array buffer buf whose elements are to be converted
T_The type of the destination array dest
Parameters
[out]destThe destination array that receives the converted array elements
[in]bufThe source buffer whose elements of type X_ are to be converted. This buffer is assumed to be at least sizeof(X_)*count bytes in size.
[in]countThe number of elements in the destination array dest.
[in]swap_bytesSpecifies whether the bytes in the source buffer buf are to be swapped before conversion.
Returns
The number bytes read from the source buffer, i.e. sizeof(X_)*count.

Definition at line 184 of file pack.cpp.

References xswap().

◆ xencode()

template<typename X_ , typename T_ >
static std::size_t FEAT::Pack::xencode ( void *  buf,
const T_ *  src,
const std::size_t  count,
bool  swap_bytes 
)
static

Encodes an array by converting each of its elements to a desired type.

Effectively, this function performs ((X_*)buf)[i] = X_(src[i]) for all i < count.

Template Parameters
X_The desired type of the encoded destination array buffer buf
T_The type of the source array src whose elements are to be converted.
Parameters
[out]bufThe destination buffer that receives the array elements of type X_. This buffer is assumed to be at least sizeof(X_)*count bytes in size.
[in]srcThe source array whose elements of type T_ are to be converted
[in]countThe number of elements in the source array src.
[in]swap_bytesSpecifies whether the bytes in the destination buffer buf are to be swapped after conversion.
Returns
The number bytes written to the destination buffer, i.e. sizeof(X_)*count.

Definition at line 133 of file pack.cpp.

References xswap().

◆ xswap()

template<typename X_ >
X_ FEAT::Pack::xswap ( X_  x)
inline

Swaps the bytes of an object.

Definition at line 96 of file pack.cpp.

Referenced by xdecode(), and xencode().