NumCpp  2.3.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
poisson.hpp
Go to the documentation of this file.
1 #pragma once
29 
33 #include "NumCpp/Core/Shape.hpp"
34 #include "NumCpp/NdArray.hpp"
36 
37 #include "boost/random/poisson_distribution.hpp"
38 
39 #include <string>
40 
41 namespace nc
42 {
43  namespace random
44  {
45  //============================================================================
46  // Method Description:
55  template<typename dtype>
56  dtype poisson(double inMean = 1)
57  {
59 
60  if (inMean <= 0)
61  {
62  THROW_INVALID_ARGUMENT_ERROR("input mean must be greater than zero.");
63  }
64 
65  const boost::random::poisson_distribution<dtype, double> dist(inMean);
66  return dist(generator_);
67  }
68 
69  //============================================================================
70  // Method Description:
81  template<typename dtype>
82  NdArray<dtype> poisson(const Shape& inShape, double inMean = 1)
83  {
85 
86  if (inMean <= 0)
87  {
88  THROW_INVALID_ARGUMENT_ERROR("input mean must be greater than zero.");
89  }
90 
91  NdArray<dtype> returnArray(inShape);
92 
93  const boost::random::poisson_distribution<dtype, double> dist(inMean);
94 
95  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
96  [&dist](dtype& value) -> void
97  {
98  value = dist(generator_);
99  });
100 
101  return returnArray;
102  }
103  } // namespace random
104 } // namespace nc
StaticAsserts.hpp
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
generator.hpp
nc::NdArray< dtype >
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:213
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:40
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1434
Shape.hpp
nc
Definition: Coordinate.hpp:44
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1090
nc::random::poisson
dtype poisson(double inMean=1)
Definition: poisson.hpp:56