// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
void RoundtripRandomStream(int alphabet_size, size_t reps = kReps,
size_t num = 1 << 18) {
constexpr int kNumHistograms = 3;
Rng rng(0); for (size_t i = 0; i < reps; i++) {
std::vector<Token> symbols; for (size_t j = 0; j < num; j++) { int context = rng.UniformI(0, kNumHistograms); int value = rng.UniformU(0, alphabet_size);
symbols.emplace_back(context, value);
}
RoundtripTestcase(kNumHistograms, alphabet_size, symbols);
}
}
void RoundtripRandomUnbalancedStream(int alphabet_size) {
constexpr int kNumHistograms = 3;
constexpr int kPrecision = 1 << 10;
Rng rng(0); for (size_t i = 0; i < kReps; i++) {
std::vector<int> distributions[kNumHistograms] = {}; for (auto& distr : distributions) {
distr.resize(kPrecision); int symbol = 0; int remaining = 1; for (int k = 0; k < kPrecision; k++) { if (remaining == 0) { if (symbol < alphabet_size - 1) symbol++; // There is no meaning behind this distribution: it's anything that // will create a nonuniform distribution and won't have too few // symbols usually. Also we want different distributions we get to be // sufficiently dissimilar.
remaining = rng.UniformU(0, kPrecision - k + 1);
}
distr[k] = symbol;
remaining--;
}
}
std::vector<Token> symbols; for (int j = 0; j < 1 << 18; j++) { int context = rng.UniformI(0, kNumHistograms); int value = rng.UniformU(0, kPrecision);
symbols.emplace_back(context, value);
}
RoundtripTestcase(kNumHistograms + 1, alphabet_size, symbols);
}
}
TEST(ANSTest, UintConfigRoundtrip) {
JxlMemoryManager* memory_manager = jxl::test::MemoryManager(); for (size_t log_alpha_size = 5; log_alpha_size <= 8; log_alpha_size++) {
std::vector<HybridUintConfig> uint_config;
std::vector<HybridUintConfig> uint_config_dec; for (size_t i = 0; i < log_alpha_size; i++) { for (size_t j = 0; j <= i; j++) { for (size_t k = 0; k <= i - j; k++) {
uint_config.emplace_back(i, j, k);
}
}
}
uint_config.emplace_back(log_alpha_size, 0, 0);
uint_config_dec.resize(uint_config.size());
BitWriter writer{memory_manager};
ASSERT_TRUE(writer.WithMaxBits(
10 * uint_config.size(), LayerType::Header, nullptr, [&] {
EncodeUintConfigs(uint_config, &writer, log_alpha_size); returntrue;
}));
writer.ZeroPadToByte();
BitReader br(writer.GetSpan());
EXPECT_TRUE(DecodeUintConfigs(log_alpha_size, &uint_config_dec, &br));
EXPECT_TRUE(br.Close()); for (size_t i = 0; i < uint_config.size(); i++) {
EXPECT_EQ(uint_config[i].split_token, uint_config_dec[i].split_token);
EXPECT_EQ(uint_config[i].msb_in_token, uint_config_dec[i].msb_in_token);
EXPECT_EQ(uint_config[i].lsb_in_token, uint_config_dec[i].lsb_in_token);
}
}
}
void TestCheckpointing(bool ans, bool lz77) {
JxlMemoryManager* memory_manager = jxl::test::MemoryManager();
std::vector<std::vector<Token>> input_values(1); for (size_t i = 0; i < 1024; i++) {
input_values[0].emplace_back(0, i % 4);
} // up to lz77 window size. for (size_t i = 0; i < (1 << 20) - 1022; i++) {
input_values[0].emplace_back(0, (i % 5) + 4);
} // Ensure that when the window wraps around, new values are different.
input_values[0].emplace_back(0, 0); for (size_t i = 0; i < 1024; i++) {
input_values[0].emplace_back(0, i % 4);
}
// We do not truncate the output. Reading past the end reads out zeroes // anyway.
BitReader br(writer.GetSpan());
Status status = true;
{
BitReaderScopedCloser bc(br, status);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.