NumCpp  2.11.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
factorial.hpp
Go to the documentation of this file.
1 #pragma once
29 
31 #include "NumCpp/Core/Types.hpp"
32 #include "NumCpp/NdArray.hpp"
33 
34 #ifndef NUMCPP_NO_USE_BOOST
35 #include "boost/math/special_functions/factorials.hpp"
36 #endif
37 
38 #include <limits>
39 
40 namespace nc::special
41 {
42  //============================================================================
43  // Method Description:
49  inline double factorial(uint32 inValue)
50  {
51 #ifndef NUMCPP_NO_USE_BOOST
52  if (inValue <= boost::math::max_factorial<double>::value)
53  {
54  return boost::math::factorial<double>(inValue);
55  }
56 
57  return std::numeric_limits<double>::infinity();
58 #else
59  double result = 1.;
60  for (uint32 i = 2; i <= inValue; ++i)
61  {
62  result *= static_cast<double>(i);
63  }
64 
65  return result;
66 #endif
67  }
68 
69  //============================================================================
70  // Method Description:
76  inline NdArray<double> factorial(const NdArray<uint32>& inArray)
77  {
78  NdArray<double> returnArray(inArray.shape());
79 
81  inArray.cend(),
82  returnArray.begin(),
83  [](uint32 inValue) -> double { return factorial(inValue); });
84 
85  return returnArray;
86  }
87 } // namespace nc::special
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1318
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1626
iterator begin() noexcept
Definition: NdArrayCore.hpp:1268
const Shape & shape() const noexcept
Definition: NdArrayCore.hpp:4464
Definition: airy_ai.hpp:39
double factorial(uint32 inValue)
Definition: factorial.hpp:49
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:775
std::uint32_t uint32
Definition: Types.hpp:40