/src/llvm-project/libcxx/test/libcxx/fuzzing/random.pass.cpp
Line | Count | Source |
1 | | //===----------------------------------------------------------------------===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | // UNSUPPORTED: c++03, c++11 |
10 | | |
11 | | #include <cassert> |
12 | | #include <cmath> |
13 | | #include <cstddef> |
14 | | #include <cstdint> |
15 | | #include <cstring> |
16 | | #include <random> |
17 | | #include <type_traits> |
18 | | #include <vector> |
19 | | |
20 | | #include "fuzz.h" |
21 | | |
22 | | template <class IntT> |
23 | 2.31k | std::vector<IntT> GetValues(const std::uint8_t *data, std::size_t size) { |
24 | 2.31k | std::vector<IntT> result; |
25 | 43.9M | while (size >= sizeof(IntT)) { |
26 | 43.9M | IntT tmp; |
27 | 43.9M | std::memcpy(&tmp, data, sizeof(IntT)); |
28 | 43.9M | size -= sizeof(IntT); |
29 | 43.9M | data += sizeof(IntT); |
30 | 43.9M | result.push_back(tmp); |
31 | 43.9M | } |
32 | 2.31k | return result; |
33 | 2.31k | } std::__1::vector<double, std::__1::allocator<double> > GetValues<double>(unsigned char const*, unsigned long) Line | Count | Source | 23 | 1.32k | std::vector<IntT> GetValues(const std::uint8_t *data, std::size_t size) { | 24 | 1.32k | std::vector<IntT> result; | 25 | 17.5M | while (size >= sizeof(IntT)) { | 26 | 17.5M | IntT tmp; | 27 | 17.5M | std::memcpy(&tmp, data, sizeof(IntT)); | 28 | 17.5M | size -= sizeof(IntT); | 29 | 17.5M | data += sizeof(IntT); | 30 | 17.5M | result.push_back(tmp); | 31 | 17.5M | } | 32 | 1.32k | return result; | 33 | 1.32k | } |
std::__1::vector<float, std::__1::allocator<float> > GetValues<float>(unsigned char const*, unsigned long) Line | Count | Source | 23 | 993 | std::vector<IntT> GetValues(const std::uint8_t *data, std::size_t size) { | 24 | 993 | std::vector<IntT> result; | 25 | 26.3M | while (size >= sizeof(IntT)) { | 26 | 26.3M | IntT tmp; | 27 | 26.3M | std::memcpy(&tmp, data, sizeof(IntT)); | 28 | 26.3M | size -= sizeof(IntT); | 29 | 26.3M | data += sizeof(IntT); | 30 | 26.3M | result.push_back(tmp); | 31 | 26.3M | } | 32 | 993 | return result; | 33 | 993 | } |
|
34 | | |
35 | | template <class Dist> |
36 | | struct ParamTypeHelper { |
37 | | using ParamT = typename Dist::param_type; |
38 | | using ResultT = typename Dist::result_type; |
39 | | static_assert(std::is_same<ResultT, typename ParamT::distribution_type::result_type>::value, ""); |
40 | | |
41 | 5.29k | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { |
42 | 5.29k | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; |
43 | 5.29k | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; |
44 | 5.29k | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); |
45 | 5.29k | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); |
46 | 5.29k | } ParamTypeHelper<std::__1::uniform_int_distribution<short> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::uniform_real_distribution<float> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::binomial_distribution<short> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::negative_binomial_distribution<short> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::exponential_distribution<float> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::gamma_distribution<float> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::weibull_distribution<float> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::extreme_value_distribution<float> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::normal_distribution<float> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::chi_squared_distribution<float> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::cauchy_distribution<float> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::fisher_f_distribution<float> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::student_t_distribution<float> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::discrete_distribution<short> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::piecewise_constant_distribution<float> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
ParamTypeHelper<std::__1::piecewise_linear_distribution<float> >::Create(unsigned char const*, unsigned long, bool&) Line | Count | Source | 41 | 331 | static ParamT Create(const std::uint8_t* data, std::size_t size, bool &OK) { | 42 | 331 | constexpr bool select_vector_result = std::is_constructible<ParamT, ResultT*, ResultT*, ResultT*>::value; | 43 | 331 | constexpr bool select_vector_double = std::is_constructible<ParamT, double*, double*>::value; | 44 | 331 | constexpr int selector = select_vector_result ? 0 : (select_vector_double ? 1 : 2); | 45 | 331 | return DispatchAndCreate(std::integral_constant<int, selector>{}, data, size, OK); | 46 | 331 | } |
|
47 | | |
48 | | // Vector result |
49 | 662 | static ParamT DispatchAndCreate(std::integral_constant<int, 0>, const std::uint8_t *data, std::size_t size, bool &OK) { |
50 | 662 | auto Input = GetValues<ResultT>(data, size); |
51 | 662 | OK = false; |
52 | 662 | if (Input.size() < 10) |
53 | 260 | return ParamT{}; |
54 | 402 | OK = true; |
55 | 402 | auto Beg = Input.begin(); |
56 | 402 | auto End = Input.end(); |
57 | 402 | auto Mid = Beg + ((End - Beg) / 2); |
58 | | |
59 | 402 | assert(Mid - Beg <= (End - Mid)); |
60 | 402 | ParamT p(Beg, Mid, Mid); |
61 | 402 | return p; |
62 | 402 | } ParamTypeHelper<std::__1::piecewise_constant_distribution<float> >::DispatchAndCreate(std::__1::integral_constant<int, 0>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 49 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 0>, const std::uint8_t *data, std::size_t size, bool &OK) { | 50 | 331 | auto Input = GetValues<ResultT>(data, size); | 51 | 331 | OK = false; | 52 | 331 | if (Input.size() < 10) | 53 | 130 | return ParamT{}; | 54 | 201 | OK = true; | 55 | 201 | auto Beg = Input.begin(); | 56 | 201 | auto End = Input.end(); | 57 | 201 | auto Mid = Beg + ((End - Beg) / 2); | 58 | | | 59 | 201 | assert(Mid - Beg <= (End - Mid)); | 60 | 201 | ParamT p(Beg, Mid, Mid); | 61 | 201 | return p; | 62 | 201 | } |
ParamTypeHelper<std::__1::piecewise_linear_distribution<float> >::DispatchAndCreate(std::__1::integral_constant<int, 0>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 49 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 0>, const std::uint8_t *data, std::size_t size, bool &OK) { | 50 | 331 | auto Input = GetValues<ResultT>(data, size); | 51 | 331 | OK = false; | 52 | 331 | if (Input.size() < 10) | 53 | 130 | return ParamT{}; | 54 | 201 | OK = true; | 55 | 201 | auto Beg = Input.begin(); | 56 | 201 | auto End = Input.end(); | 57 | 201 | auto Mid = Beg + ((End - Beg) / 2); | 58 | | | 59 | 201 | assert(Mid - Beg <= (End - Mid)); | 60 | 201 | ParamT p(Beg, Mid, Mid); | 61 | 201 | return p; | 62 | 201 | } |
|
63 | | |
64 | | // Vector double |
65 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 1>, const std::uint8_t *data, std::size_t size, bool &OK) { |
66 | 331 | auto Input = GetValues<double>(data, size); |
67 | | |
68 | 331 | OK = true; |
69 | 331 | auto Beg = Input.begin(); |
70 | 331 | auto End = Input.end(); |
71 | | |
72 | 331 | ParamT p(Beg, End); |
73 | 331 | return p; |
74 | 331 | } |
75 | | |
76 | | // Default |
77 | 4.30k | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { |
78 | 4.30k | OK = false; |
79 | 4.30k | if (size < sizeof(ParamT)) |
80 | 681 | return ParamT{}; |
81 | 3.62k | OK = true; |
82 | 3.62k | ParamT input; |
83 | 3.62k | std::memcpy(&input, data, sizeof(ParamT)); |
84 | 3.62k | return input; |
85 | 4.30k | } ParamTypeHelper<std::__1::uniform_int_distribution<short> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 3 | return ParamT{}; | 81 | 328 | OK = true; | 82 | 328 | ParamT input; | 83 | 328 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 328 | return input; | 85 | 331 | } |
ParamTypeHelper<std::__1::uniform_real_distribution<float> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 64 | return ParamT{}; | 81 | 267 | OK = true; | 82 | 267 | ParamT input; | 83 | 267 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 267 | return input; | 85 | 331 | } |
ParamTypeHelper<std::__1::binomial_distribution<short> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 130 | return ParamT{}; | 81 | 201 | OK = true; | 82 | 201 | ParamT input; | 83 | 201 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 201 | return input; | 85 | 331 | } |
ParamTypeHelper<std::__1::negative_binomial_distribution<short> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 91 | return ParamT{}; | 81 | 240 | OK = true; | 82 | 240 | ParamT input; | 83 | 240 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 240 | return input; | 85 | 331 | } |
ParamTypeHelper<std::__1::exponential_distribution<float> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 3 | return ParamT{}; | 81 | 328 | OK = true; | 82 | 328 | ParamT input; | 83 | 328 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 328 | return input; | 85 | 331 | } |
ParamTypeHelper<std::__1::gamma_distribution<float> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 64 | return ParamT{}; | 81 | 267 | OK = true; | 82 | 267 | ParamT input; | 83 | 267 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 267 | return input; | 85 | 331 | } |
ParamTypeHelper<std::__1::weibull_distribution<float> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 64 | return ParamT{}; | 81 | 267 | OK = true; | 82 | 267 | ParamT input; | 83 | 267 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 267 | return input; | 85 | 331 | } |
ParamTypeHelper<std::__1::extreme_value_distribution<float> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 64 | return ParamT{}; | 81 | 267 | OK = true; | 82 | 267 | ParamT input; | 83 | 267 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 267 | return input; | 85 | 331 | } |
ParamTypeHelper<std::__1::normal_distribution<float> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 64 | return ParamT{}; | 81 | 267 | OK = true; | 82 | 267 | ParamT input; | 83 | 267 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 267 | return input; | 85 | 331 | } |
ParamTypeHelper<std::__1::chi_squared_distribution<float> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 3 | return ParamT{}; | 81 | 328 | OK = true; | 82 | 328 | ParamT input; | 83 | 328 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 328 | return input; | 85 | 331 | } |
ParamTypeHelper<std::__1::cauchy_distribution<float> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 64 | return ParamT{}; | 81 | 267 | OK = true; | 82 | 267 | ParamT input; | 83 | 267 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 267 | return input; | 85 | 331 | } |
ParamTypeHelper<std::__1::fisher_f_distribution<float> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 64 | return ParamT{}; | 81 | 267 | OK = true; | 82 | 267 | ParamT input; | 83 | 267 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 267 | return input; | 85 | 331 | } |
ParamTypeHelper<std::__1::student_t_distribution<float> >::DispatchAndCreate(std::__1::integral_constant<int, 2>, unsigned char const*, unsigned long, bool&) Line | Count | Source | 77 | 331 | static ParamT DispatchAndCreate(std::integral_constant<int, 2>, const std::uint8_t *data, std::size_t size, bool &OK) { | 78 | 331 | OK = false; | 79 | 331 | if (size < sizeof(ParamT)) | 80 | 3 | return ParamT{}; | 81 | 328 | OK = true; | 82 | 328 | ParamT input; | 83 | 328 | std::memcpy(&input, data, sizeof(ParamT)); | 84 | 328 | return input; | 85 | 331 | } |
|
86 | | }; |
87 | | |
88 | | template <class IntT> |
89 | | struct ParamTypeHelper<std::poisson_distribution<IntT>> { |
90 | | using Dist = std::poisson_distribution<IntT>; |
91 | | using ParamT = typename Dist::param_type; |
92 | | using ResultT = typename Dist::result_type; |
93 | | |
94 | 331 | static ParamT Create(const std::uint8_t *data, std::size_t size, bool& OK) { |
95 | 331 | OK = false; |
96 | 331 | auto vals = GetValues<double>(data, size); |
97 | 331 | if (vals.empty() || std::isnan(vals[0]) || std::isnan(std::abs(vals[0])) || vals[0] < 0) |
98 | 95 | return ParamT{}; |
99 | 236 | OK = true; |
100 | 236 | return ParamT{vals[0]}; |
101 | 331 | } |
102 | | }; |
103 | | |
104 | | template <class IntT> |
105 | | struct ParamTypeHelper<std::geometric_distribution<IntT>> { |
106 | | using Dist = std::geometric_distribution<IntT>; |
107 | | using ParamT = typename Dist::param_type; |
108 | | using ResultT = typename Dist::result_type; |
109 | | |
110 | 331 | static ParamT Create(const std::uint8_t *data, std::size_t size, bool& OK) { |
111 | 331 | OK = false; |
112 | 331 | auto vals = GetValues<double>(data, size); |
113 | 331 | if (vals.empty() || std::isnan(vals[0]) || vals[0] < 0 ) |
114 | 95 | return ParamT{}; |
115 | 236 | OK = true; |
116 | 236 | return ParamT{vals[0]}; |
117 | 331 | } |
118 | | }; |
119 | | |
120 | | template <class IntT> |
121 | | struct ParamTypeHelper<std::lognormal_distribution<IntT>> { |
122 | | using Dist = std::lognormal_distribution<IntT>; |
123 | | using ParamT = typename Dist::param_type; |
124 | | using ResultT = typename Dist::result_type; |
125 | | |
126 | 331 | static ParamT Create(const std::uint8_t *data, std::size_t size, bool& OK) { |
127 | 331 | OK = false; |
128 | 331 | auto vals = GetValues<ResultT>(data, size); |
129 | 331 | if (vals.size() < 2 ) |
130 | 64 | return ParamT{}; |
131 | 267 | OK = true; |
132 | 267 | return ParamT{vals[0], vals[1]}; |
133 | 331 | } |
134 | | }; |
135 | | |
136 | | template <> |
137 | | struct ParamTypeHelper<std::bernoulli_distribution> { |
138 | | using Dist = std::bernoulli_distribution; |
139 | | using ParamT = Dist::param_type; |
140 | | using ResultT = Dist::result_type; |
141 | | |
142 | 331 | static ParamT Create(const std::uint8_t *data, std::size_t size, bool& OK) { |
143 | 331 | OK = false; |
144 | 331 | auto vals = GetValues<double>(data, size); |
145 | 331 | if (vals.empty()) |
146 | 64 | return ParamT{}; |
147 | 267 | OK = true; |
148 | 267 | return ParamT{vals[0]}; |
149 | 331 | } |
150 | | }; |
151 | | |
152 | | template <class Distribution> |
153 | 6.62k | int helper(const std::uint8_t *data, std::size_t size) { |
154 | 6.62k | std::mt19937 engine; |
155 | 6.62k | using ParamT = typename Distribution::param_type; |
156 | 6.62k | bool OK; |
157 | 6.62k | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); |
158 | 6.62k | if (!OK) |
159 | 1.25k | return 0; |
160 | 5.36k | Distribution d(p); |
161 | 5.36k | volatile auto res = d(engine); |
162 | 5.36k | if (std::isnan(res)) { |
163 | | // FIXME(llvm.org/PR44289): |
164 | | // Investigate why these distributions are returning NaN and decide |
165 | | // if that's what we want them to be doing. |
166 | | // |
167 | | // Make this assert false (or return non-zero). |
168 | 479 | return 0; |
169 | 479 | } |
170 | 4.88k | return 0; |
171 | 5.36k | } int helper<std::__1::uniform_int_distribution<short> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 3 | return 0; | 160 | 328 | Distribution d(p); | 161 | 328 | volatile auto res = d(engine); | 162 | 328 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 328 | return 0; | 171 | 328 | } |
int helper<std::__1::uniform_real_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 64 | return 0; | 160 | 267 | Distribution d(p); | 161 | 267 | volatile auto res = d(engine); | 162 | 267 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 267 | return 0; | 171 | 267 | } |
int helper<std::__1::bernoulli_distribution>(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 64 | return 0; | 160 | 267 | Distribution d(p); | 161 | 267 | volatile auto res = d(engine); | 162 | 267 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 267 | return 0; | 171 | 267 | } |
int helper<std::__1::poisson_distribution<short> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 95 | return 0; | 160 | 236 | Distribution d(p); | 161 | 236 | volatile auto res = d(engine); | 162 | 236 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 236 | return 0; | 171 | 236 | } |
int helper<std::__1::geometric_distribution<short> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 95 | return 0; | 160 | 236 | Distribution d(p); | 161 | 236 | volatile auto res = d(engine); | 162 | 236 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 236 | return 0; | 171 | 236 | } |
int helper<std::__1::binomial_distribution<short> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 130 | return 0; | 160 | 201 | Distribution d(p); | 161 | 201 | volatile auto res = d(engine); | 162 | 201 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 201 | return 0; | 171 | 201 | } |
int helper<std::__1::negative_binomial_distribution<short> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 91 | return 0; | 160 | 240 | Distribution d(p); | 161 | 240 | volatile auto res = d(engine); | 162 | 240 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 240 | return 0; | 171 | 240 | } |
int helper<std::__1::exponential_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 3 | return 0; | 160 | 328 | Distribution d(p); | 161 | 328 | volatile auto res = d(engine); | 162 | 328 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 328 | return 0; | 171 | 328 | } |
int helper<std::__1::gamma_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 64 | return 0; | 160 | 267 | Distribution d(p); | 161 | 267 | volatile auto res = d(engine); | 162 | 267 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 267 | return 0; | 171 | 267 | } |
int helper<std::__1::weibull_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 64 | return 0; | 160 | 267 | Distribution d(p); | 161 | 267 | volatile auto res = d(engine); | 162 | 267 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 38 | return 0; | 169 | 38 | } | 170 | 229 | return 0; | 171 | 267 | } |
int helper<std::__1::extreme_value_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 64 | return 0; | 160 | 267 | Distribution d(p); | 161 | 267 | volatile auto res = d(engine); | 162 | 267 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 267 | return 0; | 171 | 267 | } |
int helper<std::__1::normal_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 64 | return 0; | 160 | 267 | Distribution d(p); | 161 | 267 | volatile auto res = d(engine); | 162 | 267 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 267 | return 0; | 171 | 267 | } |
int helper<std::__1::lognormal_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 64 | return 0; | 160 | 267 | Distribution d(p); | 161 | 267 | volatile auto res = d(engine); | 162 | 267 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 267 | return 0; | 171 | 267 | } |
int helper<std::__1::chi_squared_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 3 | return 0; | 160 | 328 | Distribution d(p); | 161 | 328 | volatile auto res = d(engine); | 162 | 328 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 328 | return 0; | 171 | 328 | } |
int helper<std::__1::cauchy_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 64 | return 0; | 160 | 267 | Distribution d(p); | 161 | 267 | volatile auto res = d(engine); | 162 | 267 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 267 | return 0; | 171 | 267 | } |
int helper<std::__1::fisher_f_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 64 | return 0; | 160 | 267 | Distribution d(p); | 161 | 267 | volatile auto res = d(engine); | 162 | 267 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 104 | return 0; | 169 | 104 | } | 170 | 163 | return 0; | 171 | 267 | } |
int helper<std::__1::student_t_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 3 | return 0; | 160 | 328 | Distribution d(p); | 161 | 328 | volatile auto res = d(engine); | 162 | 328 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 80 | return 0; | 169 | 80 | } | 170 | 248 | return 0; | 171 | 328 | } |
int helper<std::__1::discrete_distribution<short> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 0 | return 0; | 160 | 331 | Distribution d(p); | 161 | 331 | volatile auto res = d(engine); | 162 | 331 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 0 | return 0; | 169 | 0 | } | 170 | 331 | return 0; | 171 | 331 | } |
int helper<std::__1::piecewise_constant_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 130 | return 0; | 160 | 201 | Distribution d(p); | 161 | 201 | volatile auto res = d(engine); | 162 | 201 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 91 | return 0; | 169 | 91 | } | 170 | 110 | return 0; | 171 | 201 | } |
int helper<std::__1::piecewise_linear_distribution<float> >(unsigned char const*, unsigned long) Line | Count | Source | 153 | 331 | int helper(const std::uint8_t *data, std::size_t size) { | 154 | 331 | std::mt19937 engine; | 155 | 331 | using ParamT = typename Distribution::param_type; | 156 | 331 | bool OK; | 157 | 331 | ParamT p = ParamTypeHelper<Distribution>::Create(data, size, OK); | 158 | 331 | if (!OK) | 159 | 130 | return 0; | 160 | 201 | Distribution d(p); | 161 | 201 | volatile auto res = d(engine); | 162 | 201 | if (std::isnan(res)) { | 163 | | // FIXME(llvm.org/PR44289): | 164 | | // Investigate why these distributions are returning NaN and decide | 165 | | // if that's what we want them to be doing. | 166 | | // | 167 | | // Make this assert false (or return non-zero). | 168 | 166 | return 0; | 169 | 166 | } | 170 | 35 | return 0; | 171 | 201 | } |
|
172 | | |
173 | 331 | extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *data, std::size_t size) { |
174 | 331 | return helper<std::uniform_int_distribution<std::int16_t>>(data, size) || |
175 | 331 | helper<std::uniform_real_distribution<float>>(data, size) || |
176 | 331 | helper<std::bernoulli_distribution>(data, size) || |
177 | 331 | helper<std::poisson_distribution<std::int16_t>>(data, size) || |
178 | 331 | helper<std::geometric_distribution<std::int16_t>>(data, size) || |
179 | 331 | helper<std::binomial_distribution<std::int16_t>>(data, size) || |
180 | 331 | helper<std::negative_binomial_distribution<std::int16_t>>(data, size) || |
181 | 331 | helper<std::exponential_distribution<float>>(data, size) || |
182 | 331 | helper<std::gamma_distribution<float>>(data, size) || |
183 | 331 | helper<std::weibull_distribution<float>>(data, size) || |
184 | 331 | helper<std::extreme_value_distribution<float>>(data, size) || |
185 | 331 | helper<std::normal_distribution<float>>(data, size) || |
186 | 331 | helper<std::lognormal_distribution<float>>(data, size) || |
187 | 331 | helper<std::chi_squared_distribution<float>>(data, size) || |
188 | 331 | helper<std::cauchy_distribution<float>>(data, size) || |
189 | 331 | helper<std::fisher_f_distribution<float>>(data, size) || |
190 | 331 | helper<std::student_t_distribution<float>>(data, size) || |
191 | 331 | helper<std::discrete_distribution<std::int16_t>>(data, size) || |
192 | 331 | helper<std::piecewise_constant_distribution<float>>(data, size) || |
193 | 331 | helper<std::piecewise_linear_distribution<float>>(data, size); |
194 | 331 | } |