about summary refs log tree commit diff
path: root/absl/random/distributions.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-01-07T14·56-0800
committerDerek Mauro <dmauro@google.com>2020-01-07T19·50-0500
commit63ee2f8877915a3565c29707dba8fe4d7822596a (patch)
tree2fbadda72047a8441c181a0adf1215cec0155036 /absl/random/distributions.h
parenta048203a881f11f4b7b8df5fb563aec85522f8db (diff)
Export of internal Abseil changes
--
7f6c15aadc4d97e217dd446518dbb4fdc86b36a3 by Derek Mauro <dmauro@google.com>:

Upgrade GCC automated testing to use GCC 9.2 and Cmake 3.16.2

PiperOrigin-RevId: 288488783

--
a978cee848d3cf65b0826c981bfd81022fc36660 by Abseil Team <absl-team@google.com>:

Removing formatting traits that were only used internally. ON_CALL/EXPECT_CALL do a sufficient job here.

PiperOrigin-RevId: 288386509

--
fdec6f40293d5883220f1f0ea1261f7c5b60a66e by Derek Mauro <dmauro@google.com>:

Upgrade MacOS tests to use Bazel 2.0.0

PiperOrigin-RevId: 288373298

--
465865c4123e9481ab50ea0527e92b39519704dd by Derek Mauro <dmauro@google.com>:

