Project
Loading...
Searching...
No Matches
factory.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_FACTORY_H_
17#define RANS_FACTORY_H_
18
19#ifdef __CLING__
20#error rANS should not be exposed to root
21#endif
22
26
29
32
35
38
40
44
48
51
52namespace o2::rans
53{
54
55namespace internal
56{
57
58template <template <class... types> class histogram_T>
60
61 template <typename source_T>
62 using histogram_type = histogram_T<source_T>;
63
64 template <typename source_IT>
65 [[nodiscard]] inline static decltype(auto) fromSamples(source_IT begin, source_IT end)
66 {
67 using source_type = typename std::iterator_traits<source_IT>::value_type;
68
70 f.addSamples(begin, end);
71 return f;
72 };
73
74 template <typename source_T>
75 [[nodiscard]] inline static decltype(auto) fromSamples(gsl::span<const source_T> range)
76 {
77 using source_type = typename std::remove_cv_t<source_T>;
78
80 f.addSamples(range);
81 return f;
82 };
83};
84
85template <template <typename source_T, typename symbol_T> class symbolTable_T,
86 CoderTag coderTag_V = defaults::DefaultTag,
88 size_t renormingLowerBound_V = defaults::CoderPreset<coderTag_V>::renormingLowerBound>
90{
91 private:
92 static constexpr size_t NStreams = nStreams_V;
93 static constexpr size_t RenormingLowerBound = renormingLowerBound_V;
94 static constexpr CoderTag coderTag = coderTag_V;
95
97 using symbol_type = typename internal::SymbolTraits<coderTag>::type;
99 template <typename source_T>
100 using symbolTable_type = symbolTable_T<source_T, symbol_type>;
101 template <typename source_T>
103
104 public:
105 template <typename container_T>
106 [[nodiscard]] inline static constexpr decltype(auto) fromRenormed(const RenormedHistogramConcept<container_T>& renormed)
107 {
109 return encoderType<source_type>{renormed};
110 };
111
112 template <typename histogram_T>
113 [[nodiscard]] inline static decltype(auto) fromHistogram(histogram_T histogram, RenormingPolicy renormingPolicy = RenormingPolicy::Auto)
114 {
115 static_assert(internal::isHistogram_v<histogram_T>);
116 const auto renormedHistogram = renorm(std::move(histogram), renormingPolicy);
117 return this_type::fromRenormed(renormedHistogram);
118 };
119
120 template <typename histogram_T>
121 [[nodiscard]] inline static decltype(auto) fromHistogram(histogram_T histogram, Metrics<typename histogram_T::source_type>& metrics, RenormingPolicy renormingPolicy = RenormingPolicy::Auto)
122 {
123 static_assert(internal::isHistogram_v<histogram_T>);
124 const auto renormedHistogram = renorm(std::move(histogram), metrics, renormingPolicy);
125 return this_type::fromRenormed(renormedHistogram);
126 };
127
128 template <typename histogram_T>
129 [[nodiscard]] inline static decltype(auto) fromHistogram(histogram_T histogram, size_t renormingPrecision, RenormingPolicy renormingPolicy = RenormingPolicy::Auto)
130 {
131 static_assert(internal::isHistogram_v<histogram_T>);
132 const auto renormedHistogram = renorm(std::move(histogram), renormingPrecision, renormingPolicy);
133 return this_type::fromRenormed(renormedHistogram);
134 };
135};
136} // namespace internal
137
138struct makeDenseHistogram : public internal::makeHistogram<DenseHistogram> {
140
142
143 template <typename source_IT>
144 [[nodiscard]] inline static decltype(auto) fromSamples(source_IT begin, source_IT end,
145 typename std::iterator_traits<source_IT>::value_type min,
146 typename std::iterator_traits<source_IT>::value_type max)
147 {
148 using source_type = typename std::iterator_traits<source_IT>::value_type;
150
152 f.addSamples(begin, end, min, max);
153 return f;
154 };
155
156 template <typename source_T>
157 [[nodiscard]] inline static decltype(auto) fromSamples(gsl::span<const source_T> range, source_T min, source_T max)
158 {
159 using source_type = typename std::remove_cv_t<source_T>;
161
163 f.addSamples(range, min, max);
164 return f;
165 };
166};
167
169
171
172template <CoderTag coderTag_V = defaults::DefaultTag,
174 size_t renormingLowerBound_V = defaults::CoderPreset<coderTag_V>::renormingLowerBound>
176
177template <CoderTag coderTag_V = defaults::DefaultTag,
179 size_t renormingLowerBound_V = defaults::CoderPreset<coderTag_V>::renormingLowerBound>
181
182template <CoderTag coderTag_V = defaults::DefaultTag,
184 size_t renormingLowerBound_V = defaults::CoderPreset<coderTag_V>::renormingLowerBound>
186
187template <size_t renormingLowerBound_V = defaults::internal::RenormingLowerBound>
189{
190
192
193 public:
194 template <typename source_T>
195 [[nodiscard]] inline static constexpr decltype(auto) fromRenormed(const RenormedDenseHistogram<source_T>& renormed)
196 {
197 using namespace internal;
198
199 using source_type = source_T;
200 using coder_type = DecoderImpl<renormingLowerBound_V>;
201 using decoder_type = Decoder<source_type, coder_type>;
202
203 return decoder_type{renormed};
204 };
205
206 template <typename source_T>
207 [[nodiscard]] inline static decltype(auto) fromHistogram(DenseHistogram<source_T> histogram, RenormingPolicy renormingPolicy = RenormingPolicy::Auto)
208 {
209 const auto renormedHistogram = renorm(std::move(histogram), renormingPolicy);
210 return this_type::fromRenormed(renormedHistogram);
211 };
212
213 template <typename source_T>
214 [[nodiscard]] inline static decltype(auto) fromHistogram(DenseHistogram<source_T> histogram, Metrics<source_T>& metrics, RenormingPolicy renormingPolicy = RenormingPolicy::Auto)
215 {
216 const auto renormedHistogram = renorm(std::move(histogram), metrics, renormingPolicy);
217 return this_type::fromRenormed(renormedHistogram);
218 };
219
220 template <typename source_T>
221 [[nodiscard]] inline static decltype(auto) fromHistogram(DenseHistogram<source_T> histogram, size_t renormingPrecision, RenormingPolicy renormingPolicy = RenormingPolicy::Auto)
222 {
223 const auto renormedHistogram = renorm(std::move(histogram), renormingPrecision);
224 return this_type::fromRenormed(renormedHistogram);
225 };
226};
227
228template <typename source_T>
230
231template <typename source_T>
233
234template <typename source_T>
236
237template <typename source_T>
239
240} // namespace o2::rans
241
242#endif /* RANS_FACTORY_H_ */
Lookup table containing statistical information for each symbol in the alphabet required for encoding...
Operations to decode a rANS stream.
Histogram for source symbols used to estimate symbol probabilities for entropy coding.
Lookup table containing statistical information for each symbol in the alphabet required for encoding...
Maps rANS state information back to source symbol, used for decoding.
Maps rANS state information back to source symbol, used for decoding.
Computes and provides essential metrics on the dataset used for parameter and size estimates by other...
Histogram renormed to sum of frequencies being 2^P for use in fast rans coding.
rANS encoding operations that encode multiple symbols simultaniously using SIMD. Unified implementati...
rANS encoding operations based on ryg's fast algorithm and a naive rANS implementation for all 64Bit ...
Histogram to depict frequencies of source symbols for rANS compression, based on an ordered set.
Contains statistical information for one source symbol, required for encoding/decoding.
Decoder - User facing class to decode a rANS encoded stream back into the source data based on the sa...
Encoder - User facing class to perform rANS entropy coding of source symbols onto a rANS state based ...
uint32_t source_type
typename base_type::source_type source_type
static constexpr decltype(auto) fromRenormed(const RenormedHistogramConcept< container_T > &renormed)
Definition factory.h:106
static decltype(auto) fromHistogram(histogram_T histogram, Metrics< typename histogram_T::source_type > &metrics, RenormingPolicy renormingPolicy=RenormingPolicy::Auto)
Definition factory.h:121
static decltype(auto) fromHistogram(histogram_T histogram, size_t renormingPrecision, RenormingPolicy renormingPolicy=RenormingPolicy::Auto)
Definition factory.h:129
static decltype(auto) fromHistogram(histogram_T histogram, RenormingPolicy renormingPolicy=RenormingPolicy::Auto)
Definition factory.h:113
static decltype(auto) fromHistogram(DenseHistogram< source_T > histogram, size_t renormingPrecision, RenormingPolicy renormingPolicy=RenormingPolicy::Auto)
Definition factory.h:221
static decltype(auto) fromHistogram(DenseHistogram< source_T > histogram, Metrics< source_T > &metrics, RenormingPolicy renormingPolicy=RenormingPolicy::Auto)
Definition factory.h:214
static constexpr decltype(auto) fromRenormed(const RenormedDenseHistogram< source_T > &renormed)
Definition factory.h:195
static decltype(auto) fromHistogram(DenseHistogram< source_T > histogram, RenormingPolicy renormingPolicy=RenormingPolicy::Auto)
Definition factory.h:207
sane compile time defaults for encoders/decoders
GLuint GLuint end
Definition glcorearb.h:469
GLsizei GLenum GLenum * types
Definition glcorearb.h:2516
GLsizei GLenum const void GLuint GLsizei GLfloat * metrics
Definition glcorearb.h:5500
GLdouble f
Definition glcorearb.h:310
GLenum GLint * range
Definition glcorearb.h:1899
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
decltype(makeDenseEncoder<>::fromRenormed(RenormedDenseHistogram< source_T >{})) denseEncoder_type
Definition factory.h:229
decltype(makeSparseEncoder<>::fromRenormed(RenormedSparseHistogram< source_T >{})) sparseEncoder_type
Definition factory.h:235
decltype(makeDecoder<>::fromRenormed(RenormedDenseHistogram< source_T >{})) defaultDecoder_type
Definition factory.h:238
decltype(auto) renorm(histogram_T histogram, size_t newPrecision, RenormingPolicy renormingPolicy=RenormingPolicy::Auto, size_t lowProbabilityCutoffBits=0)
Definition renorm.h:203
RenormingPolicy
Definition renorm.h:32
decltype(makeAdaptiveEncoder<>::fromRenormed(RenormedAdaptiveHistogram< source_T >{})) adaptiveEncoder_type
Definition factory.h:232
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)
Definition factory.h:65
static decltype(auto) fromSamples(gsl::span< const source_T > range)
Definition factory.h:75
histogram_T< source_T > histogram_type
Definition factory.h:62
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
static decltype(auto) fromSamples(gsl::span< const source_T > range, source_T min, source_T max)
Definition factory.h:157
constexpr size_t min
constexpr size_t max
manipulation of types at compile time