NumCpp  2.3.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
extremeValue.hpp
Go to the documentation of this file.
1 #pragma once
29 
33 #include "NumCpp/Core/Shape.hpp"
34 #include "NumCpp/NdArray.hpp"
36 
37 #include <boost/random/extreme_value_distribution.hpp>
38 
39 #include <string>
40 
41 namespace nc
42 {
43  namespace random
44  {
45  //============================================================================
46  // Method Description:
54  template<typename dtype>
55  dtype extremeValue(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  const boost::random::extreme_value_distribution<dtype> dist(inA, inB);
70  return dist(generator_);
71  }
72 
73  //============================================================================
74  // Method Description:
84  template<typename dtype>
85  NdArray<dtype> extremeValue(const Shape& inShape, dtype inA = 1, dtype inB = 1)
86  {
88 
89  if (inA <= 0)
90  {
91  THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
92  }
93 
94  if (inB <= 0)
95  {
96  THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
97  }
98 
99  NdArray<dtype> returnArray(inShape);
100 
101  const boost::random::extreme_value_distribution<dtype> dist(inA, inB);
102 
103  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
104  [&dist](dtype& value) -> void
105  {
106  value = dist(generator_);
107  });
108 
109  return returnArray;
110  }
111  } // namespace random
112 } // namespace nc
StaticAsserts.hpp
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
generator.hpp
nc::random::extremeValue
dtype extremeValue(dtype inA=1, dtype inB=1)
Definition: extremeValue.hpp:55
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:1434
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
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1090