NumCpp  2.8.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
exponential.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <algorithm>
31 #include <random>
32 
34 #include "NumCpp/Core/Shape.hpp"
35 #include "NumCpp/NdArray.hpp"
37 
38 namespace nc
39 {
40  namespace random
41  {
42  namespace detail
43  {
44  //============================================================================
45  // Method Description:
55  template<typename dtype, typename GeneratorType = std::mt19937>
56  dtype exponential(GeneratorType& generator, dtype inScaleValue = 1)
57  {
59 
60  std::exponential_distribution<dtype> dist(inScaleValue);
61  return dist(generator);
62  }
63 
64  //============================================================================
65  // Method Description:
77  template<typename dtype, typename GeneratorType = std::mt19937>
78  NdArray<dtype> exponential(GeneratorType& generator, const Shape& inShape, dtype inScaleValue = 1)
79  {
81 
82  NdArray<dtype> returnArray(inShape);
83 
84  std::exponential_distribution<dtype> dist(inScaleValue);
85 
86  std::for_each(returnArray.begin(),
87  returnArray.end(),
88  [&generator, &dist](dtype& value) -> void { value = dist(generator); });
89 
90  return returnArray;
91  }
92  } // namespace detail
93 
94  //============================================================================
95  // Method Description:
104  template<typename dtype>
105  dtype exponential(dtype inScaleValue = 1)
106  {
107  return detail::exponential(generator_, inScaleValue);
108  }
109 
110  //============================================================================
111  // Method Description:
122  template<typename dtype>
123  NdArray<dtype> exponential(const Shape& inShape, dtype inScaleValue = 1)
124  {
125  return detail::exponential(generator_, inShape, inScaleValue);
126  }
127  } // namespace random
128 } // namespace nc
#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:1479
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
dtype exponential(GeneratorType &generator, dtype inScaleValue=1)
Definition: exponential.hpp:56
dtype exponential(dtype inScaleValue=1)
Definition: exponential.hpp:105
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:37
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:227
Definition: Coordinate.hpp:45