NumCpp  2.7.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 NUMCPP_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:
56  template<typename dtype>
57  dtype laplace(dtype inLoc = 0, dtype inScale = 1)
58  {
60 
61  boost::random::laplace_distribution<dtype> dist(inLoc, inScale);
62  return dist(generator_);
63  }
64 
65  //============================================================================
66  // Method Description:
78  template<typename dtype>
79  NdArray<dtype> laplace(const Shape& inShape, dtype inLoc = 0, dtype inScale = 1)
80  {
82 
83  NdArray<dtype> returnArray(inShape);
84 
85  boost::random::laplace_distribution<dtype> dist(inLoc, inScale);
86 
87  std::for_each(returnArray.begin(), returnArray.end(),
88  [&dist](dtype& value) -> void
89  {
90  value = dist(generator_);
91  });
92 
93  return returnArray;
94  }
95  } // namespace random
96 } // namespace nc
97 
98 #endif // #ifndef NUMCPP_NO_USE_BOOST
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
iterator end() noexcept
Definition: NdArrayCore.hpp:1474
iterator begin() noexcept
Definition: NdArrayCore.hpp:1166
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
dtype laplace(dtype inLoc=0, dtype inScale=1)
Definition: Random/laplace.hpp:57
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:213
Definition: Coordinate.hpp:45