NumCpp  2.10.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
permutation.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <algorithm>
31 
34 #include "NumCpp/NdArray.hpp"
36 
37 namespace nc::random
38 {
39  namespace detail
40  {
41  //============================================================================
42  // Method Description:
51  template<typename dtype, typename GeneratorType = std::mt19937>
52  NdArray<dtype> permutation(GeneratorType& generator, dtype inValue)
53  {
55 
56  NdArray<dtype> returnArray = arange(inValue);
57  std::shuffle(returnArray.begin(), returnArray.end(), generator);
58  return returnArray;
59  }
60 
61  //============================================================================
62  // Method Description:
71  template<typename dtype, typename GeneratorType = std::mt19937>
72  NdArray<dtype> permutation(GeneratorType& generator, const NdArray<dtype>& inArray)
73  {
75 
76  NdArray<dtype> returnArray(inArray);
77  std::shuffle(returnArray.begin(), returnArray.end(), generator);
78  return returnArray;
79  }
80  } // namespace detail
81 
82  //============================================================================
83  // Method Description:
91  template<typename dtype>
92  NdArray<dtype> permutation(dtype inValue)
93  {
94  return detail::permutation(generator_, inValue);
95  }
96 
97  //============================================================================
98  // Method Description:
106  template<typename dtype>
108  {
109  return detail::permutation(generator_, inArray);
110  }
111 } // namespace nc::random
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:138
iterator end() noexcept
Definition: NdArrayCore.hpp:1566
iterator begin() noexcept
Definition: NdArrayCore.hpp:1258
NdArray< dtype > permutation(GeneratorType &generator, dtype inValue)
Definition: permutation.hpp:52
void shuffle(GeneratorType &generator, NdArray< dtype > &inArray)
Definition: shuffle.hpp:48
Definition: Random/bernoulli.hpp:41
NdArray< dtype > permutation(dtype inValue)
Definition: permutation.hpp:92
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:35
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition: arange.hpp:59