NumCpp  2.6.2
A Templatized Header Only C++ Implementation of the Python NumPy Library
Random/beta.hpp
Go to the documentation of this file.
1 
28 #pragma once
29 
30 #ifndef NUMCPP_NO_USE_BOOST
31 
34 #include "NumCpp/Core/Shape.hpp"
35 #include "NumCpp/NdArray.hpp"
37 
38 #include "boost/random/beta_distribution.hpp"
39 
40 #include <algorithm>
41 #include <string>
42 
43 namespace nc
44 {
45  namespace random
46  {
47  //============================================================================
48  // Method Description:
59  template<typename dtype>
60  dtype beta(dtype inAlpha, dtype inBeta)
61  {
63 
64  if (inAlpha < 0)
65  {
66  THROW_INVALID_ARGUMENT_ERROR("input alpha must be greater than zero.");
67  }
68 
69  if (inBeta < 0)
70  {
71  THROW_INVALID_ARGUMENT_ERROR("input beta must be greater than zero.");
72  }
73 
74  boost::random::beta_distribution<dtype> dist(inAlpha, inBeta);
75  return dist(generator_);
76  }
77 
78  //============================================================================
79  // Method Description:
92  template<typename dtype>
93  NdArray<dtype> beta(const Shape& inShape, dtype inAlpha, dtype inBeta)
94  {
96 
97  if (inAlpha < 0)
98  {
99  THROW_INVALID_ARGUMENT_ERROR("input alpha must be greater than zero.");
100  }
101 
102  if (inBeta < 0)
103  {
104  THROW_INVALID_ARGUMENT_ERROR("input beta must be greater than zero.");
105  }
106 
107  NdArray<dtype> returnArray(inShape);
108 
109  boost::random::beta_distribution<dtype> dist(inAlpha, inBeta);
110 
111  std::for_each(returnArray.begin(), returnArray.end(),
112  [&dist](dtype& value) -> void
113  {
114  value = dist(generator_);
115  });
116 
117  return returnArray;
118  }
119  } // namespace random
120 } // namespace nc
121 
122 #endif // #ifndef NUMCPP_NO_USE_BOOST
#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:1558
iterator begin() noexcept
Definition: NdArrayCore.hpp:1214
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
dtype beta(dtype inAlpha, dtype inBeta)
Definition: Random/beta.hpp:60
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