NumCpp  2.3.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 
32 #include "NumCpp/Core/Types.hpp"
33 #include "NumCpp/NdArray.hpp"
34 
35 #include "boost/math/special_functions/prime.hpp"
36 
37 #include <string>
38 
39 namespace nc
40 {
41  namespace special
42  {
43  //============================================================================
44  // Method Description:
53  inline uint32 prime(uint32 n)
54  {
55  if (n > boost::math::max_prime)
56  {
57  THROW_INVALID_ARGUMENT_ERROR("input n must be less than or equal to " + std::to_string(boost::math::max_prime));
58  }
59 
60  return boost::math::prime(n);
61  }
62 
63  //============================================================================
64  // Method Description:
73  inline NdArray<uint32> prime(const NdArray<uint32>& inArray)
74  {
75  NdArray<uint32> returnArray(inArray.shape());
76 
77  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), returnArray.begin(),
78  [](uint32 inValue) -> uint32
79  {
80  return prime(inValue);
81  });
82 
83  return returnArray;
84  }
85  } // namespace special
86 } // namespace nc
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4311
Error.hpp
nc::special::prime
uint32 prime(uint32 n)
Definition: prime.hpp:53
nc::NdArray
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:74
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:40
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1490
nc
Definition: Coordinate.hpp:44
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1146
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1090
nc::special::prime
NdArray< uint32 > prime(const NdArray< uint32 > &inArray)
Definition: prime.hpp:73