NumCpp  2.1.0
A C++ implementation of the Python Numpy library
Random/laplace.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/laplace_distribution.hpp"
38 
39 namespace nc
40 {
41  namespace random
42  {
43  //============================================================================
44  // Method Description:
54  template<typename dtype>
55  dtype laplace(dtype inLoc = 0, dtype inScale = 1)
56  {
58 
59  const boost::random::laplace_distribution<dtype> dist(inLoc, inScale);
60  return dist(generator_);
61  }
62 
63  //============================================================================
64  // Method Description:
76  template<typename dtype>
77  NdArray<dtype> laplace(const Shape& inShape, dtype inLoc = 0, dtype inScale = 1)
78  {
80 
81  NdArray<dtype> returnArray(inShape);
82 
83  const boost::random::laplace_distribution<dtype> dist(inLoc, inScale);
84 
85  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
86  [&dist](dtype& value) -> void
87  {
88  value = dist(generator_);
89  });
90 
91  return returnArray;
92  }
93  } // namespace random
94 } // namespace nc
StaticAsserts.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
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
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
nc::random::laplace
dtype laplace(dtype inLoc=0, dtype inScale=1)
Definition: Random/laplace.hpp:55
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