NumCpp  2.3.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 
33 #include "NumCpp/Core/Shape.hpp"
34 #include "NumCpp/Core/Types.hpp"
35 #include "NumCpp/NdArray.hpp"
37 
38 #include "boost/random/uniform_on_sphere.hpp"
39 
40 #include <string>
41 
42 namespace nc
43 {
44  namespace random
45  {
46  //============================================================================
47  // Method Description:
56  template<typename dtype>
57  NdArray<dtype> uniformOnSphere(uint32 inNumPoints, uint32 inDims = 2)
58  {
59  STATIC_ASSERT_FLOAT(dtype);
60 
61  boost::random::uniform_on_sphere<dtype> dist(inDims);
62 
63  NdArray<dtype> returnArray(inNumPoints, inDims);
64  for (uint32 row = 0; row < inNumPoints; ++row)
65  {
66  std::vector<dtype> point = dist(generator_);
67  stl_algorithms::copy(returnArray.begin(row), returnArray.end(row), point.begin());
68  }
69 
70  return returnArray;
71  }
72  } // namespace random
73 } // namespace nc
StaticAsserts.hpp
generator.hpp
nc::NdArray< dtype >
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:40
NdArray.hpp
STATIC_ASSERT_FLOAT
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:43
nc::stl_algorithms::copy
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:95
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1434
Shape.hpp
nc
Definition: Coordinate.hpp:44
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:39
nc::random::uniformOnSphere
NdArray< dtype > uniformOnSphere(uint32 inNumPoints, uint32 inDims=2)
Definition: uniformOnSphere.hpp:57
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1090