NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
studentT.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 // Method Description:
53 template<typename dtype, typename GeneratorType = std::mt19937>
54 dtype studentT(GeneratorType& generator, dtype inDof)
55 {
57
58 if (inDof <= 0)
59 {
60 THROW_INVALID_ARGUMENT_ERROR("degrees of freedom must be greater than zero.");
61 }
62
63 std::student_t_distribution<dtype> dist(inDof);
64 return dist(generator);
65 }
66
67 //============================================================================
68 // Method Description:
80 template<typename dtype, typename GeneratorType = std::mt19937>
81 NdArray<dtype> studentT(GeneratorType& generator, const Shape& inShape, dtype inDof)
82 {
84
85 if (inDof <= 0)
86 {
87 THROW_INVALID_ARGUMENT_ERROR("degrees of freedom must be greater than zero.");
88 }
89
90 NdArray<dtype> returnArray(inShape);
91
92 std::student_t_distribution<dtype> dist(inDof);
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:
112 template<typename dtype>
113 dtype studentT(dtype inDof)
114 {
115 return detail::studentT(generator_, inDof);
116 }
117
118 //============================================================================
119 // Method Description:
130 template<typename dtype>
131 NdArray<dtype> studentT(const Shape& inShape, dtype inDof)
132 {
133 return detail::studentT(generator_, inShape, inDof);
134 }
135} // 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 studentT(GeneratorType &generator, dtype inDof)
Definition studentT.hpp:54
Definition Random/bernoulli.hpp:39
dtype studentT(dtype inDof)
Definition studentT.hpp:113
std::mt19937_64 generator_
generator function
Definition generator.hpp:35