• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright 2019 The Abseil Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      https://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17# ABSL random-number generation libraries.
18
19load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
20load(
21    "//absl:copts/configure_copts.bzl",
22    "ABSL_DEFAULT_COPTS",
23    "ABSL_DEFAULT_LINKOPTS",
24    "ABSL_TEST_COPTS",
25)
26
27package(default_visibility = ["//visibility:public"])
28
29licenses(["notice"])
30
31cc_library(
32    name = "random",
33    hdrs = ["random.h"],
34    copts = ABSL_DEFAULT_COPTS,
35    linkopts = ABSL_DEFAULT_LINKOPTS,
36    deps = [
37        ":distributions",
38        ":seed_sequences",
39        "//absl/random/internal:nonsecure_base",
40        "//absl/random/internal:pcg_engine",
41        "//absl/random/internal:pool_urbg",
42        "//absl/random/internal:randen_engine",
43    ],
44)
45
46cc_library(
47    name = "distributions",
48    srcs = [
49        "discrete_distribution.cc",
50        "gaussian_distribution.cc",
51    ],
52    hdrs = [
53        "bernoulli_distribution.h",
54        "beta_distribution.h",
55        "discrete_distribution.h",
56        "distribution_format_traits.h",
57        "distributions.h",
58        "exponential_distribution.h",
59        "gaussian_distribution.h",
60        "log_uniform_int_distribution.h",
61        "poisson_distribution.h",
62        "uniform_int_distribution.h",
63        "uniform_real_distribution.h",
64        "zipf_distribution.h",
65    ],
66    copts = ABSL_DEFAULT_COPTS,
67    linkopts = ABSL_DEFAULT_LINKOPTS,
68    deps = [
69        "//absl/base:base_internal",
70        "//absl/base:config",
71        "//absl/base:core_headers",
72        "//absl/meta:type_traits",
73        "//absl/random/internal:distributions",
74        "//absl/random/internal:fast_uniform_bits",
75        "//absl/random/internal:fastmath",
76        "//absl/random/internal:generate_real",
77        "//absl/random/internal:iostream_state_saver",
78        "//absl/random/internal:traits",
79        "//absl/random/internal:uniform_helper",
80        "//absl/random/internal:wide_multiply",
81        "//absl/strings",
82        "//absl/types:span",
83    ],
84)
85
86cc_library(
87    name = "seed_gen_exception",
88    srcs = ["seed_gen_exception.cc"],
89    hdrs = ["seed_gen_exception.h"],
90    copts = ABSL_DEFAULT_COPTS,
91    linkopts = ABSL_DEFAULT_LINKOPTS,
92    deps = ["//absl/base:config"],
93)
94
95cc_library(
96    name = "seed_sequences",
97    srcs = ["seed_sequences.cc"],
98    hdrs = [
99        "seed_sequences.h",
100    ],
101    copts = ABSL_DEFAULT_COPTS,
102    linkopts = ABSL_DEFAULT_LINKOPTS,
103    deps = [
104        ":seed_gen_exception",
105        "//absl/container:inlined_vector",
106        "//absl/random/internal:nonsecure_base",
107        "//absl/random/internal:pool_urbg",
108        "//absl/random/internal:salted_seed_seq",
109        "//absl/random/internal:seed_material",
110        "//absl/types:span",
111    ],
112)
113
114cc_library(
115    name = "bit_gen_ref",
116    hdrs = ["bit_gen_ref.h"],
117    copts = ABSL_DEFAULT_COPTS,
118    linkopts = ABSL_DEFAULT_LINKOPTS,
119    deps = [
120        "//absl/base:core_headers",
121        "//absl/meta:type_traits",
122        "//absl/random/internal:distribution_caller",
123        "//absl/random/internal:fast_uniform_bits",
124        "//absl/random/internal:mocking_bit_gen_base",
125    ],
126)
127
128cc_library(
129    name = "mock_distributions",
130    testonly = 1,
131    hdrs = ["mock_distributions.h"],
132    deps = [
133        ":distributions",
134        ":mocking_bit_gen",
135        "//absl/meta:type_traits",
136        "//absl/random/internal:mock_overload_set",
137        "@com_google_googletest//:gtest",
138    ],
139)
140
141cc_library(
142    name = "mocking_bit_gen",
143    testonly = 1,
144    srcs = [
145        "mocking_bit_gen.cc",
146    ],
147    hdrs = [
148        "mocking_bit_gen.h",
149    ],
150    linkopts = ABSL_DEFAULT_LINKOPTS,
151    deps = [
152        ":distributions",
153        "//absl/base:raw_logging_internal",
154        "//absl/container:flat_hash_map",
155        "//absl/meta:type_traits",
156        "//absl/random/internal:distribution_caller",
157        "//absl/random/internal:mocking_bit_gen_base",
158        "//absl/strings",
159        "//absl/types:span",
160        "//absl/types:variant",
161        "//absl/utility",
162        "@com_google_googletest//:gtest",
163    ],
164)
165
166cc_test(
167    name = "bernoulli_distribution_test",
168    size = "small",
169    timeout = "eternal",  # Android can take a very long time
170    srcs = ["bernoulli_distribution_test.cc"],
171    copts = ABSL_TEST_COPTS,
172    linkopts = ABSL_DEFAULT_LINKOPTS,
173    deps = [
174        ":distributions",
175        ":random",
176        "//absl/random/internal:sequence_urbg",
177        "@com_google_googletest//:gtest_main",
178    ],
179)
180
181cc_test(
182    name = "beta_distribution_test",
183    size = "small",
184    timeout = "eternal",  # Android can take a very long time
185    srcs = ["beta_distribution_test.cc"],
186    copts = ABSL_TEST_COPTS,
187    flaky = 1,
188    linkopts = ABSL_DEFAULT_LINKOPTS,
189    deps = [
190        ":distributions",
191        ":random",
192        "//absl/base:raw_logging_internal",
193        "//absl/random/internal:distribution_test_util",
194        "//absl/random/internal:sequence_urbg",
195        "//absl/strings",
196        "//absl/strings:str_format",
197        "@com_google_googletest//:gtest_main",
198    ],
199)
200
201cc_test(
202    name = "distributions_test",
203    size = "small",
204    srcs = [
205        "distributions_test.cc",
206    ],
207    copts = ABSL_TEST_COPTS,
208    linkopts = ABSL_DEFAULT_LINKOPTS,
209    deps = [
210        ":distributions",
211        ":random",
212        "//absl/random/internal:distribution_test_util",
213        "@com_google_googletest//:gtest_main",
214    ],
215)
216
217cc_test(
218    name = "generators_test",
219    size = "small",
220    srcs = ["generators_test.cc"],
221    copts = ABSL_TEST_COPTS,
222    linkopts = ABSL_DEFAULT_LINKOPTS,
223    deps = [
224        ":distributions",
225        ":random",
226        "@com_google_googletest//:gtest_main",
227    ],
228)
229
230cc_test(
231    name = "log_uniform_int_distribution_test",
232    size = "medium",
233    srcs = [
234        "log_uniform_int_distribution_test.cc",
235    ],
236    copts = ABSL_TEST_COPTS,
237    linkopts = ABSL_DEFAULT_LINKOPTS,
238    deps = [
239        ":distributions",
240        ":random",
241        "//absl/base:core_headers",
242        "//absl/base:raw_logging_internal",
243        "//absl/random/internal:distribution_test_util",
244        "//absl/random/internal:sequence_urbg",
245        "//absl/strings",
246        "//absl/strings:str_format",
247        "@com_google_googletest//:gtest_main",
248    ],
249)
250
251cc_test(
252    name = "discrete_distribution_test",
253    size = "medium",
254    srcs = [
255        "discrete_distribution_test.cc",
256    ],
257    copts = ABSL_TEST_COPTS,
258    linkopts = ABSL_DEFAULT_LINKOPTS,
259    deps = [
260        ":distributions",
261        ":random",
262        "//absl/base:raw_logging_internal",
263        "//absl/random/internal:distribution_test_util",
264        "//absl/random/internal:sequence_urbg",
265        "//absl/strings",
266        "@com_google_googletest//:gtest_main",
267    ],
268)
269
270cc_test(
271    name = "poisson_distribution_test",
272    size = "small",
273    timeout = "eternal",  # Android can take a very long time
274    srcs = [
275        "poisson_distribution_test.cc",
276    ],
277    copts = ABSL_TEST_COPTS,
278    linkopts = ABSL_DEFAULT_LINKOPTS,
279    tags = [
280        # Too Slow.
281        "no_test_android_arm",
282        "no_test_loonix",
283    ],
284    deps = [
285        ":distributions",
286        ":random",
287        "//absl/base:core_headers",
288        "//absl/base:raw_logging_internal",
289        "//absl/container:flat_hash_map",
290        "//absl/random/internal:distribution_test_util",
291        "//absl/random/internal:sequence_urbg",
292        "//absl/strings",
293        "//absl/strings:str_format",
294        "@com_google_googletest//:gtest_main",
295    ],
296)
297
298cc_test(
299    name = "exponential_distribution_test",
300    size = "small",
301    srcs = ["exponential_distribution_test.cc"],
302    copts = ABSL_TEST_COPTS,
303    linkopts = ABSL_DEFAULT_LINKOPTS,
304    deps = [
305        ":distributions",
306        ":random",
307        "//absl/base:core_headers",
308        "//absl/base:raw_logging_internal",
309        "//absl/random/internal:distribution_test_util",
310        "//absl/random/internal:sequence_urbg",
311        "//absl/strings",
312        "//absl/strings:str_format",
313        "@com_google_googletest//:gtest_main",
314    ],
315)
316
317cc_test(
318    name = "gaussian_distribution_test",
319    size = "small",
320    timeout = "eternal",  # Android can take a very long time
321    srcs = [
322        "gaussian_distribution_test.cc",
323    ],
324    copts = ABSL_TEST_COPTS,
325    linkopts = ABSL_DEFAULT_LINKOPTS,
326    deps = [
327        ":distributions",
328        ":random",
329        "//absl/base:core_headers",
330        "//absl/base:raw_logging_internal",
331        "//absl/random/internal:distribution_test_util",
332        "//absl/random/internal:sequence_urbg",
333        "//absl/strings",
334        "//absl/strings:str_format",
335        "@com_google_googletest//:gtest_main",
336    ],
337)
338
339cc_test(
340    name = "uniform_int_distribution_test",
341    size = "medium",
342    timeout = "long",
343    srcs = [
344        "uniform_int_distribution_test.cc",
345    ],
346    copts = ABSL_TEST_COPTS,
347    linkopts = ABSL_DEFAULT_LINKOPTS,
348    deps = [
349        ":distributions",
350        ":random",
351        "//absl/base:raw_logging_internal",
352        "//absl/random/internal:distribution_test_util",
353        "//absl/random/internal:sequence_urbg",
354        "//absl/strings",
355        "@com_google_googletest//:gtest_main",
356    ],
357)
358
359cc_test(
360    name = "uniform_real_distribution_test",
361    size = "medium",
362    srcs = [
363        "uniform_real_distribution_test.cc",
364    ],
365    copts = ABSL_TEST_COPTS,
366    linkopts = ABSL_DEFAULT_LINKOPTS,
367    tags = [
368        "no_test_android_arm",
369        "no_test_android_arm64",
370        "no_test_android_x86",
371    ],
372    deps = [
373        ":distributions",
374        ":random",
375        "//absl/base:raw_logging_internal",
376        "//absl/random/internal:distribution_test_util",
377        "//absl/random/internal:sequence_urbg",
378        "//absl/strings",
379        "@com_google_googletest//:gtest_main",
380    ],
381)
382
383cc_test(
384    name = "zipf_distribution_test",
385    size = "medium",
386    srcs = [
387        "zipf_distribution_test.cc",
388    ],
389    copts = ABSL_TEST_COPTS,
390    linkopts = ABSL_DEFAULT_LINKOPTS,
391    deps = [
392        ":distributions",
393        ":random",
394        "//absl/base:raw_logging_internal",
395        "//absl/random/internal:distribution_test_util",
396        "//absl/random/internal:sequence_urbg",
397        "//absl/strings",
398        "@com_google_googletest//:gtest_main",
399    ],
400)
401
402cc_test(
403    name = "bit_gen_ref_test",
404    size = "small",
405    srcs = ["bit_gen_ref_test.cc"],
406    copts = ABSL_TEST_COPTS,
407    linkopts = ABSL_DEFAULT_LINKOPTS,
408    deps = [
409        ":bit_gen_ref",
410        ":random",
411        "//absl/random/internal:sequence_urbg",
412        "@com_google_googletest//:gtest_main",
413    ],
414)
415
416cc_test(
417    name = "mocking_bit_gen_test",
418    size = "small",
419    srcs = ["mocking_bit_gen_test.cc"],
420    linkopts = ABSL_DEFAULT_LINKOPTS,
421    deps = [
422        ":bit_gen_ref",
423        ":mock_distributions",
424        ":mocking_bit_gen",
425        ":random",
426        "@com_google_googletest//:gtest_main",
427    ],
428)
429
430cc_test(
431    name = "mock_distributions_test",
432    size = "small",
433    srcs = ["mock_distributions_test.cc"],
434    deps = [
435        ":mock_distributions",
436        ":mocking_bit_gen",
437        ":random",
438        "@com_google_googletest//:gtest_main",
439    ],
440)
441
442cc_test(
443    name = "examples_test",
444    size = "small",
445    srcs = ["examples_test.cc"],
446    copts = ABSL_TEST_COPTS,
447    linkopts = ABSL_DEFAULT_LINKOPTS,
448    deps = [
449        ":random",
450        "@com_google_googletest//:gtest_main",
451    ],
452)
453
454cc_test(
455    name = "seed_sequences_test",
456    size = "small",
457    srcs = ["seed_sequences_test.cc"],
458    copts = ABSL_TEST_COPTS,
459    linkopts = ABSL_DEFAULT_LINKOPTS,
460    deps = [
461        ":random",
462        ":seed_sequences",
463        "//absl/random/internal:nonsecure_base",
464        "@com_google_googletest//:gtest_main",
465    ],
466)
467
468BENCHMARK_TAGS = [
469    "benchmark",
470    "no_test_android_arm",
471    "no_test_android_arm64",
472    "no_test_android_x86",
473    "no_test_darwin_x86_64",
474    "no_test_ios_x86_64",
475    "no_test_loonix",
476    "no_test_msvc_x64",
477    "no_test_wasm",
478]
479
480# Benchmarks for various methods / test utilities
481cc_binary(
482    name = "benchmarks",
483    testonly = 1,
484    srcs = [
485        "benchmarks.cc",
486    ],
487    copts = ABSL_TEST_COPTS,
488    linkopts = ABSL_DEFAULT_LINKOPTS,
489    tags = BENCHMARK_TAGS,
490    deps = [
491        ":distributions",
492        ":random",
493        ":seed_sequences",
494        "//absl/base:core_headers",
495        "//absl/meta:type_traits",
496        "//absl/random/internal:fast_uniform_bits",
497        "//absl/random/internal:randen_engine",
498        "@com_github_google_benchmark//:benchmark_main",
499    ],
500)
501