NumCpp  2.9.0
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
38 {
39  namespace random
40  {
41  namespace detail
42  {
43  //============================================================================
44  // Method Description:
53  template<typename dtype, typename GeneratorType = std::mt19937>
54  NdArray<dtype> permutation(GeneratorType& generator, dtype inValue)
55  {
57 
58  NdArray<dtype> returnArray = arange(inValue);
59  std::shuffle(returnArray.begin(), returnArray.end(), generator);
60  return returnArray;
61  }
62 
63  //============================================================================
64  // Method Description:
73  template<typename dtype, typename GeneratorType = std::mt19937>
74  NdArray<dtype> permutation(GeneratorType& generator, const NdArray<dtype>& inArray)
75  {
77 
78  NdArray<dtype> returnArray(inArray);
79  std::shuffle(returnArray.begin(), returnArray.end(), generator);
80  return returnArray;
81  }
82  } // namespace detail
83 
84  //============================================================================
85  // Method Description:
93  template<typename dtype>
94  NdArray<dtype> permutation(dtype inValue)
95  {
96  return detail::permutation(generator_, inValue);
97  }
98 
99  //============================================================================
100  // Method Description:
108  template<typename dtype>
110  {
111  return detail::permutation(generator_, inArray);
112  }
113  } // namespace random
114 } // namespace nc
#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:1479
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
NdArray< dtype > permutation(GeneratorType &generator, dtype inValue)
Definition: permutation.hpp:54
void shuffle(GeneratorType &generator, NdArray< dtype > &inArray)
Definition: shuffle.hpp:50
NdArray< dtype > permutation(dtype inValue)
Definition: permutation.hpp:94
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:37
Definition: Coordinate.hpp:45
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition: arange.hpp:59