Project
Loading...
Searching...
No Matches
HighRangeDecoderTable.h
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#ifndef RANS_INTERNAL_CONTAINERS_HIGHRANGEDECODERTABLE_H_
17#define RANS_INTERNAL_CONTAINERS_HIGHRANGEDECODERTABLE_H_
18
19#include <vector>
20#include <type_traits>
21#include <fairlogger/Logger.h>
22
26
27namespace o2::rans
28{
29
30template <typename source_T>
32{
33 public:
37 using value_type = std::pair<source_type, const symbol_type&>;
38 using size_type = std::size_t;
39 using difference_type = std::ptrdiff_t;
40
41 private:
43 using container_type = std::vector<storage_type>;
44
45 public:
46 inline HighRangeDecoderTable() noexcept = default;
47
48 template <typename container_T>
49 explicit HighRangeDecoderTable(const RenormedHistogramConcept<container_T>& renormedHistogram);
50
51 [[nodiscard]] inline size_type size() const noexcept { return mContainer.size(); };
52
53 [[nodiscard]] inline bool isEscapeSymbol(count_type cumul) const noexcept { return cumul >= this->size(); };
54
55 [[nodiscard]] inline bool hasEscapeSymbol() const noexcept { return mEscapeSymbol.getFrequency() > 0; };
56
57 [[nodiscard]] inline const symbol_type& getEscapeSymbol() const noexcept { return mEscapeSymbol; };
58
59 [[nodiscard]] inline value_type operator[](count_type cumul) const;
60
61 [[nodiscard]] inline size_type getPrecision() const noexcept { return mSymbolTablePrecision; };
62
63 private:
64 container_type mContainer{};
65 symbol_type mEscapeSymbol{};
66 size_type mSymbolTablePrecision{};
67};
68
69template <typename source_T>
70template <typename container_T>
71HighRangeDecoderTable<source_T>::HighRangeDecoderTable(const RenormedHistogramConcept<container_T>& renormedHistogram) : mSymbolTablePrecision{renormedHistogram.getRenormingBits()}
72{
73 if (renormedHistogram.empty()) {
74 LOG(warning) << "SymbolStatistics of empty message passed to " << __func__;
75 }
76
77 this->mContainer.reserve(renormedHistogram.getNumSamples());
78 const auto [trimmedBegin, trimmedEnd] = internal::trim(renormedHistogram);
79
80 this->mEscapeSymbol = [&]() -> symbol_type {
81 const count_type symbolFrequency = renormedHistogram.getIncompressibleSymbolFrequency();
82 const count_type cumulatedFrequency = renormedHistogram.getNumSamples() - symbolFrequency;
83 return {symbolFrequency, cumulatedFrequency};
84 }();
85
86 count_type cumulative = 0;
87 internal::forEachIndexValue(renormedHistogram, trimmedBegin, trimmedEnd, [&](const source_type& sourceSymbol, const count_type& frequency) {
88 if (frequency > 0) {
89 this->mContainer.insert(mContainer.end(), frequency, {sourceSymbol, frequency, cumulative});
90 cumulative += frequency;
91 }
92 });
93};
94
95template <typename source_T>
96[[nodiscard]] inline auto HighRangeDecoderTable<source_T>::operator[](count_type cumul) const -> value_type
97{
98 assert(cumul < this->size());
99 const auto& val = mContainer[cumul];
100 return {val.getSourceSymbol(), val.getDecoderSymbol()};
101};
102
103} // namespace o2::rans
104#endif /* RANS_INTERNAL_CONTAINERS_HIGHRANGEDECODERTABLE_H_ */
Histogram renormed to sum of frequencies being 2^P for use in fast rans coding.
Contains statistical information for one source symbol, required for encoding/decoding.
common helper classes and functions
value_type operator[](count_type cumul) const
size_type getPrecision() const noexcept
std::pair< source_type, const symbol_type & > value_type
HighRangeDecoderTable() noexcept=default
const symbol_type & getEscapeSymbol() const noexcept
size_type size() const noexcept
bool isEscapeSymbol(count_type cumul) const noexcept
value_type getIncompressibleSymbolFrequency() const noexcept
constexpr value_type getFrequency() const noexcept
Definition Symbol.h:42
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLfloat * val
Definition glcorearb.h:1582
auto trim(typename container_T::iterator begin, typename container_T::iterator end, typename container_T::const_reference zeroElem={}) -> std::pair< typename container_T::iterator, typename container_T::iterator >
Definition algorithm.h:104
void forEachIndexValue(const container_T &container, typename container_T::const_iterator begin, typename container_T::const_iterator end, F functor)
Definition algorithm.h:80
class DenseHistogram< source_T, std::enable_if_t< sizeof(source_T)<=2 > > :public internal::VectorContainer< source_T, uint32_t >, internal::HistogramConcept< source_T, typename internal::VectorContainer< source_T, uint32_t >::value_type, typename internal::VectorContainer< source_T, uint32_t >::difference_type, DenseHistogram< source_T > >{ using containerBase_type=internal::VectorContainer< source_T, uint32_t >;using HistogramConcept_type=internal::HistogramConcept< source_T, typename internal::VectorContainer< source_T, uint32_t >::value_type, typename internal::VectorContainer< source_T, uint32_t >::difference_type, DenseHistogram< source_T > >;friend containerBase_type;friend HistogramConcept_type;public:using source_type=source_T;using value_type=typename containerBase_type::value_type;using container_type=typename containerBase_type::container_type;using size_type=typename containerBase_type::size_type;using difference_type=typename containerBase_type::difference_type;using reference=typename containerBase_type::reference;using const_reference=typename containerBase_type::const_reference;using pointer=typename containerBase_type::pointer;using const_pointer=typename containerBase_type::const_pointer;using const_iterator=typename containerBase_type::const_iterator;DenseHistogram() :containerBase_type{MaxSize, std::numeric_limits< source_type >::min()} {};template< typename freq_IT > DenseHistogram(freq_IT begin, freq_IT end, difference_type offset) :containerBase_type{MaxSize, std::numeric_limits< source_type >::min()}, HistogramConcept_type{begin, end, offset} {};using HistogramConcept_type::addSamples;template< typename source_IT > inline DenseHistogram &addSamples(source_IT begin, source_IT end, source_type min, source_type max) { return addSamplesImpl(begin, end);};template< typename source_IT > DenseHistogram &addSamples(gsl::span< const source_type > span, source_type min, source_type max) { return addSamplesImpl(span);};using HistogramConcept_type::addFrequencies;protected:template< typename source_IT > DenseHistogram &addSamplesImpl(source_IT begin, source_IT end);DenseHistogram &addSamplesImpl(gsl::span< const source_type > samples);template< typename freq_IT > DenseHistogram &addFrequenciesImpl(freq_IT begin, freq_IT end, difference_type offset);private:inline static constexpr size_t MaxSize=utils::pow2(utils::toBits< source_type >());};template< typename source_T >template< typename source_IT >auto DenseHistogram< source_T, std::enable_if_t< sizeof(source_T)<=2 > >::addSamplesImpl(source_IT begin, source_IT end) -> DenseHistogram &{ if constexpr(std::is_pointer_v< source_IT >) { return addSamplesImpl({begin, end});} else { std::for_each(begin, end,[this](const source_type &symbol) {++this->mNSamples;++this->mContainer[symbol];});} return *this;}template< typename source_T >auto DenseHistogram< source_T, std::enable_if_t< sizeof(source_T)<=2 > >::addSamplesImpl(gsl::span< const source_type > samples) -> DenseHistogram &{ using namespace internal;using namespace utils;if(samples.empty()) { return *this;} const auto begin=samples.data();const auto end=begin+samples.size();constexpr size_t ElemsPerQWord=sizeof(uint64_t)/sizeof(source_type);constexpr size_t nUnroll=2 *ElemsPerQWord;auto iter=begin;if constexpr(sizeof(source_type)==1) { std::array< ShiftableVector< source_type, value_type >, 3 > histograms{ {{this-> mContainer size()
uint32_t count_t
Definition defaults.h:34
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"