NumCpp  2.4.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 
32 #include "NumCpp/Core/Shape.hpp"
33 #include "NumCpp/NdArray.hpp"
35 
36 #include <algorithm>
37 #include <random>
38 #include <string>
39 
40 namespace nc
41 {
42  namespace random
43  {
44  //============================================================================
45  // Method Description:
55  template<typename dtype>
56  dtype weibull(dtype inA = 1, dtype inB = 1)
57  {
59 
60  if (inA <= 0)
61  {
62  THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
63  }
64 
65  if (inB <= 0)
66  {
67  THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
68  }
69 
70  std::weibull_distribution<dtype> dist(inA, inB);
71  return dist(generator_);
72  }
73 
74  //============================================================================
75  // Method Description:
87  template<typename dtype>
88  NdArray<dtype> weibull(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(), returnArray.end(),
107  [&dist](dtype& value) -> void
108  {
109  value = dist(generator_);
110  });
111 
112  return returnArray;
113  }
114  } // namespace random
115 } // namespace nc
StaticAsserts.hpp
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
generator.hpp
nc::NdArray< dtype >
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:213
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:40
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1431
Shape.hpp
nc
Definition: Coordinate.hpp:44
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
nc::random::weibull
dtype weibull(dtype inA=1, dtype inB=1)
Definition: weibull.hpp:56
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1087