NumCpp  1.0
A C++ implementation of the Python Numpy library
poisson.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
32 #include "NumCpp/Core/Shape.hpp"
37 
38 #include "boost/random/poisson_distribution.hpp"
39 
40 #include <string>
41 
42 namespace nc
43 {
44  namespace random
45  {
46  //============================================================================
47  // Method Description:
56  template<typename dtype>
57  dtype poisson(double inMean = 1)
58  {
60 
61  if (inMean <= 0)
62  {
63  THROW_INVALID_ARGUMENT_ERROR("input mean must be greater than zero.");
64  }
65 
66  const boost::random::poisson_distribution<dtype, double> dist(inMean);
67  return dist(generator_);
68  }
69 
70  //============================================================================
71  // Method Description:
82  template<typename dtype>
83  NdArray<dtype> poisson(const Shape& inShape, double inMean = 1)
84  {
86 
87  if (inMean <= 0)
88  {
89  THROW_INVALID_ARGUMENT_ERROR("input mean must be greater than zero.");
90  }
91 
92  NdArray<dtype> returnArray(inShape);
93 
94  const boost::random::poisson_distribution<dtype, double> dist(inMean);
95 
96  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
97  [&dist](dtype& value) -> void
98  {
99  value = dist(generator_);
100  });
101 
102  return returnArray;
103  }
104  }
105 }
StaticAsserts.hpp
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f) noexcept
Definition: StlAlgorithms.hpp:214
generator.hpp
nc::NdArray< dtype >
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
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091
nc::random::poisson
dtype poisson(double inMean=1)
Definition: poisson.hpp:57