NumCpp  2.9.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
weibull.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <algorithm>
31 #include <random>
32 #include <string>
33 
36 #include "NumCpp/Core/Shape.hpp"
37 #include "NumCpp/NdArray.hpp"
39 
40 namespace nc
41 {
42  namespace random
43  {
44  namespace detail
45  {
46  // Method Description:
57  template<typename dtype, typename GeneratorType = std::mt19937>
58  dtype weibull(GeneratorType& generator, dtype inA = 1, dtype inB = 1)
59  {
61 
62  if (inA <= 0)
63  {
64  THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
65  }
66 
67  if (inB <= 0)
68  {
69  THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
70  }
71 
72  std::weibull_distribution<dtype> dist(inA, inB);
73  return dist(generator);
74  }
75 
76  //============================================================================
77  // Method Description:
90  template<typename dtype, typename GeneratorType = std::mt19937>
91  NdArray<dtype> weibull(GeneratorType& generator, const Shape& inShape, dtype inA = 1, dtype inB = 1)
92  {
94 
95  if (inA <= 0)
96  {
97  THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
98  }
99 
100  if (inB <= 0)
101  {
102  THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
103  }
104 
105  NdArray<dtype> returnArray(inShape);
106 
107  std::weibull_distribution<dtype> dist(inA, inB);
108 
109  std::for_each(returnArray.begin(),
110  returnArray.end(),
111  [&generator, &dist](dtype& value) -> void { value = dist(generator); });
112 
113  return returnArray;
114  }
115  } // namespace detail
116 
117  //============================================================================
118  // Method Description:
128  template<typename dtype>
129  dtype weibull(dtype inA = 1, dtype inB = 1)
130  {
131  return detail::weibull(generator_, inA, inB);
132  }
133 
134  //============================================================================
135  // Method Description:
147  template<typename dtype>
148  NdArray<dtype> weibull(const Shape& inShape, dtype inA = 1, dtype inB = 1)
149  {
150  return detail::weibull(generator_, inShape, inA, inB);
151  }
152  } // namespace random
153 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
iterator end() noexcept
Definition: NdArrayCore.hpp:1479
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
dtype weibull(GeneratorType &generator, dtype inA=1, dtype inB=1)
Definition: weibull.hpp:58
dtype weibull(dtype inA=1, dtype inB=1)
Definition: weibull.hpp:129
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:37
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:227
Definition: Coordinate.hpp:45