Project
Loading...
Searching...
No Matches
test_ransReverseSymbolLookupTable.cxx
Go to the documentation of this file.
1// Copyright 2019-2023 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#define BOOST_TEST_MODULE Utility test
17#define BOOST_TEST_MAIN
18#define BOOST_TEST_DYN_LINK
19
20#include <numeric>
21#include <vector>
22#include <iterator>
23
24#include <boost/test/unit_test.hpp>
25#include <boost/mpl/vector.hpp>
26
31#include "rANS/factory.h"
32
33using namespace o2::rans;
34using namespace o2::rans::internal;
35
36template <typename T>
37size_t getNUniqueSymbols(const T& container)
38{
39 return std::count_if(container.begin(), container.end(), [](uint32_t value) { return value != 0; });
40};
41
43{
44 const auto renormedHistogram = renorm(DenseHistogram<uint32_t>{}, RenormingPolicy::ForceIncompressible);
45 const ReverseSymbolLookupTable<uint32_t> rLut{renormedHistogram};
46
47 const auto size = 0;
48 BOOST_CHECK_EQUAL(rLut.size(), size);
49
50 const std::vector<int32_t> res;
51 BOOST_CHECK_EQUAL_COLLECTIONS(rLut.begin(), rLut.end(), res.begin(), res.end());
52}
53
54#pragma GCC diagnostic ignored "-Wfree-nonheap-object" // TODO: Remove once this is fixed in GCC
55
56BOOST_AUTO_TEST_CASE(test_buildRLUT)
57{
58 const std::vector<int32_t> A{5, 5, 6, 6, 8, 8, 8, 8, 8, -1, -5, 2, 7, 3};
59 const std::vector<uint32_t> histA{1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 2, 2, 1, 5, 1};
60 const size_t scaleBits = 17;
61 const auto size = (1ull << scaleBits) - 1;
62
63 const auto renormedHistogram = renorm(makeDenseHistogram::fromSamples(A.begin(), A.end()), scaleBits, RenormingPolicy::ForceIncompressible);
64 const ReverseSymbolLookupTable<int32_t> rLut{renormedHistogram};
65
66 BOOST_CHECK_EQUAL(rLut.size(), size);
67
68 const auto min = *std::min_element(A.begin(), A.end());
69 const std::vector<uint32_t> frequencies{renormedHistogram.begin(), renormedHistogram.end()};
70 std::vector<uint32_t> cumulative;
71 std::exclusive_scan(frequencies.begin(), frequencies.end(), std::back_inserter(cumulative), 0);
72
73 for (size_t i = 0; i < frequencies.size(); ++i) {
74 const int symbol = min + i;
75 for (size_t cumul = cumulative[i]; cumul < cumulative[i] + frequencies[i]; ++cumul) {
76 BOOST_CHECK(cumul < rLut.size());
77 BOOST_CHECK_EQUAL(rLut[cumul], symbol);
78 }
79 }
80}
Histogram for source symbols used to estimate symbol probabilities for entropy coding.
int32_t i
uint32_t res
Definition RawData.h:0
Histogram renormed to sum of frequencies being 2^P for use in fast rans coding.
Maps rANS state information back to source symbol, used for decoding.
Definition A.h:16
static factory classes for building histograms, encoders and decoders.
GLsizeiptr size
Definition glcorearb.h:659
GLsizei const GLfloat * value
Definition glcorearb.h:819
decltype(auto) renorm(histogram_T histogram, size_t newPrecision, RenormingPolicy renormingPolicy=RenormingPolicy::Auto, size_t lowProbabilityCutoffBits=0)
Definition renorm.h:203
Renorm histogram to sum of frequencies = 2^P for use in fast rans coding. Includes estimation of P.
static decltype(auto) fromSamples(source_IT begin, source_IT end, typename std::iterator_traits< source_IT >::value_type min, typename std::iterator_traits< source_IT >::value_type max)
Definition factory.h:144
constexpr size_t min
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
size_t getNUniqueSymbols(const T &container)
BOOST_AUTO_TEST_CASE(test_empty)