16#define BOOST_TEST_MODULE Utility test
17#define BOOST_TEST_MAIN
18#define BOOST_TEST_DYN_LINK
28#include <boost/test/unit_test.hpp>
29#include <boost/mp11.hpp>
42template <
typename source_T>
46 std::vector<source_T>
result(nelems, 0);
48 std::uniform_int_distribution<source_T> dist(
min,
max);
49 std::generate(
result.begin(),
result.end(), [&dist, &mt]() { return dist(mt); });
53using buffer_types = boost::mp11::mp_list<int8_t, int16_t, int32_t, int64_t>;
55using source_types = boost::mp11::mp_list<uint8_t, uint16_t, uint32_t, uint64_t>;
59 size_t packingWidth = utils::toBits<packing_type>() - 3;
71 for (
size_t packingWidth = 1; packingWidth <= 58; ++packingWidth) {
72 BOOST_TEST_MESSAGE(fmt::format(
"Checking {} Bit Packing", packingWidth));
74 auto source = makeRandomUniformVector<source_type>(
BufferSize, 0, utils::pow2(packingWidth) - 1);
77 BitPtr packIter{packingBuffer.data()};
79 packIter =
pack(packIter,
i, packingWidth);
82 BitPtr unpackIter{packingBuffer.data()};
84 for (
size_t i = 0;
i <
source.size(); ++
i) {
85 result[
i] = unpack<uint64_t>(unpackIter, packingWidth);
86 unpackIter += packingWidth;
99 for (
size_t packingWidth = 1; packingWidth <= 63; ++packingWidth) {
100 BOOST_TEST_MESSAGE(fmt::format(
"Checking {} Bit Packing", packingWidth));
102 auto source = makeRandomUniformVector<source_type>(
BufferSize, 0, utils::pow2(packingWidth) - 1);
105 BitPtr packIter{packingBuffer.data()};
107 packIter =
packLong(packIter,
i, packingWidth);
110 BitPtr unpackIter{packingBuffer.data()};
112 for (
size_t i = 0;
i <
source.size(); ++
i) {
114 unpackIter += packingWidth;
127 for (
size_t packingWidth = 1; packingWidth <= 63; ++packingWidth) {
128 BOOST_TEST_MESSAGE(fmt::format(
"Checking {} Bit Packing", packingWidth));
129 auto source = makeRandomUniformVector<source_type>(
BufferSize, 0, utils::pow2(packingWidth) - 1);
134 [[maybe_unused]]
auto packingBufferEnd =
pack(
source.data(),
source.size(), packingBuffer.data(), packingWidth,
min);
136 std::vector<source_type> unpackBuffer(
source.size(), 0);
137 unpack(packingBuffer.data(),
source.size(), unpackBuffer.data(), packingWidth,
min);
140 BOOST_CHECK_EQUAL_COLLECTIONS(
source.begin(),
source.end(), unpackBuffer.begin(), unpackBuffer.end());
148 for (
size_t packingWidth = 1; packingWidth <= 32; ++packingWidth) {
149 BOOST_TEST_MESSAGE(fmt::format(
"Checking {} Bit Elias Delta Coder", packingWidth));
150 auto source = makeRandomUniformVector<source_type>(
BufferSize, 1ull, utils::pow2(packingWidth) - 1);
151 std::vector<uint64_t> packingBuffer(
source.size(), 0);
153 BitPtr iter{packingBuffer.data()};
158 BitPtr iterBegin{packingBuffer.data()};
159 std::vector<source_type> unpackBuffer(
source.size(), 0);
160 for (
size_t i = 0;
i <
source.size(); ++
i) {
162 unpackBuffer[
i] = eliasDeltaDecode<source_type>(iter, maxOffset);
166 BOOST_CHECK_EQUAL_COLLECTIONS(
source.begin(),
source.end(), unpackBuffer.rbegin(), unpackBuffer.rend());
Pointer type helper class for bitwise Packing.
compress data stream using Elias-Delta coding.
GLsizei GLsizei GLchar * source
BitPtr pack(BitPtr pos, uint64_t data, size_t packingWidth)
BitPtr eliasDeltaEncode(BitPtr dst, uint32_t data)
constexpr size_t EliasDeltaDecodeMaxBits
uint64_t unpackLong(BitPtr pos, size_t packingWidth)
T unpack(BitPtr pos, size_t packingWidth)
BitPtr packLong(BitPtr pos, uint64_t data, size_t packingWidth)
boost::mp11::mp_list< uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t > source_types
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
BOOST_AUTO_TEST_CASE_TEMPLATE(test_computePackingBufferSize, buffer_T, buffer_types)
std::vector< source_T > makeRandomUniformVector(size_t nelems, source_T min=std::numeric_limits< source_T >::min(), source_T max=std::numeric_limits< source_T >::max())
BOOST_AUTO_TEST_CASE(test_packUnpack)
constexpr size_t BufferSize
boost::mp11::mp_list< int8_t, int16_t, int32_t, int64_t > buffer_types