Commit 6312b70b by Aaron Jacobs Committed by Copybara-Service

absl/random: run clang-format.

In order to avoid unrelated diffs in future changes that touch this code.

PiperOrigin-RevId: 694625990
Change-Id: I51ac54438a977f38c54c7638701d9ff3a259a58b
parent dee1b6c2
...@@ -359,7 +359,7 @@ void BM_Thread(benchmark::State& state) { ...@@ -359,7 +359,7 @@ void BM_Thread(benchmark::State& state) {
// ABSL Recommended interfaces. // ABSL Recommended interfaces.
BM_BASIC(absl::InsecureBitGen); // === pcg64_2018_engine BM_BASIC(absl::InsecureBitGen); // === pcg64_2018_engine
BM_BASIC(absl::BitGen); // === randen_engine<uint64_t>. BM_BASIC(absl::BitGen); // === randen_engine<uint64_t>.
BM_THREAD(absl::BitGen); BM_THREAD(absl::BitGen);
BM_EXTENDED(absl::BitGen); BM_EXTENDED(absl::BitGen);
......
...@@ -97,17 +97,16 @@ void CheckArgsInferType() { ...@@ -97,17 +97,16 @@ void CheckArgsInferType() {
template <typename A, typename B, typename ExplicitRet> template <typename A, typename B, typename ExplicitRet>
auto ExplicitUniformReturnT(int) -> decltype(absl::Uniform<ExplicitRet>( auto ExplicitUniformReturnT(int) -> decltype(absl::Uniform<ExplicitRet>(
std::declval<absl::InsecureBitGen&>(), std::declval<absl::InsecureBitGen&>(), std::declval<A>(),
std::declval<A>(), std::declval<B>())); std::declval<B>()));
template <typename, typename, typename ExplicitRet> template <typename, typename, typename ExplicitRet>
Invalid ExplicitUniformReturnT(...); Invalid ExplicitUniformReturnT(...);
template <typename TagType, typename A, typename B, typename ExplicitRet> template <typename TagType, typename A, typename B, typename ExplicitRet>
auto ExplicitTaggedUniformReturnT(int) auto ExplicitTaggedUniformReturnT(int) -> decltype(absl::Uniform<ExplicitRet>(
-> decltype(absl::Uniform<ExplicitRet>( std::declval<TagType>(), std::declval<absl::InsecureBitGen&>(),
std::declval<TagType>(), std::declval<absl::InsecureBitGen&>(), std::declval<A>(), std::declval<B>()));
std::declval<A>(), std::declval<B>()));
template <typename, typename, typename, typename ExplicitRet> template <typename, typename, typename, typename ExplicitRet>
Invalid ExplicitTaggedUniformReturnT(...); Invalid ExplicitTaggedUniformReturnT(...);
......
...@@ -96,4 +96,3 @@ TEST(Examples, CreateingCorrelatedVariateSequences) { ...@@ -96,4 +96,3 @@ TEST(Examples, CreateingCorrelatedVariateSequences) {
EXPECT_EQ(absl::Uniform<uint32_t>(gen_1), absl::Uniform<uint32_t>(gen_2)); EXPECT_EQ(absl::Uniform<uint32_t>(gen_1), absl::Uniform<uint32_t>(gen_2));
} }
} }
...@@ -57,7 +57,7 @@ class ABSL_DLL gaussian_distribution_base { ...@@ -57,7 +57,7 @@ class ABSL_DLL gaussian_distribution_base {
bool neg); bool neg);
// Constants used for the gaussian distribution. // Constants used for the gaussian distribution.
static constexpr double kR = 3.442619855899; // Start of the tail. static constexpr double kR = 3.442619855899; // Start of the tail.
static constexpr double kRInv = 0.29047645161474317; // ~= (1.0 / kR) . static constexpr double kRInv = 0.29047645161474317; // ~= (1.0 / kR) .
static constexpr double kV = 9.91256303526217e-3; static constexpr double kV = 9.91256303526217e-3;
static constexpr uint64_t kMask = 0x07f; static constexpr uint64_t kMask = 0x07f;
......
...@@ -117,7 +117,6 @@ void TestBernoulli(URBG* gen) { ...@@ -117,7 +117,6 @@ void TestBernoulli(URBG* gen) {
absl::Bernoulli(*gen, 0.5); absl::Bernoulli(*gen, 0.5);
} }
template <typename URBG> template <typename URBG>
void TestZipf(URBG* gen) { void TestZipf(URBG* gen) {
absl::Zipf<int>(*gen, 100); absl::Zipf<int>(*gen, 100);
......
...@@ -25,9 +25,7 @@ namespace { ...@@ -25,9 +25,7 @@ namespace {
#if defined(__EMSCRIPTEN__) #if defined(__EMSCRIPTEN__)
// Workaround __EMSCRIPTEN__ error: llvm_fma_f64 not found. // Workaround __EMSCRIPTEN__ error: llvm_fma_f64 not found.
inline double fma(double x, double y, double z) { inline double fma(double x, double y, double z) { return (x * y) + z; }
return (x * y) + z;
}
#endif #endif
// Use Horner's method to evaluate a polynomial. // Use Horner's method to evaluate a polynomial.
...@@ -105,9 +103,8 @@ double normal_survival(double z) { ...@@ -105,9 +103,8 @@ double normal_survival(double z) {
// p-value, usually using bisection. Also known by the name CRITCHI. // p-value, usually using bisection. Also known by the name CRITCHI.
double ChiSquareValue(int dof, double p) { double ChiSquareValue(int dof, double p) {
static constexpr double kChiEpsilon = static constexpr double kChiEpsilon =
0.000001; // Accuracy of the approximation. 0.000001; // Accuracy of the approximation.
static constexpr double kChiMax = static constexpr double kChiMax = 99999.0; // Maximum chi-squared value.
99999.0; // Maximum chi-squared value.
const double p_value = 1.0 - p; const double p_value = 1.0 - p;
if (dof < 1 || p_value > 1.0) { if (dof < 1 || p_value > 1.0) {
......
...@@ -291,8 +291,7 @@ TEST(ChiSquareTest, TableData) { ...@@ -291,8 +291,7 @@ TEST(ChiSquareTest, TableData) {
/*97*/ {115.223, 120.990, 126.141, 132.309, 145.789}, /*97*/ {115.223, 120.990, 126.141, 132.309, 145.789},
/*98*/ {116.315, 122.108, 127.282, 133.476, 147.010}, /*98*/ {116.315, 122.108, 127.282, 133.476, 147.010},
/*99*/ {117.407, 123.225, 128.422, 134.642, 148.230}, /*99*/ {117.407, 123.225, 128.422, 134.642, 148.230},
/*100*/ {118.498, 124.342, 129.561, 135.807, 149.449} /*100*/ {118.498, 124.342, 129.561, 135.807, 149.449} /**/};
/**/};
// 0.90 0.95 0.975 0.99 0.999 // 0.90 0.95 0.975 0.99 0.999
for (int i = 0; i < ABSL_ARRAYSIZE(data); i++) { for (int i = 0; i < ABSL_ARRAYSIZE(data); i++) {
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#ifndef ABSL_RANDOM_INTERNAL_DISTRIBUTION_CALLER_H_ #ifndef ABSL_RANDOM_INTERNAL_DISTRIBUTION_CALLER_H_
#define ABSL_RANDOM_INTERNAL_DISTRIBUTION_CALLER_H_ #define ABSL_RANDOM_INTERNAL_DISTRIBUTION_CALLER_H_
#include <utility>
#include <type_traits> #include <type_traits>
#include <utility>
#include "absl/base/config.h" #include "absl/base/config.h"
#include "absl/base/internal/fast_type_id.h" #include "absl/base/internal/fast_type_id.h"
......
...@@ -29,14 +29,18 @@ using ::absl::random_internal::ExplicitSeedSeq; ...@@ -29,14 +29,18 @@ using ::absl::random_internal::ExplicitSeedSeq;
template <typename Sseq> template <typename Sseq>
bool ConformsToInterface() { bool ConformsToInterface() {
// Check that the SeedSequence can be default-constructed. // Check that the SeedSequence can be default-constructed.
{ Sseq default_constructed_seq; } {
Sseq default_constructed_seq;
}
// Check that the SeedSequence can be constructed with two iterators. // Check that the SeedSequence can be constructed with two iterators.
{ {
uint32_t init_array[] = {1, 3, 5, 7, 9}; uint32_t init_array[] = {1, 3, 5, 7, 9};
Sseq iterator_constructed_seq(init_array, &init_array[5]); Sseq iterator_constructed_seq(init_array, &init_array[5]);
} }
// Check that the SeedSequence can be std::initializer_list-constructed. // Check that the SeedSequence can be std::initializer_list-constructed.
{ Sseq list_constructed_seq = {1, 3, 5, 7, 9, 11, 13}; } {
Sseq list_constructed_seq = {1, 3, 5, 7, 9, 11, 13};
}
// Check that param() and size() return state provided to constructor. // Check that param() and size() return state provided to constructor.
{ {
uint32_t init_array[] = {1, 2, 3, 4, 5}; uint32_t init_array[] = {1, 2, 3, 4, 5};
......
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
// //
// $ blaze run :gaussian_distribution_gentables > gaussian_distribution.cc // $ blaze run :gaussian_distribution_gentables > gaussian_distribution.cc
// //
#include "absl/random/gaussian_distribution.h"
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
#include <iostream> #include <iostream>
...@@ -25,6 +23,7 @@ ...@@ -25,6 +23,7 @@
#include <string> #include <string>
#include "absl/base/macros.h" #include "absl/base/macros.h"
#include "absl/random/gaussian_distribution.h"
namespace absl { namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// //
#include "absl/random/internal/randen.h"
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
...@@ -21,6 +19,7 @@ ...@@ -21,6 +19,7 @@
#include "absl/base/internal/raw_logging.h" #include "absl/base/internal/raw_logging.h"
#include "absl/random/internal/nanobenchmark.h" #include "absl/random/internal/nanobenchmark.h"
#include "absl/random/internal/platform.h" #include "absl/random/internal/platform.h"
#include "absl/random/internal/randen.h"
#include "absl/random/internal/randen_engine.h" #include "absl/random/internal/randen_engine.h"
#include "absl/random/internal/randen_hwaes.h" #include "absl/random/internal/randen_hwaes.h"
#include "absl/random/internal/randen_slow.h" #include "absl/random/internal/randen_slow.h"
......
...@@ -33,14 +33,18 @@ namespace { ...@@ -33,14 +33,18 @@ namespace {
template <typename Sseq> template <typename Sseq>
void ConformsToInterface() { void ConformsToInterface() {
// Check that the SeedSequence can be default-constructed. // Check that the SeedSequence can be default-constructed.
{ Sseq default_constructed_seq; } {
Sseq default_constructed_seq;
}
// Check that the SeedSequence can be constructed with two iterators. // Check that the SeedSequence can be constructed with two iterators.
{ {
uint32_t init_array[] = {1, 3, 5, 7, 9}; uint32_t init_array[] = {1, 3, 5, 7, 9};
Sseq iterator_constructed_seq(std::begin(init_array), std::end(init_array)); Sseq iterator_constructed_seq(std::begin(init_array), std::end(init_array));
} }
// Check that the SeedSequence can be std::initializer_list-constructed. // Check that the SeedSequence can be std::initializer_list-constructed.
{ Sseq list_constructed_seq = {1, 3, 5, 7, 9, 11, 13}; } {
Sseq list_constructed_seq = {1, 3, 5, 7, 9, 11, 13};
}
// Check that param() and size() return state provided to constructor. // Check that param() and size() return state provided to constructor.
{ {
uint32_t init_array[] = {1, 2, 3, 4, 5}; uint32_t init_array[] = {1, 2, 3, 4, 5};
......
...@@ -104,14 +104,11 @@ void CheckWideningConvertsTo() { ...@@ -104,14 +104,11 @@ void CheckWideningConvertsTo() {
TEST(TraitsTest, IsWideningConvertibleTest) { TEST(TraitsTest, IsWideningConvertibleTest) {
constexpr bool kInvalid = false; constexpr bool kInvalid = false;
CheckWideningConvertsToSelf< CheckWideningConvertsToSelf<uint8_t, uint16_t, uint32_t, uint64_t, int8_t,
uint8_t, uint16_t, uint32_t, uint64_t, int16_t, int32_t, int64_t, float, double>();
int8_t, int16_t, int32_t, int64_t, CheckNotWideningConvertibleWithSigned<uint8_t, uint16_t, uint32_t,
float, double>(); uint64_t>();
CheckNotWideningConvertibleWithSigned< CheckWideningConvertsToLargerTypes<uint8_t, uint16_t, uint32_t, uint64_t>();
uint8_t, uint16_t, uint32_t, uint64_t>();
CheckWideningConvertsToLargerTypes<
uint8_t, uint16_t, uint32_t, uint64_t>();
CheckWideningConvertsTo<float, double>(); CheckWideningConvertsTo<float, double>();
CheckWideningConvertsTo<uint16_t, float>(); CheckWideningConvertsTo<uint16_t, float>();
......
...@@ -201,8 +201,8 @@ is_uniform_range_valid(FloatType a, FloatType b) { ...@@ -201,8 +201,8 @@ is_uniform_range_valid(FloatType a, FloatType b) {
} }
template <typename IntType> template <typename IntType>
absl::enable_if_t<IsIntegral<IntType>::value, bool> absl::enable_if_t<IsIntegral<IntType>::value, bool> is_uniform_range_valid(
is_uniform_range_valid(IntType a, IntType b) { IntType a, IntType b) {
return a <= b; return a <= b;
} }
......
...@@ -75,7 +75,6 @@ inline U256 MultiplyU128ToU256(uint128 a, uint128 b) { ...@@ -75,7 +75,6 @@ inline U256 MultiplyU128ToU256(uint128 a, uint128 b) {
c00 + (c64a << 64) + (c64b << 64)}; c00 + (c64a << 64) + (c64b << 64)};
} }
template <> template <>
struct wide_multiply<uint128> { struct wide_multiply<uint128> {
using input_type = uint128; using input_type = uint128;
......
...@@ -148,8 +148,8 @@ double LogUniformIntChiSquaredTest::ChiSquaredTestImpl() { ...@@ -148,8 +148,8 @@ double LogUniformIntChiSquaredTest::ChiSquaredTestImpl() {
const auto bucket_index = [base_log, is_2, &param](int32_t x) { const auto bucket_index = [base_log, is_2, &param](int32_t x) {
uint64_t y = static_cast<uint64_t>(x) - param.min(); uint64_t y = static_cast<uint64_t>(x) - param.min();
return (y == 0) ? 0 return (y == 0) ? 0
: is_2 ? static_cast<int>(1 + std::log2(y)) : is_2 ? static_cast<int>(1 + std::log2(y))
: static_cast<int>(1 + std::log(y) * base_log); : static_cast<int>(1 + std::log(y) * base_log);
}; };
const int max_bucket = bucket_index(param.max()); // inclusive const int max_bucket = bucket_index(param.max()); // inclusive
const size_t trials = 15 + (max_bucket + 1) * 10; const size_t trials = 15 + (max_bucket + 1) * 10;
......
...@@ -106,7 +106,6 @@ TYPED_TEST(PoissonDistributionInterfaceTest, SerializeTest) { ...@@ -106,7 +106,6 @@ TYPED_TEST(PoissonDistributionInterfaceTest, SerializeTest) {
0.0), // denorm_max 0.0), // denorm_max
}; };
constexpr int kCount = 1000; constexpr int kCount = 1000;
absl::InsecureBitGen gen; absl::InsecureBitGen gen;
for (const double m : kParams) { for (const double m : kParams) {
......
...@@ -80,8 +80,7 @@ using SeedSeq = random_internal::SaltedSeedSeq<std::seed_seq>; ...@@ -80,8 +80,7 @@ using SeedSeq = random_internal::SaltedSeedSeq<std::seed_seq>;
// //
template <typename URBG> template <typename URBG>
SeedSeq CreateSeedSeqFrom(URBG* urbg) { SeedSeq CreateSeedSeqFrom(URBG* urbg) {
SeedSeq::result_type SeedSeq::result_type seed_material[random_internal::kEntropyBlocksNeeded];
seed_material[random_internal::kEntropyBlocksNeeded];
if (!random_internal::ReadSeedMaterialFromURBG( if (!random_internal::ReadSeedMaterialFromURBG(
urbg, absl::MakeSpan(seed_material))) { urbg, absl::MakeSpan(seed_material))) {
......
...@@ -114,8 +114,8 @@ TYPED_TEST(UniformIntDistributionTest, ParamSerializeTest) { ...@@ -114,8 +114,8 @@ TYPED_TEST(UniformIntDistributionTest, ParamSerializeTest) {
TYPED_TEST(UniformIntDistributionTest, ViolatesPreconditionsDeathTest) { TYPED_TEST(UniformIntDistributionTest, ViolatesPreconditionsDeathTest) {
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST
// Hi < Lo // Hi < Lo
EXPECT_DEBUG_DEATH({ absl::uniform_int_distribution<TypeParam> dist(10, 1); }, EXPECT_DEBUG_DEATH(
""); { absl::uniform_int_distribution<TypeParam> dist(10, 1); }, "");
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
#if defined(NDEBUG) #if defined(NDEBUG)
// opt-mode, for invalid parameters, will generate a garbage value, // opt-mode, for invalid parameters, will generate a garbage value,
......
...@@ -190,7 +190,7 @@ TYPED_TEST(UniformRealDistributionTest, ParamSerializeTest) { ...@@ -190,7 +190,7 @@ TYPED_TEST(UniformRealDistributionTest, ParamSerializeTest) {
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4756) // Constant arithmetic overflow. #pragma warning(disable : 4756) // Constant arithmetic overflow.
#endif #endif
TYPED_TEST(UniformRealDistributionTest, ViolatesPreconditionsDeathTest) { TYPED_TEST(UniformRealDistributionTest, ViolatesPreconditionsDeathTest) {
using DistributionType = absl::uniform_real_distribution<TypeParam>; using DistributionType = absl::uniform_real_distribution<TypeParam>;
......
...@@ -221,7 +221,7 @@ zipf_distribution<IntType>::operator()( ...@@ -221,7 +221,7 @@ zipf_distribution<IntType>::operator()(
const double v = uniform_double(g); const double v = uniform_double(g);
const double u = p.hxm_ + v * p.hx0_minus_hxm_; const double u = p.hxm_ + v * p.hx0_minus_hxm_;
const double x = p.hinv(u); const double x = p.hinv(u);
k = rint(x); // std::floor(x + 0.5); k = rint(x); // std::floor(x + 0.5);
if (k > static_cast<double>(p.k())) continue; // reject k > max_k if (k > static_cast<double>(p.k())) continue; // reject k > max_k
if (k - x <= p.s_) break; if (k - x <= p.s_) break;
const double h = p.h(k + 0.5); const double h = p.h(k + 0.5);
......
...@@ -176,15 +176,15 @@ class ZipfModel { ...@@ -176,15 +176,15 @@ class ZipfModel {
const double x = v_ + i; const double x = v_ + i;
// H(n, q-1) // H(n, q-1)
const double hnqm1 = const double hnqm1 = (q_ == 2.0) ? (1.0 / x)
(q_ == 2.0) ? (1.0 / x) : (q_ == 3.0) ? (1.0 / (x * x))
: (q_ == 3.0) ? (1.0 / (x * x)) : std::pow(x, -qm1); : std::pow(x, -qm1);
sum_hnq_m1 += hnqm1; sum_hnq_m1 += hnqm1;
// H(n, q) // H(n, q)
const double hnq = const double hnq = (q_ == 2.0) ? (1.0 / (x * x))
(q_ == 2.0) ? (1.0 / (x * x)) : (q_ == 3.0) ? (1.0 / (x * x * x))
: (q_ == 3.0) ? (1.0 / (x * x * x)) : std::pow(x, -q_); : std::pow(x, -q_);
sum_hnq_ += hnq; sum_hnq_ += hnq;
hnq_.push_back(hnq); hnq_.push_back(hnq);
if (i > 1000 && hnq <= 1e-10) { if (i > 1000 && hnq <= 1e-10) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment