NumCpp  2.3.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
chiSquare.hpp
Go to the documentation of this file.
1 #pragma once
29 
33 #include "NumCpp/Core/Shape.hpp"
34 #include "NumCpp/NdArray.hpp"
36 
37 #include "boost/random/chi_squared_distribution.hpp"
38 
39 #include <string>
40 
41 namespace nc
42 {
43  namespace random
44  {
45  //============================================================================
46  // Method Description:
55  template<typename dtype>
56  dtype chiSquare(dtype inDof)
57  {
59 
60  if (inDof <= 0)
61  {
62  THROW_INVALID_ARGUMENT_ERROR("numerator degrees of freedom must be greater than zero.");
63  }
64 
65  boost::random::chi_squared_distribution<dtype> dist(inDof);
66  return dist(generator_);
67  }
68 
69  //============================================================================
70  // Method Description:
81  template<typename dtype>
82  NdArray<dtype> chiSquare(const Shape& inShape, dtype inDof)
83  {
85 
86  if (inDof <= 0)
87  {
88  THROW_INVALID_ARGUMENT_ERROR("numerator degrees of freedom must be greater than zero.");
89  }
90 
91  NdArray<dtype> returnArray(inShape);
92 
93  boost::random::chi_squared_distribution<dtype> dist(inDof);
94 
95  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
96  [&dist](dtype& value) -> void
97  {
98  value = dist(generator_);
99  });
100 
101  return returnArray;
102  }
103  } // namespace random
104 } // namespace nc
StaticAsserts.hpp
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
generator.hpp
nc::NdArray< dtype >
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:213
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:40
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1434
Shape.hpp
nc
Definition: Coordinate.hpp:44
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1090
nc::random::chiSquare
dtype chiSquare(dtype inDof)
Definition: chiSquare.hpp:56