NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
discrete.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 //============================================================================
44 // Method Description:
54 template<typename dtype, typename GeneratorType = std::mt19937>
56 {
58
59 std::discrete_distribution<dtype> dist(inWeights.cbegin(), inWeights.cend());
60 return dist(generator);
61 }
62
63 //============================================================================
64 // Method Description:
76 template<typename dtype, typename GeneratorType = std::mt19937>
78 {
80
82
83 std::discrete_distribution<dtype> dist(inWeights.cbegin(), inWeights.cend());
84
85 std::for_each(returnArray.begin(),
86 returnArray.end(),
87 [&generator, &dist](dtype& value) -> void { value = dist(generator); });
88
89 return returnArray;
90 }
91 } // namespace detail
92
93 //============================================================================
94 // Method Description:
103 template<typename dtype>
105 {
106 return detail::discrete<dtype>(generator_, inWeights);
107 }
108
109 //============================================================================
110 // Method Description:
121 template<typename dtype>
123 {
124 return detail::discrete<dtype>(generator_, inShape, inWeights);
125 }
126} // namespace nc::random
#define STATIC_ASSERT_INTEGER(dtype)
Definition StaticAsserts.hpp:43
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
dtype discrete(GeneratorType &generator, const NdArray< double > &inWeights)
Definition discrete.hpp:55
Definition Random/bernoulli.hpp:41
dtype discrete(const NdArray< double > &inWeights)
Definition discrete.hpp:104
std::mt19937_64 generator_
generator function
Definition generator.hpp:35
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59