NumCpp  2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Random/laplace.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #ifndef NO_USE_BOOST
31 
33 #include "NumCpp/Core/Shape.hpp"
34 #include "NumCpp/NdArray.hpp"
36 
37 #include "boost/random/laplace_distribution.hpp"
38 
39 #include <algorithm>
40 
41 namespace nc
42 {
43  namespace random
44  {
45  //============================================================================
46  // Method Description:
57  template<typename dtype>
58  dtype laplace(dtype inLoc = 0, dtype inScale = 1)
59  {
61 
62  boost::random::laplace_distribution<dtype> dist(inLoc, inScale);
63  return dist(generator_);
64  }
65 
66  //============================================================================
67  // Method Description:
80  template<typename dtype>
81  NdArray<dtype> laplace(const Shape& inShape, dtype inLoc = 0, dtype inScale = 1)
82  {
84 
85  NdArray<dtype> returnArray(inShape);
86 
87  boost::random::laplace_distribution<dtype> dist(inLoc, inScale);
88 
89  std::for_each(returnArray.begin(), returnArray.end(),
90  [&dist](dtype& value) -> void
91  {
92  value = dist(generator_);
93  });
94 
95  return returnArray;
96  }
97  } // namespace random
98 } // namespace nc
99 
100 #endif // #ifndef NO_USE_BOOST
StaticAsserts.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:1431
nc::random::laplace
dtype laplace(dtype inLoc=0, dtype inScale=1)
Definition: Random/laplace.hpp:58
Shape.hpp
nc
Definition: Coordinate.hpp:44
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1087