NumCpp  2.8.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
prime.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #ifndef NUMCPP_NO_USE_BOOST
31 
32 #include <string>
33 
34 #include "boost/math/special_functions/prime.hpp"
35 
38 #include "NumCpp/Core/Types.hpp"
39 #include "NumCpp/NdArray.hpp"
40 
41 namespace nc
42 {
43  namespace special
44  {
45  //============================================================================
46  // Method Description:
54  inline uint32 prime(uint32 n)
55  {
56  if (n > boost::math::max_prime)
57  {
58  THROW_INVALID_ARGUMENT_ERROR("input n must be less than or equal to " +
59  std::to_string(boost::math::max_prime));
60  }
61 
62  return boost::math::prime(n);
63  }
64 
65  //============================================================================
66  // Method Description:
74  inline NdArray<uint32> prime(const NdArray<uint32>& inArray)
75  {
76  NdArray<uint32> returnArray(inArray.shape());
77 
79  inArray.cend(),
80  returnArray.begin(),
81  [](uint32 inValue) -> uint32 { return prime(inValue); });
82 
83  return returnArray;
84  }
85  } // namespace special
86 } // namespace nc
87 
88 #endif // #ifndef NUMCPP_NO_USE_BOOST
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1221
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4276
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1529
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
uint32 prime(uint32 n)
Definition: prime.hpp:54
NdArray< uint32 > prime(const NdArray< uint32 > &inArray)
Definition: prime.hpp:74
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:784
Definition: Coordinate.hpp:45
std::uint32_t uint32
Definition: Types.hpp:40