NumCpp  2.6.2
A Templatized Header Only C++ Implementation of the Python NumPy Library
uniformOnSphere.hpp
Go to the documentation of this file.
1 
29 #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:
59  template<typename dtype>
60  NdArray<dtype> uniformOnSphere(uint32 inNumPoints, uint32 inDims = 2)
61  {
62  STATIC_ASSERT_FLOAT(dtype);
63 
64  boost::random::uniform_on_sphere<dtype> dist(inDims);
65 
66  NdArray<dtype> returnArray(inNumPoints, inDims);
67  for (uint32 row = 0; row < inNumPoints; ++row)
68  {
69  std::vector<dtype> point = dist(generator_);
70  std::copy(returnArray.begin(row), returnArray.end(row), point.begin());
71  }
72 
73  return returnArray;
74  }
75  } // namespace random
76 } // namespace nc
77 
78 #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 end() noexcept
Definition: NdArrayCore.hpp:1558
iterator begin() noexcept
Definition: NdArrayCore.hpp:1214
NdArray< dtype > uniformOnSphere(uint32 inNumPoints, uint32 inDims=2)
Definition: uniformOnSphere.hpp:60
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