NumCpp  2.1.0
A C++ implementation of the Python Numpy library
randN.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/normal_distribution.hpp"
38 
39 namespace nc
40 {
41  namespace random
42  {
43  //============================================================================
44  // Method Description:
51  template<typename dtype>
52  dtype randN()
53  {
54  STATIC_ASSERT_FLOAT(dtype);
55 
56  boost::random::normal_distribution<dtype> dist;
57  return dist(generator_);
58  }
59 
60  //============================================================================
61  // Method Description:
72  template<typename dtype>
73  NdArray<dtype> randN(const Shape& inShape)
74  {
75  STATIC_ASSERT_FLOAT(dtype);
76 
77  NdArray<dtype> returnArray(inShape);
78 
79  boost::random::normal_distribution<dtype> dist;
80 
81  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
82  [&dist](dtype& value) -> void
83  {
84  value = dist(generator_);
85  });
86 
87  return returnArray;
88  }
89  } // namespace random
90 } // namespace nc
StaticAsserts.hpp
generator.hpp
nc::NdArray< dtype >
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
STATIC_ASSERT_FLOAT
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:44
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
nc::random::randN
dtype randN()
Definition: randN.hpp:52
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