NumCpp  1.0
A C++ implementation of the Python Numpy library
cauchy.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
32 #include "NumCpp/Core/Shape.hpp"
37 
38 #include "boost/random/cauchy_distribution.hpp"
39 
40 #include <string>
41 
42 namespace nc
43 {
44  namespace random
45  {
46  //============================================================================
47  // Method Description:
55  template<typename dtype>
56  dtype cauchy(dtype inMean = 0, dtype inSigma = 1)
57  {
59 
60  if (inSigma <= 0)
61  {
62  THROW_INVALID_ARGUMENT_ERROR("input sigma must be greater than zero.");
63  }
64 
65  boost::random::cauchy_distribution<dtype> dist(inMean, inSigma);
66  return dist(generator_);
67  }
68 
69  //============================================================================
70  // Method Description:
80  template<typename dtype>
81  NdArray<dtype> cauchy(const Shape& inShape, dtype inMean = 0, dtype inSigma = 1)
82  {
84 
85  if (inSigma <= 0)
86  {
87  THROW_INVALID_ARGUMENT_ERROR("input sigma must be greater than zero.");
88  }
89 
90  NdArray<dtype> returnArray(inShape);
91 
92  boost::random::cauchy_distribution<dtype> dist(inMean, inSigma);
93 
94  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
95  [&dist](dtype& value) -> void
96  {
97  value = dist(generator_);
98  });
99 
100  return returnArray;
101  }
102  }
103 }
StaticAsserts.hpp
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f) noexcept
Definition: StlAlgorithms.hpp:214
generator.hpp
nc::NdArray< dtype >
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
Shape.hpp
nc::random::cauchy
dtype cauchy(dtype inMean=0, dtype inSigma=1)
Definition: cauchy.hpp:56
nc
Definition: Coordinate.hpp:45
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:40
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091