NumCpp  2.8.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 
38 namespace nc
39 {
40  namespace random
41  {
42  namespace detail
43  {
44  //============================================================================
45  // Method Description:
54  template<typename dtype, typename GeneratorType = std::mt19937>
55  NdArray<dtype> permutation(GeneratorType& generator, dtype inValue)
56  {
58 
59  NdArray<dtype> returnArray = arange(inValue);
60  std::shuffle(returnArray.begin(), returnArray.end(), generator);
61  return returnArray;
62  }
63 
64  //============================================================================
65  // Method Description:
74  template<typename dtype, typename GeneratorType = std::mt19937>
75  NdArray<dtype> permutation(GeneratorType& generator, const NdArray<dtype>& inArray)
76  {
78 
79  NdArray<dtype> returnArray(inArray);
80  std::shuffle(returnArray.begin(), returnArray.end(), generator);
81  return returnArray;
82  }
83  } // namespace detail
84 
85  //============================================================================
86  // Method Description:
94  template<typename dtype>
95  NdArray<dtype> permutation(dtype inValue)
96  {
97  return detail::permutation(generator_, inValue);
98  }
99 
100  //============================================================================
101  // Method Description:
109  template<typename dtype>
111  {
112  return detail::permutation(generator_, inArray);
113  }
114  } // namespace random
115 } // 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:55
void shuffle(GeneratorType &generator, NdArray< dtype > &inArray)
Definition: shuffle.hpp:50
NdArray< dtype > permutation(dtype inValue)
Definition: permutation.hpp:95
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