NumCpp  1.0
A C++ implementation of the Python Numpy library
uniformOnSphere.hpp
Go to the documentation of this file.
1 #pragma once
31 
32 #include "NumCpp/NdArray.hpp"
33 #include "NumCpp/Core/Shape.hpp"
34 #include "NumCpp/Core/Types.hpp"
39 
40 #include "boost/random/uniform_on_sphere.hpp"
41 
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 (inDims < 0)
64  {
65  THROW_INVALID_ARGUMENT_ERROR("input dimension must be greater than or equal to zero.");
66  }
67 
68  boost::random::uniform_on_sphere<dtype> dist(inDims);
69 
70  NdArray<dtype> returnArray(inNumPoints, inDims);
71  for (uint32 row = 0; row < inNumPoints; ++row)
72  {
73  std::vector<dtype> point = dist(generator_);
74  stl_algorithms::copy(returnArray.begin(row), returnArray.end(row), point.begin());
75  }
76 
77  return returnArray;
78  }
79  }
80 }
StaticAsserts.hpp
Error.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
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
nc::random::uniformOnSphere
NdArray< dtype > uniformOnSphere(uint32 inNumPoints, uint32 inDims=2)
Definition: uniformOnSphere.hpp:59
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091