NumCpp  2.1.0
A C++ implementation of the Python Numpy library
exponential.hpp
Go to the documentation of this file.
1 #pragma once
30 
33 #include "NumCpp/Core/Shape.hpp"
34 #include "NumCpp/NdArray.hpp"
36 
37 #include "boost/random/exponential_distribution.hpp"
38 
39 namespace nc
40 {
41  namespace random
42  {
43  //============================================================================
44  // Method Description:
53  template<typename dtype>
54  dtype exponential(dtype inScaleValue = 1)
55  {
57 
58  const boost::random::exponential_distribution<dtype> dist(inScaleValue);
59  return dist(generator_);
60  }
61 
62  //============================================================================
63  // Method Description:
74  template<typename dtype>
75  NdArray<dtype> exponential(const Shape& inShape, dtype inScaleValue = 1)
76  {
78 
79  NdArray<dtype> returnArray(inShape);
80 
81  const boost::random::exponential_distribution<dtype> dist(inScaleValue);
82 
83  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
84  [&dist](dtype& value) -> void
85  {
86  value = dist(generator_);
87  });
88 
89  return returnArray;
90  }
91  } // namespace random
92 } // namespace nc
StaticAsserts.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
generator.hpp
nc::NdArray< dtype >
nc::random::exponential
dtype exponential(dtype inScaleValue=1)
Definition: exponential.hpp:54
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:214
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
Shape.hpp
nc
Definition: Coordinate.hpp:45
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:40
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091