NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
weibull.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31#include <random>
32
35#include "NumCpp/Core/Shape.hpp"
36#include "NumCpp/NdArray.hpp"
38
39namespace nc::random
40{
41 namespace detail
42 {
43 // Method Description:
54 template<typename dtype, typename GeneratorType = std::mt19937>
55 dtype weibull(GeneratorType& generator, dtype inA = 1, dtype inB = 1)
56 {
58
59 if (inA <= 0)
60 {
61 THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
62 }
63
64 if (inB <= 0)
65 {
66 THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
67 }
68
69 std::weibull_distribution<dtype> dist(inA, inB);
70 return dist(generator);
71 }
72
73 //============================================================================
74 // Method Description:
87 template<typename dtype, typename GeneratorType = std::mt19937>
88 NdArray<dtype> weibull(GeneratorType& generator, const Shape& inShape, dtype inA = 1, dtype inB = 1)
89 {
91
92 if (inA <= 0)
93 {
94 THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
95 }
96
97 if (inB <= 0)
98 {
99 THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
100 }
101
102 NdArray<dtype> returnArray(inShape);
103
104 std::weibull_distribution<dtype> dist(inA, inB);
105
106 std::for_each(returnArray.begin(),
107 returnArray.end(),
108 [&generator, &dist](dtype& value) -> void { value = dist(generator); });
109
110 return returnArray;
111 }
112 } // namespace detail
113
114 //============================================================================
115 // Method Description:
125 template<typename dtype>
126 dtype weibull(dtype inA = 1, dtype inB = 1)
127 {
128 return detail::weibull(generator_, inA, inB);
129 }
130
131 //============================================================================
132 // Method Description:
144 template<typename dtype>
145 NdArray<dtype> weibull(const Shape& inShape, dtype inA = 1, dtype inB = 1)
146 {
147 return detail::weibull(generator_, inShape, inA, inB);
148 }
149} // namespace nc::random
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
iterator end() noexcept
Definition NdArrayCore.hpp:1619
iterator begin() noexcept
Definition NdArrayCore.hpp:1311
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
Definition Random/bernoulli.hpp:41
dtype weibull(GeneratorType &generator, dtype inA=1, dtype inB=1)
Definition weibull.hpp:55
Definition Random/bernoulli.hpp:39
dtype weibull(dtype inA=1, dtype inB=1)
Definition weibull.hpp:126
std::mt19937_64 generator_
generator function
Definition generator.hpp:35