NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
exponential.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31#include <random>
32
34#include "NumCpp/Core/Shape.hpp"
36
37namespace nc::random
38{
39 namespace detail
40 {
41 //============================================================================
42 // Method Description:
52 template<typename dtype, typename GeneratorType = std::mt19937>
53 dtype exponential(GeneratorType& generator, dtype inScaleValue = 1)
54 {
56
57 std::exponential_distribution<dtype> dist(inScaleValue);
58 return dist(generator);
59 }
60
61 //============================================================================
62 // Method Description:
74 template<typename dtype, typename GeneratorType = std::mt19937>
75 NdArray<dtype> exponential(GeneratorType& generator, const Shape& inShape, dtype inScaleValue = 1)
76 {
78
79 NdArray<dtype> returnArray(inShape);
80
81 std::exponential_distribution<dtype> dist(inScaleValue);
82
83 std::for_each(returnArray.begin(),
84 returnArray.end(),
85 [&generator, &dist](dtype& value) -> void { value = dist(generator); });
86
87 return returnArray;
88 }
89 } // namespace detail
90
91 //============================================================================
92 // Method Description:
101 template<typename dtype>
102 dtype exponential(dtype inScaleValue = 1)
103 {
104 return detail::exponential(generator_, inScaleValue);
105 }
106
107 //============================================================================
108 // Method Description:
119 template<typename dtype>
120 NdArray<dtype> exponential(const Shape& inShape, dtype inScaleValue = 1)
121 {
122 return detail::exponential(generator_, inShape, inScaleValue);
123 }
124} // namespace nc::random
#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 exponential(GeneratorType &generator, dtype inScaleValue=1)
Definition exponential.hpp:53
Definition Random/bernoulli.hpp:39
dtype exponential(dtype inScaleValue=1)
Definition exponential.hpp:102
std::mt19937_64 generator_
generator function
Definition generator.hpp:35