NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
f.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31#include <random>
32
35#include "NumCpp/Core/Shape.hpp"
36#include "NumCpp/NdArray.hpp"
38
39namespace nc::random
40{
41 namespace detail
42 {
43 //============================================================================
44 // Method Description:
54 template<typename dtype, typename GeneratorType = std::mt19937>
55 dtype f(GeneratorType& generator, dtype inDofN, dtype inDofD)
56 {
58
59 if (inDofN <= 0)
60 {
61 THROW_INVALID_ARGUMENT_ERROR("numerator degrees of freedom should be greater than zero.");
62 }
63
64 if (inDofD <= 0)
65 {
66 THROW_INVALID_ARGUMENT_ERROR("denominator degrees of freedom should be greater than zero.");
67 }
68
69 std::fisher_f_distribution<dtype> dist(inDofN, inDofD);
70 return dist(generator);
71 }
72
73 //============================================================================
74 // Method Description:
86 template<typename dtype, typename GeneratorType = std::mt19937>
87 NdArray<dtype> f(GeneratorType& generator, const Shape& inShape, dtype inDofN, dtype inDofD)
88 {
90
91 if (inDofN <= 0)
92 {
93 THROW_INVALID_ARGUMENT_ERROR("numerator degrees of freedom should be greater than zero.");
94 }
95
96 if (inDofD <= 0)
97 {
98 THROW_INVALID_ARGUMENT_ERROR("denominator degrees of freedom should be greater than zero.");
99 }
100
101 NdArray<dtype> returnArray(inShape);
102
103 std::fisher_f_distribution<dtype> dist(inDofN, inDofD);
104
105 std::for_each(returnArray.begin(),
106 returnArray.end(),
107 [&generator, &dist](dtype& value) -> void { value = dist(generator); });
108
109 return returnArray;
110 }
111 } // namespace detail
112
113 //============================================================================
114 // Method Description:
123 template<typename dtype>
124 dtype f(dtype inDofN, dtype inDofD)
125 {
126 return detail::f(generator_, inDofN, inDofD);
127 }
128
129 //============================================================================
130 // Method Description:
141 template<typename dtype>
142 NdArray<dtype> f(const Shape& inShape, dtype inDofN, dtype inDofD)
143 {
144 return detail::f(generator_, inShape, inDofN, inDofD);
145 }
146} // 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:135
iterator end() noexcept
Definition NdArrayCore.hpp:1619
iterator begin() noexcept
Definition NdArrayCore.hpp:1311
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
Definition Random/bernoulli.hpp:41
dtype f(GeneratorType &generator, dtype inDofN, dtype inDofD)
Definition f.hpp:55
Definition Random/bernoulli.hpp:39
dtype f(dtype inDofN, dtype inDofD)
Definition f.hpp:124
std::mt19937_64 generator_
generator function
Definition generator.hpp:35