diff options
author | yazevnul <yazevnul@yandex-team.ru> | 2022-02-10 16:46:48 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:48 +0300 |
commit | 9abfb1a53b7f7b791444d1378e645d8fad9b06ed (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /util/random | |
parent | 8cbc307de0221f84c80c42dcbe07d40727537e2c (diff) | |
download | ydb-9abfb1a53b7f7b791444d1378e645d8fad9b06ed.tar.gz |
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/random')
-rw-r--r-- | util/random/benchmark/prng/main.cpp | 42 | ||||
-rw-r--r-- | util/random/benchmark/prng/metrics/main.py | 8 | ||||
-rw-r--r-- | util/random/benchmark/prng/metrics/ya.make | 26 | ||||
-rw-r--r-- | util/random/benchmark/prng/ya.make | 20 | ||||
-rw-r--r-- | util/random/benchmark/ya.make | 16 | ||||
-rw-r--r-- | util/random/common_ops.h | 28 | ||||
-rw-r--r-- | util/random/common_ops_ut.cpp | 10 | ||||
-rw-r--r-- | util/random/easy_ut.cpp | 4 | ||||
-rw-r--r-- | util/random/entropy.cpp | 20 | ||||
-rw-r--r-- | util/random/entropy.h | 6 | ||||
-rw-r--r-- | util/random/entropy_ut.cpp | 4 | ||||
-rw-r--r-- | util/random/fast.cpp | 8 | ||||
-rw-r--r-- | util/random/fast.h | 14 | ||||
-rw-r--r-- | util/random/fast_ut.cpp | 24 | ||||
-rw-r--r-- | util/random/lcg_engine.h | 2 | ||||
-rw-r--r-- | util/random/mersenne.h | 4 | ||||
-rw-r--r-- | util/random/mersenne32.cpp | 4 | ||||
-rw-r--r-- | util/random/mersenne32.h | 6 | ||||
-rw-r--r-- | util/random/mersenne64.cpp | 4 | ||||
-rw-r--r-- | util/random/mersenne64.h | 6 | ||||
-rw-r--r-- | util/random/mersenne_ut.cpp | 18 | ||||
-rw-r--r-- | util/random/normal_ut.cpp | 10 | ||||
-rw-r--r-- | util/random/random_ut.cpp | 12 | ||||
-rw-r--r-- | util/random/shuffle_ut.cpp | 8 |
24 files changed, 152 insertions, 152 deletions
diff --git a/util/random/benchmark/prng/main.cpp b/util/random/benchmark/prng/main.cpp index 4c3fc3872e..2c6279ff71 100644 --- a/util/random/benchmark/prng/main.cpp +++ b/util/random/benchmark/prng/main.cpp @@ -1,12 +1,12 @@ #include <library/cpp/testing/benchmark/bench.h> - -#include <util/random/entropy.h> -#include <util/random/fast.h> + +#include <util/random/entropy.h> +#include <util/random/fast.h> #include <util/random/normal.h> -#include <util/random/mersenne.h> -#include <util/system/compiler.h> +#include <util/random/mersenne.h> +#include <util/system/compiler.h> #include <util/generic/xrange.h> - + #include <random> // double part @@ -15,36 +15,36 @@ Y_CPU_BENCHMARK(Mersenne32_Double, p) { for (auto i : xrange<size_t>(0, p.Iterations())) { (void)i; - Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1()); - } -} - + Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1()); + } +} + Y_CPU_BENCHMARK(Mersenne64_Double, p) { TMersenne<ui64> rng(Seed()); for (auto i : xrange<size_t>(0, p.Iterations())) { (void)i; - Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1()); - } -} - + Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1()); + } +} + Y_CPU_BENCHMARK(Fast32_Double, p) { TFastRng<ui32> rng(Seed()); for (auto i : xrange<size_t>(0, p.Iterations())) { (void)i; - Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1()); - } -} - + Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1()); + } +} + Y_CPU_BENCHMARK(Fast64_Double, p) { TFastRng<ui64> rng(Seed()); for (auto i : xrange<size_t>(0, p.Iterations())) { (void)i; - Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1()); - } -} + Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1()); + } +} // integer part Y_CPU_BENCHMARK(mt19937_32, p) { diff --git a/util/random/benchmark/prng/metrics/main.py b/util/random/benchmark/prng/metrics/main.py index 7b8174a647..15b371fe75 100644 --- a/util/random/benchmark/prng/metrics/main.py +++ b/util/random/benchmark/prng/metrics/main.py @@ -1,5 +1,5 @@ -import yatest.common as yc - - -def test_export_metrics(metrics): +import yatest.common as yc + + +def test_export_metrics(metrics): metrics.set_benchmark(yc.execute_benchmark('util/random/benchmark/prng/prng', threads=8)) diff --git a/util/random/benchmark/prng/metrics/ya.make b/util/random/benchmark/prng/metrics/ya.make index 45f0ab0923..1f56aac0bd 100644 --- a/util/random/benchmark/prng/metrics/ya.make +++ b/util/random/benchmark/prng/metrics/ya.make @@ -1,21 +1,21 @@ -OWNER( - yazevnul +OWNER( + yazevnul g:util -) +) SUBSCRIBER(g:util-subscribers) - + PY2TEST() - + SIZE(LARGE) - -TAG( + +TAG( ya:force_sandbox - sb:intel_e5_2660v1 + sb:intel_e5_2660v1 ya:fat -) - +) + TEST_SRCS(main.py) - + DEPENDS(util/random/benchmark/prng) - -END() + +END() diff --git a/util/random/benchmark/prng/ya.make b/util/random/benchmark/prng/ya.make index a475d0c67f..976977014f 100644 --- a/util/random/benchmark/prng/ya.make +++ b/util/random/benchmark/prng/ya.make @@ -1,13 +1,13 @@ -OWNER( - yazevnul +OWNER( + yazevnul g:util -) +) SUBSCRIBER(g:util-subscribers) - + Y_BENCHMARK() - -SRCS( - main.cpp -) - -END() + +SRCS( + main.cpp +) + +END() diff --git a/util/random/benchmark/ya.make b/util/random/benchmark/ya.make index a4ae9d2728..7d753ae6e7 100644 --- a/util/random/benchmark/ya.make +++ b/util/random/benchmark/ya.make @@ -1,10 +1,10 @@ -OWNER( - yazevnul +OWNER( + yazevnul g:util -) +) SUBSCRIBER(g:util-subscribers) - -RECURSE( - prng - prng/metrics -) + +RECURSE( + prng + prng/metrics +) diff --git a/util/random/common_ops.h b/util/random/common_ops.h index 373046cdce..602eede351 100644 --- a/util/random/common_ops.h +++ b/util/random/common_ops.h @@ -4,31 +4,31 @@ #include <util/system/yassert.h> namespace NPrivate { - constexpr double ToRandReal1(const ui32 x) noexcept { + constexpr double ToRandReal1(const ui32 x) noexcept { return x * (double)(1.0 / 4294967295.0); } - constexpr double ToRandReal2(const ui32 x) noexcept { + constexpr double ToRandReal2(const ui32 x) noexcept { return x * (double)(1.0 / 4294967296.0); } - constexpr double ToRandReal3(const ui32 x) noexcept { + constexpr double ToRandReal3(const ui32 x) noexcept { return ((double)x + 0.5) * (double)(1.0 / 4294967296.0); } - constexpr double ToRandReal1(const ui64 x) noexcept { + constexpr double ToRandReal1(const ui64 x) noexcept { return (x >> 11) * (double)(1.0 / 9007199254740991.0); } - constexpr double ToRandReal2(const ui64 x) noexcept { + constexpr double ToRandReal2(const ui64 x) noexcept { return (x >> 11) * (double)(1.0 / 9007199254740992.0); } - constexpr double ToRandReal3(const ui64 x) noexcept { + constexpr double ToRandReal3(const ui64 x) noexcept { return ((x >> 12) + 0.5) * (double)(1.0 / 4503599627370496.0); } - constexpr double ToRandReal4(const ui64 x) noexcept { + constexpr double ToRandReal4(const ui64 x) noexcept { return double(x * (double)(1.0 / 18446744073709551616.0L)); } @@ -38,7 +38,7 @@ namespace NPrivate { } template <class T> - static constexpr ui64 ToRand64(T&&, ui64 x) noexcept { + static constexpr ui64 ToRand64(T&&, ui64 x) noexcept { return x; } @@ -47,7 +47,7 @@ namespace NPrivate { */ template <class T, class TRandGen> static T GenUniform(T max, TRandGen&& gen) { - Y_VERIFY(max > 0, "Invalid random number range [0, 0)"); + Y_VERIFY(max > 0, "Invalid random number range [0, 0)"); const T randmax = gen.RandMax() - gen.RandMax() % max; T rand; @@ -63,7 +63,7 @@ namespace NPrivate { template <class TRandType, class T> struct TCommonRNG { using TResult = TRandType; - using result_type = TRandType; + using result_type = TRandType; inline T& Engine() noexcept { return static_cast<T&>(*this); @@ -72,11 +72,11 @@ struct TCommonRNG { static constexpr TResult _Min = TResult(0); static constexpr TResult _Max = TResult(-1); - static constexpr TResult RandMax() noexcept { + static constexpr TResult RandMax() noexcept { return _Max; } - static constexpr TResult RandMin() noexcept { + static constexpr TResult RandMin() noexcept { return _Min; } @@ -120,11 +120,11 @@ struct TCommonRNG { return Engine().GenRand(); } - static constexpr TResult max() noexcept { + static constexpr TResult max() noexcept { return T::RandMax(); } - static constexpr TResult min() noexcept { + static constexpr TResult min() noexcept { return T::RandMin(); } }; diff --git a/util/random/common_ops_ut.cpp b/util/random/common_ops_ut.cpp index 4eea0eaf3f..905912bd1e 100644 --- a/util/random/common_ops_ut.cpp +++ b/util/random/common_ops_ut.cpp @@ -7,7 +7,7 @@ #include <random> -Y_UNIT_TEST_SUITE(TestCommonRNG) { +Y_UNIT_TEST_SUITE(TestCommonRNG) { template <class T> struct TRng: public TCommonRNG<T, TRng<T>> { inline T GenRand() noexcept { @@ -17,7 +17,7 @@ Y_UNIT_TEST_SUITE(TestCommonRNG) { T C_ = RandomNumber<T>(); }; - Y_UNIT_TEST(TestUniform1) { + Y_UNIT_TEST(TestUniform1) { TRng<ui32> r; for (size_t i = 0; i < 1000; ++i) { @@ -25,7 +25,7 @@ Y_UNIT_TEST_SUITE(TestCommonRNG) { } } - Y_UNIT_TEST(TestUniform2) { + Y_UNIT_TEST(TestUniform2) { TRng<ui32> r; for (size_t i = 0; i < 1000; ++i) { @@ -33,7 +33,7 @@ Y_UNIT_TEST_SUITE(TestCommonRNG) { } } - Y_UNIT_TEST(TestUniform3) { + Y_UNIT_TEST(TestUniform3) { TRng<ui32> r; for (size_t i = 0; i < 1000; ++i) { @@ -44,7 +44,7 @@ Y_UNIT_TEST_SUITE(TestCommonRNG) { } } - Y_UNIT_TEST(TestStlCompatibility) { + Y_UNIT_TEST(TestStlCompatibility) { { TRng<ui32> r; r.C_ = 17; diff --git a/util/random/easy_ut.cpp b/util/random/easy_ut.cpp index d8ac86dd29..d1d024a91f 100644 --- a/util/random/easy_ut.cpp +++ b/util/random/easy_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TEasyRndInterface) { - Y_UNIT_TEST(Test1) { +Y_UNIT_TEST_SUITE(TEasyRndInterface) { + Y_UNIT_TEST(Test1) { { ui32 x = 0; diff --git a/util/random/entropy.cpp b/util/random/entropy.cpp index 7450f390c2..3617edb83d 100644 --- a/util/random/entropy.cpp +++ b/util/random/entropy.cpp @@ -5,10 +5,10 @@ #include "shuffle.h" #include "init_atfork.h" -#include <util/stream/output.h> -#include <util/stream/mem.h> +#include <util/stream/output.h> +#include <util/stream/mem.h> #include <util/stream/zlib.h> -#include <util/stream/buffer.h> +#include <util/stream/buffer.h> #include <util/system/fs.h> #include <util/system/info.h> @@ -102,7 +102,7 @@ namespace { }; //not thread-safe - class TMersenneInput: public IInputStream { + class TMersenneInput: public IInputStream { using TKey = ui64; using TRnd = TMersenne<TKey>; @@ -134,7 +134,7 @@ namespace { TRnd Rnd_; }; - class TEntropyPoolStream: public IInputStream { + class TEntropyPoolStream: public IInputStream { public: inline explicit TEntropyPoolStream(const TBuffer& buffer) : Mi_(buffer) @@ -154,7 +154,7 @@ namespace { TBufferedInput Bi_; }; - struct TSeedStream: public IInputStream { + struct TSeedStream: public IInputStream { size_t DoRead(void* inbuf, size_t len) override { char* buf = (char*)inbuf; @@ -184,11 +184,11 @@ namespace { Reset(); } - inline IInputStream& EntropyPool() noexcept { + inline IInputStream& EntropyPool() noexcept { return *EP; } - inline IInputStream& Seed() noexcept { + inline IInputStream& Seed() noexcept { return SS; } @@ -208,11 +208,11 @@ namespace { using TRandomTraits = TDefaultTraits; } -IInputStream& EntropyPool() { +IInputStream& EntropyPool() { return TRandomTraits::Instance().EntropyPool(); } -IInputStream& Seed() { +IInputStream& Seed() { return TRandomTraits::Instance().Seed(); } diff --git a/util/random/entropy.h b/util/random/entropy.h index 9cb3b2abae..62029c1b63 100644 --- a/util/random/entropy.h +++ b/util/random/entropy.h @@ -1,19 +1,19 @@ #pragma once class TBuffer; -class IInputStream; +class IInputStream; /* * fast entropy pool, based on good prng, can lock for some time * initialized with some bits from system entropy pool * think as /dev/urandom replacement */ -IInputStream& EntropyPool(); +IInputStream& EntropyPool(); /* * fast(non-blocking) entropy pool, useful for seeding PRNGs */ -IInputStream& Seed(); +IInputStream& Seed(); /* * Re-initialize entropy pool - useful after forking in multi-process programs. diff --git a/util/random/entropy_ut.cpp b/util/random/entropy_ut.cpp index ed976a9c64..1ff27203f0 100644 --- a/util/random/entropy_ut.cpp +++ b/util/random/entropy_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TestEntropy) { - Y_UNIT_TEST(TestSeed) { +Y_UNIT_TEST_SUITE(TestEntropy) { + Y_UNIT_TEST(TestSeed) { char buf[100]; for (size_t i = 0; i < sizeof(buf); ++i) { diff --git a/util/random/fast.cpp b/util/random/fast.cpp index 82d3c9bf76..2f98dfc5d3 100644 --- a/util/random/fast.cpp +++ b/util/random/fast.cpp @@ -27,13 +27,13 @@ TFastRng64::TArgs::TArgs(ui64 seed) noexcept { Seq2 = rng.GenRand(); } -TFastRng64::TArgs::TArgs(IInputStream& entropy) { +TFastRng64::TArgs::TArgs(IInputStream& entropy) { static_assert(sizeof(*this) == 3 * sizeof(ui64), "please, fix me"); entropy.LoadOrFail(this, sizeof(*this)); } template <class T> -static inline T Read(IInputStream& in) noexcept { +static inline T Read(IInputStream& in) noexcept { T t = T(); in.LoadOrFail(&t, sizeof(t)); @@ -41,12 +41,12 @@ static inline T Read(IInputStream& in) noexcept { return t; } -TFastRng32::TFastRng32(IInputStream& entropy) +TFastRng32::TFastRng32(IInputStream& entropy) : TFastRng32(Read<ui64>(entropy), Read<ui32>(entropy)) { } -TReallyFastRng32::TReallyFastRng32(IInputStream& entropy) +TReallyFastRng32::TReallyFastRng32(IInputStream& entropy) : TReallyFastRng32(Read<ui64>(entropy)) { } diff --git a/util/random/fast.h b/util/random/fast.h index 194524d4b9..ddc5711641 100644 --- a/util/random/fast.h +++ b/util/random/fast.h @@ -3,7 +3,7 @@ #include "lcg_engine.h" #include "common_ops.h" -#include <util/generic/bitops.h> +#include <util/generic/bitops.h> #include <util/system/platform.h> // based on http://www.pcg-random.org/. See T*FastRng* family below. @@ -13,14 +13,14 @@ struct TPCGMixer { const ui32 xorshifted = ((x >> 18u) ^ x) >> 27u; const ui32 rot = x >> 59u; - return RotateBitsRight(xorshifted, rot); + return RotateBitsRight(xorshifted, rot); } }; using TFastRng32Base = TLcgRngBase<TLcgIterator<ui64, ULL(6364136223846793005)>, TPCGMixer>; using TReallyFastRng32Base = TLcgRngBase<TFastLcgIterator<ui64, ULL(6364136223846793005), ULL(1)>, TPCGMixer>; -class IInputStream; +class IInputStream; struct TFastRng32: public TCommonRNG<ui32, TFastRng32>, public TFastRng32Base { inline TFastRng32(ui64 seed, ui32 seq) @@ -28,7 +28,7 @@ struct TFastRng32: public TCommonRNG<ui32, TFastRng32>, public TFastRng32Base { { } - TFastRng32(IInputStream& entropy); + TFastRng32(IInputStream& entropy); }; // faster than TFastRng32, but have only one possible stream sequence @@ -38,14 +38,14 @@ struct TReallyFastRng32: public TCommonRNG<ui32, TReallyFastRng32>, public TReal { } - TReallyFastRng32(IInputStream& entropy); + TReallyFastRng32(IInputStream& entropy); }; class TFastRng64: public TCommonRNG<ui64, TFastRng64> { public: struct TArgs { TArgs(ui64 seed) noexcept; - TArgs(IInputStream& entropy); + TArgs(IInputStream& entropy); ui64 Seed1; ui64 Seed2; @@ -58,7 +58,7 @@ public: /* * simplify constructions like * TFastRng64 rng(17); - * TFastRng64 rng(Seek()); //from any IInputStream + * TFastRng64 rng(Seek()); //from any IInputStream */ inline TFastRng64(const TArgs& args) noexcept : TFastRng64(args.Seed1, args.Seq1, args.Seed2, args.Seq2) diff --git a/util/random/fast_ut.cpp b/util/random/fast_ut.cpp index a513a973b1..60994a98b0 100644 --- a/util/random/fast_ut.cpp +++ b/util/random/fast_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TTestFastRng) { - Y_UNIT_TEST(Test1) { +Y_UNIT_TEST_SUITE(TTestFastRng) { + Y_UNIT_TEST(Test1) { TFastRng32 rng1(17, 0); TReallyFastRng32 rng2(17); @@ -35,15 +35,15 @@ Y_UNIT_TEST_SUITE(TTestFastRng) { 75, }; - Y_UNIT_TEST(Test2) { + Y_UNIT_TEST(Test2) { TFastRng64 rng(0, 1, 2, 3); - for (auto& i : R1) { - UNIT_ASSERT_VALUES_EQUAL(rng.Uniform(100u), i); + for (auto& i : R1) { + UNIT_ASSERT_VALUES_EQUAL(rng.Uniform(100u), i); } } - Y_UNIT_TEST(TestAdvance) { + Y_UNIT_TEST(TestAdvance) { TReallyFastRng32 rng1(17); TReallyFastRng32 rng2(17); for (size_t i = 0; i < 100; i++) { @@ -61,7 +61,7 @@ Y_UNIT_TEST_SUITE(TTestFastRng) { UNIT_ASSERT_VALUES_EQUAL(rng3.GenRand(), rng4.GenRand()); } - Y_UNIT_TEST(TestAdvanceBoundaries) { + Y_UNIT_TEST(TestAdvanceBoundaries) { TReallyFastRng32 rng1(17); TReallyFastRng32 rng2(17); TReallyFastRng32 rng3(17); @@ -71,7 +71,7 @@ Y_UNIT_TEST_SUITE(TTestFastRng) { UNIT_ASSERT_VALUES_EQUAL(rng1.GenRand(), rng3.GenRand()); } - Y_UNIT_TEST(TestCopy) { + Y_UNIT_TEST(TestCopy) { TReallyFastRng32 r1(1); TReallyFastRng32 r2(2); @@ -82,13 +82,13 @@ Y_UNIT_TEST_SUITE(TTestFastRng) { UNIT_ASSERT_VALUES_EQUAL(r1.GenRand(), r2.GenRand()); } - Y_UNIT_TEST(Test3) { + Y_UNIT_TEST(Test3) { TFastRng64 rng(17); UNIT_ASSERT_VALUES_EQUAL(rng.GenRand(), ULL(14895365814383052362)); } - Y_UNIT_TEST(TestCompile) { + Y_UNIT_TEST(TestCompile) { TFastRng<ui32> rng1(1); TFastRng<ui64> rng2(2); TFastRng<size_t> rng3(3); @@ -103,14 +103,14 @@ Y_UNIT_TEST_SUITE(TTestFastRng) { "But apparently I made a blunder here -" "Doha does not warm ... Absolutely."; - Y_UNIT_TEST(TestStreamCtor1) { + Y_UNIT_TEST(TestStreamCtor1) { TMemoryInput mi(RNG_DATA, strlen(RNG_DATA)); TFastRng<ui32> rng(mi); UNIT_ASSERT_VALUES_EQUAL(rng.GenRand(), 1449109131u); } - Y_UNIT_TEST(TestStreamCtor2) { + Y_UNIT_TEST(TestStreamCtor2) { TMemoryInput mi(RNG_DATA, strlen(RNG_DATA)); TFastRng<ui64> rng(mi); diff --git a/util/random/lcg_engine.h b/util/random/lcg_engine.h index bee44db16c..08cc93c845 100644 --- a/util/random/lcg_engine.h +++ b/util/random/lcg_engine.h @@ -15,7 +15,7 @@ template <typename T, T A, T C> struct TFastLcgIterator { static_assert(C % 2 == 1, "C must be odd"); - static constexpr T Iterate(T x) noexcept { + static constexpr T Iterate(T x) noexcept { return x * A + C; } diff --git a/util/random/mersenne.h b/util/random/mersenne.h index 567fafc362..b2044604ac 100644 --- a/util/random/mersenne.h +++ b/util/random/mersenne.h @@ -19,7 +19,7 @@ namespace NPrivate { }; } -class IInputStream; +class IInputStream; template <class T> class TMersenne: public TCommonRNG<T, TMersenne<T>>, public ::NPrivate::TMersenneTraits<T>::TImpl { @@ -34,7 +34,7 @@ public: { } - inline TMersenne(IInputStream& pool) + inline TMersenne(IInputStream& pool) : TBase(pool) { } diff --git a/util/random/mersenne32.cpp b/util/random/mersenne32.cpp index 04a2af59e4..cb8aad8b03 100644 --- a/util/random/mersenne32.cpp +++ b/util/random/mersenne32.cpp @@ -83,13 +83,13 @@ void TMersenne32::InitNext() noexcept { mti = 0; } -TMersenne32::TMersenne32(IInputStream& input) +TMersenne32::TMersenne32(IInputStream& input) : mti(N + 1) { ui32 buf[128]; input.LoadOrFail(buf, sizeof(buf)); - InitByArray(buf, Y_ARRAY_SIZE(buf)); + InitByArray(buf, Y_ARRAY_SIZE(buf)); } #undef M diff --git a/util/random/mersenne32.h b/util/random/mersenne32.h index 75096e68a0..861f3a3d38 100644 --- a/util/random/mersenne32.h +++ b/util/random/mersenne32.h @@ -2,11 +2,11 @@ #include <util/system/defaults.h> -class IInputStream; +class IInputStream; namespace NPrivate { class TMersenne32 { - static constexpr int N = 624; + static constexpr int N = 624; public: inline TMersenne32(ui32 s = 19650218UL) noexcept @@ -21,7 +21,7 @@ namespace NPrivate { InitByArray(init_key, key_length); } - TMersenne32(IInputStream& input); + TMersenne32(IInputStream& input); inline ui32 GenRand() noexcept { if (mti >= N) { diff --git a/util/random/mersenne64.cpp b/util/random/mersenne64.cpp index 9426e58e5e..4ede2c6dca 100644 --- a/util/random/mersenne64.cpp +++ b/util/random/mersenne64.cpp @@ -85,13 +85,13 @@ void TMersenne64::InitNext() noexcept { mti = 0; } -TMersenne64::TMersenne64(IInputStream& input) +TMersenne64::TMersenne64(IInputStream& input) : mti(NN + 1) { ui64 buf[128]; input.LoadOrFail(buf, sizeof(buf)); - InitByArray(buf, Y_ARRAY_SIZE(buf)); + InitByArray(buf, Y_ARRAY_SIZE(buf)); } #undef MM diff --git a/util/random/mersenne64.h b/util/random/mersenne64.h index db40a939ac..12ca43b6af 100644 --- a/util/random/mersenne64.h +++ b/util/random/mersenne64.h @@ -2,11 +2,11 @@ #include <util/system/defaults.h> -class IInputStream; +class IInputStream; namespace NPrivate { class TMersenne64 { - static constexpr int NN = 312; + static constexpr int NN = 312; public: inline TMersenne64(ui64 s = ULL(19650218)) @@ -21,7 +21,7 @@ namespace NPrivate { InitByArray(keys, len); } - TMersenne64(IInputStream& input); + TMersenne64(IInputStream& input); inline ui64 GenRand() noexcept { if (mti >= NN) { diff --git a/util/random/mersenne_ut.cpp b/util/random/mersenne_ut.cpp index 27bd979deb..a4b84efa3d 100644 --- a/util/random/mersenne_ut.cpp +++ b/util/random/mersenne_ut.cpp @@ -2,11 +2,11 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/stream/output.h> +#include <util/stream/output.h> #define UI32(x) x##ul -Y_UNIT_TEST_SUITE(TMersenneRndTest) { +Y_UNIT_TEST_SUITE(TMersenneRndTest) { template <class T> inline void Test(const T* res, size_t len) { TMersenne<T> m; @@ -16,7 +16,7 @@ Y_UNIT_TEST_SUITE(TMersenneRndTest) { } } - Y_UNIT_TEST(Test32) { + Y_UNIT_TEST(Test32) { const ui32 res[] = { UI32(2325592414), UI32(482149846), @@ -30,10 +30,10 @@ Y_UNIT_TEST_SUITE(TMersenneRndTest) { UI32(3882134983), }; - Test<ui32>(res, Y_ARRAY_SIZE(res)); + Test<ui32>(res, Y_ARRAY_SIZE(res)); } - Y_UNIT_TEST(Test64) { + Y_UNIT_TEST(Test64) { const ui64 res[] = { ULL(13735441942630277712), ULL(10468394322237346228), @@ -47,10 +47,10 @@ Y_UNIT_TEST_SUITE(TMersenneRndTest) { ULL(11231499428520958715), }; - Test<ui64>(res, Y_ARRAY_SIZE(res)); + Test<ui64>(res, Y_ARRAY_SIZE(res)); } - Y_UNIT_TEST(TestGenRand64) { + Y_UNIT_TEST(TestGenRand64) { TMersenne<ui32> rng; for (size_t i = 0; i < 100; ++i) { @@ -58,7 +58,7 @@ Y_UNIT_TEST_SUITE(TMersenneRndTest) { } } - Y_UNIT_TEST(TestCopy32) { + Y_UNIT_TEST(TestCopy32) { TMersenne<ui32> r1(1); TMersenne<ui32> r2(2); @@ -69,7 +69,7 @@ Y_UNIT_TEST_SUITE(TMersenneRndTest) { UNIT_ASSERT_VALUES_EQUAL(r1.GenRand(), r2.GenRand()); } - Y_UNIT_TEST(TestCopy64) { + Y_UNIT_TEST(TestCopy64) { TMersenne<ui64> r1(1); TMersenne<ui64> r2(2); diff --git a/util/random/normal_ut.cpp b/util/random/normal_ut.cpp index 23311c8079..42b6cc4ba2 100644 --- a/util/random/normal_ut.cpp +++ b/util/random/normal_ut.cpp @@ -7,8 +7,8 @@ #include <functional> -Y_UNIT_TEST_SUITE(TestNormalDistribution) { - Y_UNIT_TEST(TestDefined) { +Y_UNIT_TEST_SUITE(TestNormalDistribution) { + Y_UNIT_TEST(TestDefined) { volatile auto x = NormalRandom<float>(0, 1) + NormalRandom<double>(0, 1) + NormalRandom<long double>(0, 1); (void)x; @@ -45,7 +45,7 @@ Y_UNIT_TEST_SUITE(TestNormalDistribution) { UNIT_ASSERT_DOUBLES_EQUAL(d, dd, (d + 1) * 0.05); } - Y_UNIT_TEST(Test1) { + Y_UNIT_TEST(Test1) { TestMD<float>(&StdNormalRandom<float>, 0, 1); TestMD<double>(&StdNormalRandom<double>, 0, 1); TestMD<long double>(&StdNormalRandom<long double>, 0, 1); @@ -67,13 +67,13 @@ Y_UNIT_TEST_SUITE(TestNormalDistribution) { }; } - Y_UNIT_TEST(Test2) { + Y_UNIT_TEST(Test2) { TestMD<float>(GenFunc1<float>(2, 3), 2, 3); TestMD<double>(GenFunc1<double>(3, 4), 3, 4); TestMD<long double>(GenFunc1<long double>(4, 5), 4, 5); } - Y_UNIT_TEST(Test3) { + Y_UNIT_TEST(Test3) { TestMD<float>(GenFunc2<float>(20, 30), 20, 30); TestMD<double>(GenFunc2<double>(30, 40), 30, 40); TestMD<long double>(GenFunc2<long double>(40, 50), 40, 50); diff --git a/util/random/random_ut.cpp b/util/random/random_ut.cpp index 1f52efe2fa..30427676f3 100644 --- a/util/random/random_ut.cpp +++ b/util/random/random_ut.cpp @@ -10,7 +10,7 @@ static inline void AssertRange(T v, T r1, T r2) { UNIT_ASSERT(v < r2); } -Y_UNIT_TEST_SUITE(TRandomNumberTest) { +Y_UNIT_TEST_SUITE(TRandomNumberTest) { template <typename T> void TestAll(T n) { for (T i = 0; i < n; ++i) { @@ -49,32 +49,32 @@ Y_UNIT_TEST_SUITE(TRandomNumberTest) { TestSome<T>(Max<T>() - 22222); } - Y_UNIT_TEST(TestWithLimit) { + Y_UNIT_TEST(TestWithLimit) { TestType<unsigned short>(); TestType<unsigned int>(); TestType<unsigned long>(); TestType<unsigned long long>(); } - Y_UNIT_TEST(TestRandomNumberFloat) { + Y_UNIT_TEST(TestRandomNumberFloat) { for (size_t i = 0; i < 1000; ++i) { AssertRange<float>(RandomNumber<float>(), 0.0, 1.0); } } - Y_UNIT_TEST(TestRandomNumberDouble) { + Y_UNIT_TEST(TestRandomNumberDouble) { for (size_t i = 0; i < 1000; ++i) { AssertRange<double>(RandomNumber<double>(), 0.0, 1.0); } } - Y_UNIT_TEST(TestRandomNumberLongDouble) { + Y_UNIT_TEST(TestRandomNumberLongDouble) { for (size_t i = 0; i < 1000; ++i) { AssertRange<long double>(RandomNumber<long double>(), 0.0, 1.0); } } - Y_UNIT_TEST(TestBoolean) { + Y_UNIT_TEST(TestBoolean) { while (RandomNumber<bool>()) { } while (!RandomNumber<bool>()) { diff --git a/util/random/shuffle_ut.cpp b/util/random/shuffle_ut.cpp index 5da99b0b48..87cbae94c0 100644 --- a/util/random/shuffle_ut.cpp +++ b/util/random/shuffle_ut.cpp @@ -6,7 +6,7 @@ #include <util/generic/ylimits.h> -Y_UNIT_TEST_SUITE(TRandUtilsTest) { +Y_UNIT_TEST_SUITE(TRandUtilsTest) { template <typename... A> static void TestRange(A&&... args) { TString s0, s1; @@ -55,19 +55,19 @@ Y_UNIT_TEST_SUITE(TRandUtilsTest) { TestRange(prng); } - Y_UNIT_TEST(TestShuffleMersenne32) { + Y_UNIT_TEST(TestShuffleMersenne32) { TMersenne<ui32> prng(24); TestIter(prng); } - Y_UNIT_TEST(TestShuffleFast32) { + Y_UNIT_TEST(TestShuffleFast32) { TFastRng32 prng(24, 0); TestIter(prng); } - Y_UNIT_TEST(TestShuffleFast64) { + Y_UNIT_TEST(TestShuffleFast64) { TFastRng64 prng(24, 0, 25, 1); TestIter(prng); |