NumCpp  1.0
A C++ implementation of the Python Numpy library
prime.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
32 #include "NumCpp/Core/Types.hpp"
35 
36 #include "boost/math/special_functions/prime.hpp"
37 
38 #include <string>
39 
40 namespace nc
41 {
42  namespace special
43  {
44  //============================================================================
45  // 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 " + std::to_string(boost::math::max_prime));
59  }
60 
61  return boost::math::prime(n);
62  }
63 
64  //============================================================================
65  // Method Description:
74  inline NdArray<uint32> prime(const NdArray<uint32>& inArray)
75  {
76  NdArray<uint32> returnArray(inArray.shape());
77 
78  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), returnArray.begin(),
79  [](uint32 inValue) -> uint32
80  {
81  return prime(inValue);
82  });
83 
84  return returnArray;
85  }
86  }
87 }
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4296
Error.hpp
nc::special::prime
uint32 prime(uint32 n)
Definition: prime.hpp:54
nc::NdArray
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:75
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
nc
Definition: Coordinate.hpp:45
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction) noexcept
Definition: StlAlgorithms.hpp:703
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091
nc::special::prime
NdArray< uint32 > prime(const NdArray< uint32 > &inArray)
Definition: prime.hpp:74