NumCpp  2.7.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 
34 #include "NumCpp/Core/Shape.hpp"
35 #include "NumCpp/Core/Types.hpp"
36 #include "NumCpp/NdArray.hpp"
38 
39 #include "boost/random/uniform_on_sphere.hpp"
40 
41 #include <algorithm>
42 #include <string>
43 
44 namespace nc
45 {
46  namespace random
47  {
48  //============================================================================
49  // Method Description:
58  template<typename dtype>
59  NdArray<dtype> uniformOnSphere(uint32 inNumPoints, uint32 inDims = 2)
60  {
61  STATIC_ASSERT_FLOAT(dtype);
62 
63  if (inNumPoints == 0)
64  {
65  return {};
66  }
67 
68  boost::random::uniform_on_sphere<dtype> dist(static_cast<int>(inDims));
69 
70  NdArray<dtype> returnArray(inNumPoints, inDims);
71  for (uint32 row = 0; row < inNumPoints; ++row)
72  {
73  const auto& point = dist(generator_);
74  std::copy(point.begin(), point.end(), returnArray.begin(row));
75  }
76 
77  return returnArray;
78  }
79  } // namespace random
80 } // namespace nc
81 
82 #endif // #ifndef NUMCPP_NO_USE_BOOST
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:43
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
iterator begin() noexcept
Definition: NdArrayCore.hpp:1166
NdArray< dtype > uniformOnSphere(uint32 inNumPoints, uint32 inDims=2)
Definition: uniformOnSphere.hpp:59
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:95
Definition: Coordinate.hpp:45
std::uint32_t uint32
Definition: Types.hpp:40