NumCpp  2.6.2
A Templatized Header Only C++ Implementation of the Python NumPy Library
Random/laplace.hpp
Go to the documentation of this file.
1 
28 #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:
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 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:1558
iterator begin() noexcept
Definition: NdArrayCore.hpp:1214
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
dtype laplace(dtype inLoc=0, dtype inScale=1)
Definition: Random/laplace.hpp:58
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