NumCpp  2.1.0
A C++ implementation of the Python Numpy library
uniformOnSphere.hpp
Go to the documentation of this file.
1 #pragma once
31 
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 <string>
42 
43 namespace nc
44 {
45  namespace random
46  {
47  //============================================================================
48  // Method Description:
57  template<typename dtype>
58  NdArray<dtype> uniformOnSphere(uint32 inNumPoints, uint32 inDims = 2)
59  {
60  STATIC_ASSERT_FLOAT(dtype);
61 
62  boost::random::uniform_on_sphere<dtype> dist(inDims);
63 
64  NdArray<dtype> returnArray(inNumPoints, inDims);
65  for (uint32 row = 0; row < inNumPoints; ++row)
66  {
67  std::vector<dtype> point = dist(generator_);
68  stl_algorithms::copy(returnArray.begin(row), returnArray.end(row), point.begin());
69  }
70 
71  return returnArray;
72  }
73  } // namespace random
74 } // namespace nc
StaticAsserts.hpp
generator.hpp
nc::NdArray< dtype >
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
NdArray.hpp
STATIC_ASSERT_FLOAT
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:44
nc::stl_algorithms::copy
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:96
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
Shape.hpp
nc
Definition: Coordinate.hpp:45
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:40
nc::random::uniformOnSphere
NdArray< dtype > uniformOnSphere(uint32 inNumPoints, uint32 inDims=2)
Definition: uniformOnSphere.hpp:58
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091