NumCpp  2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
ellint_2.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #if defined(__cpp_lib_math_special_functions) || !defined(NO_USE_BOOST)
31 
35 #include "NumCpp/NdArray.hpp"
36 
37 #ifdef __cpp_lib_math_special_functions
38 #include <cmath>
39 #else
40 #include "boost/math/special_functions/ellint_2.hpp"
41 #endif
42 
43 #include <type_traits>
44 
45 namespace nc
46 {
47  namespace special
48  {
49  //============================================================================
50  // Method Description:
60  template<typename dtype1, typename dtype2>
61  auto ellint_2(dtype1 inK, dtype2 inP)
62  {
65 
66 #ifdef __cpp_lib_math_special_functions
67  return std::ellint_2(inK, inP);
68 #else
69  return boost::math::ellint_2(inK, inP);
70 #endif
71  }
72 
73  //============================================================================
74  // Method Description:
84  template<typename dtype1, typename dtype2>
85  auto ellint_2(const NdArray<dtype1>& inArrayK, const NdArray<dtype2>& inArrayP)
86  {
87  if (inArrayK.size() != inArrayP.size())
88  {
89  THROW_INVALID_ARGUMENT_ERROR("Shapes of inArrayK and inArrayP must match.");
90  }
91 
92  NdArray<decltype(ellint_2(dtype1{ 0 }, dtype2{ 0 }))> returnArray(inArrayK.shape());
93 
94  stl_algorithms::transform(inArrayK.cbegin(), inArrayK.cend(), inArrayP.cbegin(), returnArray.begin(),
95  [](dtype1 inK, dtype2 inP) -> auto
96  {
97  return ellint_2(inK, inP);
98  });
99 
100  return returnArray;
101  }
102  } // namespace special
103 } // namespace nc
104 
105 #endif // #if defined(__cpp_lib_math_special_functions) || !defined(NO_USE_BOOST)
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4356
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
nc::NdArray
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:71
nc::special::ellint_2
auto ellint_2(const NdArray< dtype1 > &inArrayK, const NdArray< dtype2 > &inArrayP)
Definition: ellint_2.hpp:85
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
NdArray.hpp
nc::NdArray::size
size_type size() const noexcept
Definition: NdArrayCore.hpp:4370
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1487
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:1143
StlAlgorithms.hpp
nc::special::ellint_2
auto ellint_2(dtype1 inK, dtype2 inP)
Definition: ellint_2.hpp:61
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1087