NumCpp  2.3.1
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 
32 #include "NumCpp/Core/Shape.hpp"
33 #include "NumCpp/NdArray.hpp"
35 
36 #include "boost/random/laplace_distribution.hpp"
37 
38 namespace nc
39 {
40  namespace random
41  {
42  //============================================================================
43  // Method Description:
53  template<typename dtype>
54  dtype laplace(dtype inLoc = 0, dtype inScale = 1)
55  {
57 
58  const boost::random::laplace_distribution<dtype> dist(inLoc, inScale);
59  return dist(generator_);
60  }
61 
62  //============================================================================
63  // Method Description:
75  template<typename dtype>
76  NdArray<dtype> laplace(const Shape& inShape, dtype inLoc = 0, dtype inScale = 1)
77  {
79 
80  NdArray<dtype> returnArray(inShape);
81 
82  const boost::random::laplace_distribution<dtype> dist(inLoc, inScale);
83 
84  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
85  [&dist](dtype& value) -> void
86  {
87  value = dist(generator_);
88  });
89 
90  return returnArray;
91  }
92  } // namespace random
93 } // namespace nc
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:1434
nc::random::laplace
dtype laplace(dtype inLoc=0, dtype inScale=1)
Definition: Random/laplace.hpp:54
Shape.hpp
nc
Definition: Coordinate.hpp:44
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1090