NumCpp  2.13.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
cauchy.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31#include <random>
32#include <string>
33
36#include "NumCpp/Core/Shape.hpp"
37#include "NumCpp/NdArray.hpp"
39
40namespace nc::random
41{
42 namespace detail
43 {
44 //============================================================================
45 // Method Description:
54 template<typename dtype, typename GeneratorType = std::mt19937>
56 {
58
59 if (inSigma <= 0)
60 {
61 THROW_INVALID_ARGUMENT_ERROR("input sigma must be greater than zero.");
62 }
63
64 std::cauchy_distribution<dtype> dist(inMean, inSigma);
65 return dist(generator);
66 }
67
68 //============================================================================
69 // Method Description:
80 template<typename dtype, typename GeneratorType = std::mt19937>
82 {
84
85 if (inSigma <= 0)
86 {
87 THROW_INVALID_ARGUMENT_ERROR("input sigma must be greater than zero.");
88 }
89
91
92 std::cauchy_distribution<dtype> dist(inMean, inSigma);
93
94 std::for_each(returnArray.begin(),
95 returnArray.end(),
96 [&generator, &dist](dtype& value) -> void { value = dist(generator); });
97
98 return returnArray;
99 }
100 } // namespace detail
101
102 //============================================================================
103 // Method Description:
111 template<typename dtype>
116
117 //============================================================================
118 // Method Description:
128 template<typename dtype>
133} // namespace nc::random
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
dtype cauchy(GeneratorType &generator, dtype inMean=0, dtype inSigma=1)
Definition cauchy.hpp:55
Definition Random/bernoulli.hpp:41
std::mt19937_64 generator_
generator function
Definition generator.hpp:35
dtype cauchy(dtype inMean=0, dtype inSigma=1)
Definition cauchy.hpp:112
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59