NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
uniformOnSphere.hpp
Go to the documentation of this file.
1
29#pragma once
30
31#ifndef NUMCPP_NO_USE_BOOST
32
33#include <algorithm>
34
35#include "boost/random/uniform_on_sphere.hpp"
36
38#include "NumCpp/Core/Shape.hpp"
39#include "NumCpp/Core/Types.hpp"
40#include "NumCpp/NdArray.hpp"
42
43namespace nc::random
44{
45 namespace detail
46 {
47 //============================================================================
48 // Method Description:
58 template<typename dtype, typename GeneratorType = std::mt19937>
59 NdArray<dtype> uniformOnSphere(GeneratorType& generator, uint32 inNumPoints, uint32 inDims = 2)
60 {
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 detail
80
81 //============================================================================
82 // Method Description:
91 template<typename dtype>
93 {
94 return detail::uniformOnSphere<dtype>(generator_, inNumPoints, inDims);
95 }
96} // namespace nc::random
97
98#endif // #ifndef NUMCPP_NO_USE_BOOST
#define STATIC_ASSERT_FLOAT(dtype)
Definition StaticAsserts.hpp:50
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
iterator begin() noexcept
Definition NdArrayCore.hpp:1311
Definition Random/bernoulli.hpp:41
NdArray< dtype > uniformOnSphere(GeneratorType &generator, uint32 inNumPoints, uint32 inDims=2)
Definition uniformOnSphere.hpp:59
Definition Random/bernoulli.hpp:39
NdArray< dtype > uniformOnSphere(uint32 inNumPoints, uint32 inDims=2)
Definition uniformOnSphere.hpp:92
std::mt19937_64 generator_
generator function
Definition generator.hpp:35
std::uint32_t uint32
Definition Types.hpp:40