NumCpp  2.3.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
cauchy.hpp
Go to the documentation of this file.
1 #pragma once
29 
33 #include "NumCpp/Core/Shape.hpp"
34 #include "NumCpp/NdArray.hpp"
36 
37 #include "boost/random/cauchy_distribution.hpp"
38 
39 #include <string>
40 
41 namespace nc
42 {
43  namespace random
44  {
45  //============================================================================
46  // Method Description:
54  template<typename dtype>
55  dtype cauchy(dtype inMean = 0, dtype inSigma = 1)
56  {
58 
59  if (inSigma <= 0)
60  {
61  THROW_INVALID_ARGUMENT_ERROR("input sigma must be greater than zero.");
62  }
63 
64  boost::random::cauchy_distribution<dtype> dist(inMean, inSigma);
65  return dist(generator_);
66  }
67 
68  //============================================================================
69  // Method Description:
79  template<typename dtype>
80  NdArray<dtype> cauchy(const Shape& inShape, dtype inMean = 0, dtype inSigma = 1)
81  {
83 
84  if (inSigma <= 0)
85  {
86  THROW_INVALID_ARGUMENT_ERROR("input sigma must be greater than zero.");
87  }
88 
89  NdArray<dtype> returnArray(inShape);
90 
91  boost::random::cauchy_distribution<dtype> dist(inMean, inSigma);
92 
93  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
94  [&dist](dtype& value) -> void
95  {
96  value = dist(generator_);
97  });
98 
99  return returnArray;
100  }
101  } // namespace random
102 } // namespace nc
StaticAsserts.hpp
Error.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
Shape.hpp
nc::random::cauchy
dtype cauchy(dtype inMean=0, dtype inSigma=1)
Definition: cauchy.hpp:55
nc
Definition: Coordinate.hpp:44
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1090