Changes to support GCC 9
 * Fix several -Wredundant-move warnings
 * Remove FlatHashMap.Any test, which basically doesn't work on any platform
   any more (see https://cplusplus.github.io/LWG/lwg-active.html#3121)
 * Fix a constant sign-compare warning
 * Conditionally compile out the PoisonHash test which doesn't build

PiperOrigin-RevId: 288360204

--
57c4bb07fc58e7dd2a04f3c45027aab5ecaccf25 by Andy Soffer <asoffer@google.com>:

Deflaking MockingBitGen test. Because MockingBitGen can return random values,
it is inherently flaky. For log-unifrom, 2040 is a common enough value that
tests failed unreasonably frequently. Replacing it with a significantly larger
value so as to be much less common. 50000 is a good choice because it is (tied for) the least likely to occur randomly from this distribution, but is still in the distribution.

PiperOrigin-RevId: 288360112

--
86f38e4109899d972de353b1c556c018cfe37956 by Matt Calabrese <calabrese@google.com>:

Remove construction tests for the internal `CompressedTuple<std::any>` instantiation. This was not guaranteed to work for the reasons that `std::tuple<std::any>` copy construction does not actually work by standard specification (some implementations introduce workarounds for this). In GCC9, `CompressedTuple<std::any>` and `std::tuple<std::any>` both fail for the same reasons, and a proper "fix" requires updating `std::any`, which is out of our control.

PiperOrigin-RevId: 288351977
GitOrigin-RevId: 7f6c15aadc4d97e217dd446518dbb4fdc86b36a3
Change-Id: I5d5c62bd297dc0ff1f2970ff076bb5cd088a7e4c
Diffstat (limited to 'absl/random/distributions.h')
-rw-r--r--absl/random/distributions.h41
1 files changed, 27 insertions, 14 deletions
diff --git a/absl/random/distributions.h b/absl/random/distributions.h
index 7abdfa8f202a..c1fb66501593 100644
--- a/absl/random/distributions.h
+++ b/absl/random/distributions.h
@@ -55,6 +55,7 @@
 #include "absl/base/internal/inline_variable.h"
 #include "absl/random/bernoulli_distribution.h"
 #include "absl/random/beta_distribution.h"
+#include "absl/random/distribution_format_traits.h"
 #include "absl/random/exponential_distribution.h"
 #include "absl/random/gaussian_distribution.h"
 #include "absl/random/internal/distributions.h"  // IWYU pragma: export
@@ -125,13 +126,14 @@ Uniform(TagType tag,
         R lo, R hi) {
   using gen_t = absl::decay_t<URBG>;
   using distribution_t = random_internal::UniformDistributionWrapper<R>;
+  using format_t = random_internal::DistributionFormatTraits<distribution_t>;
 
   auto a = random_internal::uniform_lower_bound(tag, lo, hi);
   auto b = random_internal::uniform_upper_bound(tag, lo, hi);
   if (a > b) return a;
 
   return random_internal::DistributionCaller<gen_t>::template Call<
-      distribution_t>(&urbg, tag, lo, hi);
+      distribution_t, format_t>(&urbg, tag, lo, hi);
 }
 
 // absl::Uniform<T>(bitgen, lo, hi)
@@ -144,6 +146,7 @@ Uniform(URBG&& urbg,  // NOLINT(runtime/references)
         R lo, R hi) {
   using gen_t = absl::decay_t<URBG>;
   using distribution_t = random_internal::UniformDistributionWrapper<R>;
+  using format_t = random_internal::DistributionFormatTraits<distribution_t>;
 
   constexpr auto tag = absl::IntervalClosedOpen;
   auto a = random_internal::uniform_lower_bound(tag, lo, hi);
@@ -151,7 +154,7 @@ Uniform(URBG&& urbg,  // NOLINT(runtime/references)
   if (a > b) return a;
 
   return random_internal::DistributionCaller<gen_t>::template Call<
-      distribution_t>(&urbg, lo, hi);
+      distribution_t, format_t>(&urbg, lo, hi);
 }
 
 // absl::Uniform(tag, bitgen, lo, hi)
@@ -169,14 +172,15 @@ Uniform(TagType tag,
   using gen_t = absl::decay_t<URBG>;
   using return_t = typename random_internal::uniform_inferred_return_t<A, B>;
   using distribution_t = random_internal::UniformDistributionWrapper<return_t>;
+  using format_t = random_internal::DistributionFormatTraits<distribution_t>;
 
   auto a = random_internal::uniform_lower_bound<return_t>(tag, lo, hi);
   auto b = random_internal::uniform_upper_bound<return_t>(tag, lo, hi);
   if (a > b) return a;
 
   return random_internal::DistributionCaller<gen_t>::template Call<
-      distribution_t>(&urbg, tag, static_cast<return_t>(lo),
-                      static_cast<return_t>(hi));
+      distribution_t, format_t>(&urbg, tag, static_cast<return_t>(lo),
+                                static_cast<return_t>(hi));
 }
 
 // absl::Uniform(bitgen, lo, hi)
@@ -192,6 +196,7 @@ Uniform(URBG&& urbg,  // NOLINT(runtime/references)
   using gen_t = absl::decay_t<URBG>;
   using return_t = typename random_internal::uniform_inferred_return_t<A, B>;
   using distribution_t = random_internal::UniformDistributionWrapper<return_t>;
+  using format_t = random_internal::DistributionFormatTraits<distribution_t>;
 
   constexpr auto tag = absl::IntervalClosedOpen;
   auto a = random_internal::uniform_lower_bound<return_t>(tag, lo, hi);
@@ -199,8 +204,8 @@ Uniform(URBG&& urbg,  // NOLINT(runtime/references)
   if (a > b) return a;
 
   return random_internal::DistributionCaller<gen_t>::template Call<
-      distribution_t>(&urbg, static_cast<return_t>(lo),
-                      static_cast<return_t>(hi));
+      distribution_t, format_t>(&urbg, static_cast<return_t>(lo),
+                                static_cast<return_t>(hi));
 }
 
 // absl::Uniform<unsigned T>(bitgen)
@@ -212,9 +217,10 @@ typename absl::enable_if_t<!std::is_signed<R>::value, R>  //
 Uniform(URBG&& urbg) {  // NOLINT(runtime/references)
   using gen_t = absl::decay_t<URBG>;
   using distribution_t = random_internal::UniformDistributionWrapper<R>;
+  using format_t = random_internal::DistributionFormatTraits<distribution_t>;
 
   return random_internal::DistributionCaller<gen_t>::template Call<
-      distribution_t>(&urbg);
+      distribution_t, format_t>(&urbg);
 }
 
 // -----------------------------------------------------------------------------
@@ -242,9 +248,10 @@ bool Bernoulli(URBG&& urbg,  // NOLINT(runtime/references)
                double p) {
   using gen_t = absl::decay_t<URBG>;
   using distribution_t = absl::bernoulli_distribution;
+  using format_t = random_internal::DistributionFormatTraits<distribution_t>;
 
   return random_internal::DistributionCaller<gen_t>::template Call<
-      distribution_t>(&urbg, p);
+      distribution_t, format_t>(&urbg, p);
 }
 
 // -----------------------------------------------------------------------------
@@ -274,9 +281,10 @@ RealType Beta(URBG&& urbg,  // NOLINT(runtime/references)
 
   using gen_t = absl::decay_t<URBG>;
   using distribution_t = typename absl::beta_distribution<RealType>;
+  using format_t = random_internal::DistributionFormatTraits<distribution_t>;
 
   return random_internal::DistributionCaller<gen_t>::template Call<
-      distribution_t>(&urbg, alpha, beta);
+      distribution_t, format_t>(&urbg, alpha, beta);
 }
 
 // -----------------------------------------------------------------------------
@@ -306,9 +314,10 @@ RealType Exponential(URBG&& urbg,  // NOLINT(runtime/references)
 
   using gen_t = absl::decay_t<URBG>;
   using distribution_t = typename absl::exponential_distribution<RealType>;
+  using format_t = random_internal::DistributionFormatTraits<distribution_t>;
 
   return random_internal::DistributionCaller<gen_t>::template Call<
-      distribution_t>(&urbg, lambda);
+      distribution_t, format_t>(&urbg, lambda);
 }
 
 // -----------------------------------------------------------------------------
@@ -337,9 +346,10 @@ RealType Gaussian(URBG&& urbg,  // NOLINT(runtime/references)
 
   using gen_t = absl::decay_t<URBG>;
   using distribution_t = typename absl::gaussian_distribution<RealType>;
+  using format_t = random_internal::DistributionFormatTraits<distribution_t>;
 
   return random_internal::DistributionCaller<gen_t>::template Call<
-      distribution_t>(&urbg, mean, stddev);
+      distribution_t, format_t>(&urbg, mean, stddev);
 }
 
 // -----------------------------------------------------------------------------
@@ -379,9 +389,10 @@ IntType LogUniform(URBG&& urbg,  // NOLINT(runtime/references)
 
   using gen_t = absl::decay_t<URBG>;
   using distribution_t = typename absl::log_uniform_int_distribution<IntType>;
+  using format_t = random_internal::DistributionFormatTraits<distribution_t>;
 
   return random_internal::DistributionCaller<gen_t>::template Call<
-      distribution_t>(&urbg, lo, hi, base);
+      distribution_t, format_t>(&urbg, lo, hi, base);
 }
 
 // -----------------------------------------------------------------------------
@@ -409,9 +420,10 @@ IntType Poisson(URBG&& urbg,  // NOLINT(runtime/references)
 
   using gen_t = absl::decay_t<URBG>;
   using distribution_t = typename absl::poisson_distribution<IntType>;
+  using format_t = random_internal::DistributionFormatTraits<distribution_t>;
 
   return random_internal::DistributionCaller<gen_t>::template Call<
-      distribution_t>(&urbg, mean);
+      distribution_t, format_t>(&urbg, mean);
 }
 
 // -----------------------------------------------------------------------------
@@ -441,9 +453,10 @@ IntType Zipf(URBG&& urbg,  // NOLINT(runtime/references)
 
   using gen_t = absl::decay_t<URBG>;
   using distribution_t = typename absl::zipf_distribution<IntType>;
+  using format_t = random_internal::DistributionFormatTraits<distribution_t>;
 
   return random_internal::DistributionCaller<gen_t>::template Call<
-      distribution_t>(&urbg, hi, q, v);
+      distribution_t, format_t>(&urbg, hi, q, v);
 }
 
 ABSL_NAMESPACE_END