NumCpp  2.9.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
uniformOnSphere.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #ifndef NUMCPP_NO_USE_BOOST
32 
33 #include <algorithm>
34 #include <string>
35 
36 #include "boost/random/uniform_on_sphere.hpp"
37 
39 #include "NumCpp/Core/Shape.hpp"
40 #include "NumCpp/Core/Types.hpp"
41 #include "NumCpp/NdArray.hpp"
43 
44 namespace nc
45 {
46  namespace random
47  {
48  namespace detail
49  {
50  //============================================================================
51  // Method Description:
61  template<typename dtype, typename GeneratorType = std::mt19937>
62  NdArray<dtype> uniformOnSphere(GeneratorType& generator, uint32 inNumPoints, uint32 inDims = 2)
63  {
64  STATIC_ASSERT_FLOAT(dtype);
65 
66  if (inNumPoints == 0)
67  {
68  return {};
69  }
70 
71  boost::random::uniform_on_sphere<dtype> dist(static_cast<int>(inDims));
72 
73  NdArray<dtype> returnArray(inNumPoints, inDims);
74  for (uint32 row = 0; row < inNumPoints; ++row)
75  {
76  const auto& point = dist(generator);
77  std::copy(point.begin(), point.end(), returnArray.begin(row));
78  }
79 
80  return returnArray;
81  }
82  } // namespace detail
83 
84  //============================================================================
85  // Method Description:
94  template<typename dtype>
95  NdArray<dtype> uniformOnSphere(uint32 inNumPoints, uint32 inDims = 2)
96  {
97  return detail::uniformOnSphere<dtype>(generator_, inNumPoints, inDims);
98  }
99  } // namespace random
100 } // namespace nc
101 
102 #endif // #ifndef NUMCPP_NO_USE_BOOST
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:45
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
NdArray< dtype > uniformOnSphere(GeneratorType &generator, uint32 inNumPoints, uint32 inDims=2)
Definition: uniformOnSphere.hpp:62
NdArray< dtype > uniformOnSphere(uint32 inNumPoints, uint32 inDims=2)
Definition: uniformOnSphere.hpp:95
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:37
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:99
Definition: Coordinate.hpp:45
std::uint32_t uint32
Definition: Types.hpp:40