NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
studentT.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:
53  template<typename dtype>
54  dtype studentT(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:
78  template<typename dtype>
79  NdArray<dtype> studentT(const Shape& inShape, dtype inDof)
80  {
82 
83  if (inDof <= 0)
84  {
85  THROW_INVALID_ARGUMENT_ERROR("degrees of freedom must be greater than zero.");
86  }
87 
88  NdArray<dtype> returnArray(inShape);
89 
90  std::student_t_distribution<dtype> dist(inDof);
91 
92  std::for_each(returnArray.begin(), returnArray.end(),
93  [&dist](dtype& value) -> void
94  {
95  value = dist(generator_);
96  });
97 
98  return returnArray;
99  }
100  } // namespace random
101 } // 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
dtype studentT(dtype inDof)
Definition: studentT.hpp:54
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:213
Definition: Coordinate.hpp:45