NumCpp  2.1.0
A C++ implementation of the Python Numpy library
legendre_p.hpp
Go to the documentation of this file.
1 #pragma once
30 
34 #include "NumCpp/NdArray.hpp"
35 
36 #include "boost/math/special_functions/legendre.hpp"
37 
38 namespace nc
39 {
40  namespace polynomial
41  {
42  //============================================================================
43  // Method Description:
51  template<typename dtype>
52  double legendre_p(int32 n, dtype x)
53  {
55 
56  if (x < -1.0 || x > 1.0 )
57  {
58  THROW_INVALID_ARGUMENT_ERROR("input x must be of the range [-1, 1].");
59  }
60 
61  return boost::math::legendre_p(n, static_cast<double>(x));
62  }
63 
64  //============================================================================
65  // Method Description:
74  template<typename dtype>
75  double legendre_p(int32 n, int32 m, dtype x)
76  {
78 
79  if (x < -1.0 || x > 1.0 )
80  {
81  THROW_INVALID_ARGUMENT_ERROR("input x must be of the range [-1, 1].");
82  }
83 
84  return boost::math::legendre_p(m, n, static_cast<double>(x));
85  }
86 
87  //============================================================================
88  // Method Description:
96  template<typename dtype>
98  {
99  NdArray<double> returnArray(inArrayX.shape());
100 
101  const auto function = [n](dtype x) -> double
102  {
103  return legendre_p(n, x);
104  };
105 
106  stl_algorithms::transform(inArrayX.cbegin(), inArrayX.cend(), returnArray.begin(), function);
107 
108  return returnArray;
109  }
110 
111  //============================================================================
112  // Method Description:
121  template<typename dtype>
123  {
124  NdArray<double> returnArray(inArrayX.shape());
125 
126  const auto function = [n, m](dtype x) -> double
127  {
128  return legendre_p(n, m, x);
129  };
130 
131  stl_algorithms::transform(inArrayX.cbegin(), inArrayX.cend(), returnArray.begin(), function);
132 
133  return returnArray;
134  }
135  } // namespace polynomial
136 } // namespace nc
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
nc::int32
std::int32_t int32
Definition: Types.hpp:37
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::NdArray< double >
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:703
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
nc
Definition: Coordinate.hpp:45
nc::polynomial::legendre_p
double legendre_p(int32 n, dtype x)
Definition: legendre_p.hpp:52
nc::polynomial::legendre_p
NdArray< double > legendre_p(int32 n, int32 m, const NdArray< dtype > &inArrayX)
Definition: legendre_p.hpp:122
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091