NumCpp  2.3.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
normal.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/normal_distribution.hpp"
38 
39 #include <string>
40 
41 namespace nc
42 {
43  namespace random
44  {
45  //============================================================================
46  // Method Description:
56  template<typename dtype>
57  dtype normal(dtype inMean = 0, dtype inSigma = 1)
58  {
60 
61  if (inSigma <= 0)
62  {
63  THROW_INVALID_ARGUMENT_ERROR("input sigma must be greater than zero.");
64  }
65 
66  boost::random::normal_distribution<dtype> dist(inMean, inSigma);
67  return dist(generator_);
68  }
69 
70  //============================================================================
71  // Method Description:
83  template<typename dtype>
84  NdArray<dtype> normal(const Shape& inShape, dtype inMean = 0, dtype inSigma = 1)
85  {
87 
88  if (inSigma <= 0)
89  {
90  THROW_INVALID_ARGUMENT_ERROR("input sigma must be greater than zero.");
91  }
92 
93  NdArray<dtype> returnArray(inShape);
94 
95  boost::random::normal_distribution<dtype> dist(inMean, inSigma);
96 
97  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
98  [&dist](dtype& value) -> void
99  {
100  value = dist(generator_);
101  });
102 
103  return returnArray;
104  }
105  } // namespace random
106 } // namespace nc
StaticAsserts.hpp
nc::random::normal
dtype normal(dtype inMean=0, dtype inSigma=1)
Definition: normal.hpp:57
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