NumCpp  2.6.2
A Templatized Header Only C++ Implementation of the Python NumPy Library
prime.hpp
Go to the documentation of this file.
1 
28 #pragma once
29 
30 #ifndef NUMCPP_NO_USE_BOOST
31 
34 #include "NumCpp/Core/Types.hpp"
35 #include "NumCpp/NdArray.hpp"
36 
37 #include "boost/math/special_functions/prime.hpp"
38 
39 #include <string>
40 
41 namespace nc
42 {
43  namespace special
44  {
45  //============================================================================
46  // Method Description:
56  inline uint32 prime(uint32 n)
57  {
58  if (n > boost::math::max_prime)
59  {
60  THROW_INVALID_ARGUMENT_ERROR("input n must be less than or equal to " + std::to_string(boost::math::max_prime));
61  }
62 
63  return boost::math::prime(n);
64  }
65 
66  //============================================================================
67  // Method Description:
77  inline NdArray<uint32> prime(const NdArray<uint32>& inArray)
78  {
79  NdArray<uint32> returnArray(inArray.shape());
80 
81  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), returnArray.begin(),
82  [](uint32 inValue) -> uint32
83  {
84  return prime(inValue);
85  });
86 
87  return returnArray;
88  }
89  } // namespace special
90 } // namespace nc
91 
92 #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:1270
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4483
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1614
iterator begin() noexcept
Definition: NdArrayCore.hpp:1214
uint32 prime(uint32 n)
Definition: prime.hpp:56
NdArray< uint32 > prime(const NdArray< uint32 > &inArray)
Definition: prime.hpp:77
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
Definition: Coordinate.hpp:45
std::uint32_t uint32
Definition: Types.hpp:40