NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
extremeValue.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31#include <random>
32
35#include "NumCpp/Core/Shape.hpp"
36#include "NumCpp/NdArray.hpp"
38
39namespace nc::random
40{
41 namespace detail
42 {
43 //============================================================================
44 // Method Description:
52 template<typename dtype, typename GeneratorType = std::mt19937>
53 dtype extremeValue(GeneratorType& generator, 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:
82 template<typename dtype, typename GeneratorType = std::mt19937>
83 NdArray<dtype> extremeValue(GeneratorType& generator, const Shape& inShape, dtype inA = 1, dtype inB = 1)
84 {
86
87 if (inA <= 0)
88 {
89 THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
90 }
91
92 if (inB <= 0)
93 {
94 THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
95 }
96
97 NdArray<dtype> returnArray(inShape);
98
99 std::extreme_value_distribution<dtype> dist(inA, inB);
100
101 std::for_each(returnArray.begin(),
102 returnArray.end(),
103 [&generator, &dist](dtype& value) -> void { value = dist(generator); });
104
105 return returnArray;
106 }
107 } // namespace detail
108
109 //============================================================================
110 // Method Description:
117 template<typename dtype>
118 dtype extremeValue(dtype inA = 1, dtype inB = 1)
119 {
120 return detail::extremeValue<dtype>(generator_, inA, inB);
121 }
122
123 //============================================================================
124 // Method Description:
133 template<typename dtype>
134 NdArray<dtype> extremeValue(const Shape& inShape, dtype inA = 1, dtype inB = 1)
135 {
136 return detail::extremeValue<dtype>(generator_, inShape, inA, inB);
137 }
138} // namespace nc::random
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
iterator end() noexcept
Definition NdArrayCore.hpp:1619
iterator begin() noexcept
Definition NdArrayCore.hpp:1311
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
Definition Random/bernoulli.hpp:41
dtype extremeValue(GeneratorType &generator, dtype inA=1, dtype inB=1)
Definition extremeValue.hpp:53
Definition Random/bernoulli.hpp:39
dtype extremeValue(dtype inA=1, dtype inB=1)
Definition extremeValue.hpp:118
std::mt19937_64 generator_
generator function
Definition generator.hpp:35