NumCpp  2.4.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:
53  template<typename dtype>
54  dtype extremeValue(dtype inA = 1, dtype inB = 1)
55  {
57 
58  if (inA <= 0)
59  {
60  THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
61  }
62 
63  if (inB <= 0)
64  {
65  THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
66  }
67 
68  std::extreme_value_distribution<dtype> dist(inA, inB);
69  return dist(generator_);
70  }
71 
72  //============================================================================
73  // Method Description:
83  template<typename dtype>
84  NdArray<dtype> extremeValue(const Shape& inShape, dtype inA = 1, dtype inB = 1)
85  {
87 
88  if (inA <= 0)
89  {
90  THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
91  }
92 
93  if (inB <= 0)
94  {
95  THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
96  }
97 
98  NdArray<dtype> returnArray(inShape);
99 
100  std::extreme_value_distribution<dtype> dist(inA, inB);
101 
102  std::for_each(returnArray.begin(), returnArray.end(),
103  [&dist](dtype& value) -> void
104  {
105  value = dist(generator_);
106  });
107 
108  return returnArray;
109  }
110  } // namespace random
111 } // 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:54
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::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1087