NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Random/gamma.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31#include <random>
32#include <string>
33
36#include "NumCpp/Core/Shape.hpp"
37#include "NumCpp/NdArray.hpp"
39
40namespace nc::random
41{
42 namespace detail
43 {
44 //============================================================================
45 // Method Description:
56 template<typename dtype, typename GeneratorType = std::mt19937>
58 {
60
61 if (inGammaShape <= 0)
62 {
63 THROW_INVALID_ARGUMENT_ERROR("input gamma shape should be greater than zero.");
64 }
65
66 if (inScaleValue <= 0)
67 {
68 THROW_INVALID_ARGUMENT_ERROR("input scale should be greater than zero.");
69 }
70
71 std::gamma_distribution<dtype> dist(inGammaShape, inScaleValue);
72 return dist(generator);
73 }
74
75 //============================================================================
76 // Method Description:
89 template<typename dtype, typename GeneratorType = std::mt19937>
91 {
93
94 if (inGammaShape <= 0)
95 {
96 THROW_INVALID_ARGUMENT_ERROR("input gamma shape should be greater than zero.");
97 }
98
99 if (inScaleValue <= 0)
100 {
101 THROW_INVALID_ARGUMENT_ERROR("input scale should be greater than zero.");
102 }
103
105
106 std::gamma_distribution<dtype> dist(inGammaShape, inScaleValue);
107
108 std::for_each(returnArray.begin(),
109 returnArray.end(),
110 [&generator, &dist](dtype& value) -> void { value = dist(generator); });
111
112 return returnArray;
113 }
114 } // namespace detail
115
116 //============================================================================
117 // Method Description:
127 template<typename dtype>
132
133 //============================================================================
134 // Method Description:
146 template<typename dtype>
151} // 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:139
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
dtype gamma(GeneratorType &generator, dtype inGammaShape, dtype inScaleValue=1)
Definition Random/gamma.hpp:57
Definition Random/bernoulli.hpp:41
dtype gamma(dtype inGammaShape, dtype inScaleValue=1)
Definition Random/gamma.hpp:128
std::mt19937_64 generator_
generator function
Definition generator.hpp:35
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59