NumCpp  2.10.1
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::random
45 {
46  namespace detail
47  {
48  //============================================================================
49  // Method Description:
59  template<typename dtype, typename GeneratorType = std::mt19937>
60  NdArray<dtype> uniformOnSphere(GeneratorType& generator, uint32 inNumPoints, uint32 inDims = 2)
61  {
62  STATIC_ASSERT_FLOAT(dtype);
63 
64  if (inNumPoints == 0)
65  {
66  return {};
67  }
68 
69  boost::random::uniform_on_sphere<dtype> dist(static_cast<int>(inDims));
70 
71  NdArray<dtype> returnArray(inNumPoints, inDims);
72  for (uint32 row = 0; row < inNumPoints; ++row)
73  {
74  const auto& point = dist(generator);
75  std::copy(point.begin(), point.end(), returnArray.begin(row));
76  }
77 
78  return returnArray;
79  }
80  } // namespace detail
81 
82  //============================================================================
83  // Method Description:
92  template<typename dtype>
93  NdArray<dtype> uniformOnSphere(uint32 inNumPoints, uint32 inDims = 2)
94  {
95  return detail::uniformOnSphere<dtype>(generator_, inNumPoints, inDims);
96  }
97 } // namespace nc::random
98 
99 #endif // #ifndef NUMCPP_NO_USE_BOOST
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:50
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:138
iterator begin() noexcept
Definition: NdArrayCore.hpp:1258
NdArray< dtype > uniformOnSphere(GeneratorType &generator, uint32 inNumPoints, uint32 inDims=2)
Definition: uniformOnSphere.hpp:60
Definition: Random/bernoulli.hpp:41
NdArray< dtype > uniformOnSphere(uint32 inNumPoints, uint32 inDims=2)
Definition: uniformOnSphere.hpp:93
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:35
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:97
std::uint32_t uint32
Definition: Types.hpp:40