20#error rANS should not be exposed to root
67 const uint32_t estimate = minBits * 3u / 2u;
71 return std::min(minThreshold, maxThreshold);
74template <
typename source_T>
79 constexpr size_t IncompressibleSymbolFrequency = 1;
81 if (histogram.empty()) {
82 LOG(warning) <<
"rescaling empty histogram";
87 if (newPrecision == 0) {
91 const size_t alphabetSize = histogram.size() + 1;
92 std::vector<uint64_t> cumulativeFrequencies(alphabetSize + 1);
93 cumulativeFrequencies[0] = 0;
94 std::inclusive_scan(histogram.begin(), histogram.end(), ++cumulativeFrequencies.begin(), std::plus<>(), 0ull);
95 cumulativeFrequencies.back() = histogram.getNumSamples() + IncompressibleSymbolFrequency;
97 auto getFrequency = [&cumulativeFrequencies](
count_t i) {
98 assert(cumulativeFrequencies[
i + 1] >= cumulativeFrequencies[
i]);
99 return cumulativeFrequencies[
i + 1] - cumulativeFrequencies[
i];
103 const auto sortIdx = [&]() {
105 indices.reserve(nUsedAlphabetSymbols + 1);
107 for (
size_t i = 0;
i < alphabetSize; ++
i) {
108 if (getFrequency(
i) != 0) {
119 size_t nSamples = histogram.getNumSamples() + IncompressibleSymbolFrequency;
120 assert(newCumulatedFrequency >= nUsedAlphabetSymbols);
121 size_t needsShift = 0;
122 for (
size_t i = 0;
i < sortIdx.size();
i++) {
123 if (
static_cast<count_t>(getFrequency(sortIdx[
i])) * (newCumulatedFrequency - needsShift) /
nSamples >= 1) {
130 auto beforeUpdate = cumulativeFrequencies[0];
131 for (
size_t i = 0;
i < alphabetSize;
i++) {
132 auto& nextCumulative = cumulativeFrequencies[
i + 1];
133 uint64_t oldFrequeny = nextCumulative - beforeUpdate;
134 if (oldFrequeny && oldFrequeny * (newCumulatedFrequency - needsShift) /
nSamples < 1) {
137 beforeUpdate = cumulativeFrequencies[
i + 1];
138 nextCumulative = (
static_cast<uint64_t>(newCumulatedFrequency - needsShift) * nextCumulative) /
nSamples + shift;
140 assert(shift == needsShift);
144 assert(cumulativeFrequencies.front() == 0);
145 assert(cumulativeFrequencies.back() == newCumulatedFrequency);
147 for (
auto frequency : histogram) {
148 if (frequency == 0) {
149 assert(cumulativeFrequencies[
i + 1] == cumulativeFrequencies[
i]);
151 assert(cumulativeFrequencies[
i + 1] > cumulativeFrequencies[
i]);
159 assert(cumulativeFrequencies.size() == histogram.size() + 2);
161 for (
size_t i = 0;
i < histogram.size(); ++
i) {
162 rescaledFrequencies(
i) = getFrequency(
i);
173 template <
typename container_T>
179 using coder_command = SingleStreamEncoderImpl<mRenormingLowerBound>;
183 return encoderType{renormed};
186 template <
typename source_T>
193 template <
typename source_IT>
194 [[nodiscard]]
inline static decltype(
auto)
fromSamples(source_IT begin, source_IT
end,
size_t renormingPrecision = 0)
201 template <
typename source_T>
202 [[nodiscard]]
inline static decltype(
auto)
fromSamples(gsl::span<const source_T>
range,
size_t renormingPrecision = 0)
220 template <
typename container_T>
232 template <
typename source_T>
239 template <
typename source_IT>
240 [[nodiscard]]
inline static decltype(
auto)
fromSamples(source_IT begin, source_IT
end,
size_t renormingPrecision = 0)
246 template <
typename source_T>
247 [[nodiscard]]
inline static decltype(
auto)
fromSamples(gsl::span<const source_T>
range,
size_t renormingPrecision = 0)
259template <
typename source_T>
267template <
typename source_T>
275template <
typename source_T,
typename symbol_T>
278 const bool hasIncompressibleSymbol = symbolTable.getEscapeSymbol().getFrequency() > 0;
284 constexpr size_t sizeofStreamT =
sizeof(
uint32_t);
288 return nElements * sizeofStreamT;
291template <
typename source_T>
294template <
typename source_T>
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...
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h internal
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
Maps rANS state information back to source symbol, used for decoding.
Histogram renormed to sum of frequencies being 2^P for use in fast rans coding.
rANS encoding operations based on ryg's fast algorithm and a naive rANS implementation for all 64Bit ...
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 ...
typename base_type::value_type value_type
typename base_type::container_type container_type
typename base_type::source_type source_type
static constexpr decltype(auto) fromRenormed(const RenormedHistogramConcept< container_T > &renormed)
static decltype(auto) fromHistogram(DenseHistogram< source_T > histogram, size_t renormingPrecision=0)
static decltype(auto) fromSamples(source_IT begin, source_IT end, size_t renormingPrecision=0)
static decltype(auto) fromSamples(gsl::span< const source_T > range, size_t renormingPrecision=0)
static decltype(auto) fromHistogram(DenseHistogram< source_T > histogram, size_t renormingPrecision=0)
static decltype(auto) fromSamples(source_IT begin, source_IT end, size_t renormingPrecision=0)
static decltype(auto) fromSamples(gsl::span< const source_T > range, size_t renormingPrecision=0)
static constexpr decltype(auto) fromRenormed(const RenormedHistogramConcept< container_T > &renormed)
static factory classes for building histograms, encoders and decoders.
GLsizei GLenum const void * indices
constexpr uint32_t MinRenormThreshold
constexpr uint32_t MaxRenormThreshold
constexpr size_t RenormingLowerBound
size_t computeRenormingPrecision(size_t nUsedAlphabetSymbols)
decltype(makeEncoder::fromRenormed(RenormedDenseHistogram< source_T >{})) encoder_type
RenormedDenseHistogram< source_T > renorm(DenseHistogram< source_T > histogram, size_t newPrecision=0)
size_t getAlphabetRangeBits(const DenseHistogram< source_T > &histogram) noexcept
size_t calculateMaxBufferSizeB(size_t nElements, size_t rangeBits)
decltype(makeDecoder::fromRenormed(RenormedDenseHistogram< source_T >{})) decoder_type
constexpr size_t numBitsForNSymbols(size_t nSymbols) noexcept
constexpr size_t pow2(size_t n) noexcept
constexpr T log2UInt(T x) noexcept
auto makeHistogramView(container_T &container, std::ptrdiff_t offset) noexcept -> HistogramView< decltype(std::begin(container))>
HistogramView< Hist_IT > trim(const HistogramView< Hist_IT > &buffer)
size_t countNUsedAlphabetSymbols(const AdaptiveHistogram< source_T > &histogram)
static constexpr size_t nStreams
static constexpr size_t renormingLowerBound
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)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
manipulation of types at compile time