NumCpp  2.7.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 
32 #include "NumCpp/Core/Shape.hpp"
33 #include "NumCpp/NdArray.hpp"
35 
36 #include <algorithm>
37 #include <random>
38 #include <string>
39 
40 namespace nc
41 {
42  namespace random
43  {
44  //============================================================================
45  // Method Description:
52  template<typename dtype>
53  dtype cauchy(dtype inMean = 0, dtype inSigma = 1)
54  {
56 
57  if (inSigma <= 0)
58  {
59  THROW_INVALID_ARGUMENT_ERROR("input sigma must be greater than zero.");
60  }
61 
62  std::cauchy_distribution<dtype> dist(inMean, inSigma);
63  return dist(generator_);
64  }
65 
66  //============================================================================
67  // Method Description:
76  template<typename dtype>
77  NdArray<dtype> cauchy(const Shape& inShape, dtype inMean = 0, dtype inSigma = 1)
78  {
80 
81  if (inSigma <= 0)
82  {
83  THROW_INVALID_ARGUMENT_ERROR("input sigma must be greater than zero.");
84  }
85 
86  NdArray<dtype> returnArray(inShape);
87 
88  std::cauchy_distribution<dtype> dist(inMean, inSigma);
89 
90  std::for_each(returnArray.begin(), returnArray.end(),
91  [&dist](dtype& value) -> void
92  {
93  value = dist(generator_);
94  });
95 
96  return returnArray;
97  }
98  } // namespace random
99 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#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:1474
iterator begin() noexcept
Definition: NdArrayCore.hpp:1166
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
dtype cauchy(dtype inMean=0, dtype inSigma=1)
Definition: cauchy.hpp:53
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:213
Definition: Coordinate.hpp:45