NumCpp  1.0
A C++ implementation of the Python Numpy library
extremeValue.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
32 #include "NumCpp/Core/Shape.hpp"
37 
38 #include <boost/random/extreme_value_distribution.hpp>
39 
40 #include <string>
41 
42 namespace nc
43 {
44  namespace random
45  {
46  //============================================================================
47  // Method Description:
55  template<typename dtype>
56  dtype extremeValue(dtype inA = 1, dtype inB = 1)
57  {
59 
60  if (inA <= 0)
61  {
62  THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
63  }
64 
65  if (inB <= 0)
66  {
67  THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
68  }
69 
70  const boost::random::extreme_value_distribution<dtype> dist(inA, inB);
71  return dist(generator_);
72  }
73 
74  //============================================================================
75  // Method Description:
85  template<typename dtype>
86  NdArray<dtype> extremeValue(const Shape& inShape, dtype inA = 1, dtype inB = 1)
87  {
89 
90  if (inA <= 0)
91  {
92  THROW_INVALID_ARGUMENT_ERROR("input a must be greater than zero.");
93  }
94 
95  if (inB <= 0)
96  {
97  THROW_INVALID_ARGUMENT_ERROR("input b must be greater than zero.");
98  }
99 
100  NdArray<dtype> returnArray(inShape);
101 
102  const boost::random::extreme_value_distribution<dtype> dist(inA, inB);
103 
104  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
105  [&dist](dtype& value) -> void
106  {
107  value = dist(generator_);
108  });
109 
110  return returnArray;
111  }
112  }
113 }
StaticAsserts.hpp
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f) noexcept
Definition: StlAlgorithms.hpp:214
generator.hpp
nc::random::extremeValue
dtype extremeValue(dtype inA=1, dtype inB=1)
Definition: extremeValue.hpp:56
nc::NdArray< dtype >
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
Shape.hpp
nc
Definition: Coordinate.hpp:45
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:40
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091