NumCpp  1.0
A C++ implementation of the Python Numpy library
legendre_q.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #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_q(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_q(n, static_cast<double>(x));
61  }
62 
63  //============================================================================
64  // Method Description:
72  template<typename dtype>
74  {
75  NdArray<double> returnArray(inArrayX.shape());
76 
77  const auto function = [n](dtype x) -> double
78  {
79  return legendre_q(n, x);
80  };
81 
82  stl_algorithms::transform(inArrayX.cbegin(), inArrayX.cend(), returnArray.begin(), function);
83 
84  return returnArray;
85  }
86  }
87 }
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4296
nc::int32
std::int32_t int32
Definition: Types.hpp:37
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::polynomial::legendre_q
NdArray< double > legendre_q(int32 n, const NdArray< dtype > &inArrayX)
Definition: legendre_q.hpp:73
nc::NdArray< double >
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
nc::polynomial::legendre_q
double legendre_q(int32 n, dtype x)
Definition: legendre_q.hpp:51
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091