NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
extremeValue.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:
52  template<typename dtype>
53  dtype extremeValue(dtype inA = 1, dtype inB = 1)
54  {
56 
57  if (inA <= 0)
58  {
59  THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
60  }
61 
62  if (inB <= 0)
63  {
64  THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
65  }
66 
67  std::extreme_value_distribution<dtype> dist(inA, inB);
68  return dist(generator_);
69  }
70 
71  //============================================================================
72  // Method Description:
81  template<typename dtype>
82  NdArray<dtype> extremeValue(const Shape& inShape, dtype inA = 1, dtype inB = 1)
83  {
85 
86  if (inA <= 0)
87  {
88  THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
89  }
90 
91  if (inB <= 0)
92  {
93  THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
94  }
95 
96  NdArray<dtype> returnArray(inShape);
97 
98  std::extreme_value_distribution<dtype> dist(inA, inB);
99 
100  std::for_each(returnArray.begin(), returnArray.end(),
101  [&dist](dtype& value) -> void
102  {
103  value = dist(generator_);
104  });
105 
106  return returnArray;
107  }
108  } // namespace random
109 } // 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:1474
iterator begin() noexcept
Definition: NdArrayCore.hpp:1166
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
dtype extremeValue(dtype inA=1, dtype inB=1)
Definition: extremeValue.hpp:53
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:213
Definition: Coordinate.hpp:45