NumCpp  2.3.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
legendre_p.hpp
Go to the documentation of this file.
1 #pragma once
29 
33 #include "NumCpp/NdArray.hpp"
34 
35 #include "boost/math/special_functions/legendre.hpp"
36 
37 namespace nc
38 {
39  namespace polynomial
40  {
41  //============================================================================
42  // Method Description:
50  template<typename dtype>
51  double legendre_p(int32 n, dtype x)
52  {
54 
55  if (x < -1.0 || x > 1.0 )
56  {
57  THROW_INVALID_ARGUMENT_ERROR("input x must be of the range [-1, 1].");
58  }
59 
60  return boost::math::legendre_p(n, static_cast<double>(x));
61  }
62 
63  //============================================================================
64  // Method Description:
73  template<typename dtype>
74  double legendre_p(int32 n, int32 m, dtype x)
75  {
77 
78  if (x < -1.0 || x > 1.0 )
79  {
80  THROW_INVALID_ARGUMENT_ERROR("input x must be of the range [-1, 1].");
81  }
82 
83  return boost::math::legendre_p(m, n, static_cast<double>(x));
84  }
85 
86  //============================================================================
87  // Method Description:
95  template<typename dtype>
97  {
98  NdArray<double> returnArray(inArrayX.shape());
99 
100  const auto function = [n](dtype x) -> double
101  {
102  return legendre_p(n, x);
103  };
104 
105  stl_algorithms::transform(inArrayX.cbegin(), inArrayX.cend(), returnArray.begin(), function);
106 
107  return returnArray;
108  }
109 
110  //============================================================================
111  // Method Description:
120  template<typename dtype>
122  {
123  NdArray<double> returnArray(inArrayX.shape());
124 
125  const auto function = [n, m](dtype x) -> double
126  {
127  return legendre_p(n, m, x);
128  };
129 
130  stl_algorithms::transform(inArrayX.cbegin(), inArrayX.cend(), returnArray.begin(), function);
131 
132  return returnArray;
133  }
134  } // namespace polynomial
135 } // namespace nc
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4311
nc::int32
std::int32_t int32
Definition: Types.hpp:36
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
nc::NdArray< double >
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1490
nc
Definition: Coordinate.hpp:44
nc::polynomial::legendre_p
double legendre_p(int32 n, dtype x)
Definition: legendre_p.hpp:51
nc::polynomial::legendre_p
NdArray< double > legendre_p(int32 n, int32 m, const NdArray< dtype > &inArrayX)
Definition: legendre_p.hpp:121
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
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1090