NumCpp  2.11.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Special/bernoulli.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #ifndef NUMCPP_NO_USE_BOOST
31 
32 #include "boost/math/special_functions/bernoulli.hpp"
33 
35 #include "NumCpp/Core/Types.hpp"
36 #include "NumCpp/NdArray.hpp"
37 
38 namespace nc::special
39 {
40  //============================================================================
41  // Method Description:
48  inline double bernoilli(uint32 n)
49  {
50  if (n == 1)
51  {
52  return 0.5;
53  }
54  if (n % 2 != 0)
55  {
56  return 0.;
57  }
58 
59  return boost::math::bernoulli_b2n<double>(n / 2);
60  }
61 
62  //============================================================================
63  // Method Description:
70  inline NdArray<double> bernoilli(const NdArray<uint32>& inArray)
71  {
72  NdArray<double> returnArray(inArray.shape());
73 
75  inArray.cend(),
76  returnArray.begin(),
77  [](uint32 inValue) -> double { return bernoilli(inValue); });
78 
79  return returnArray;
80  }
81 } // namespace nc::special
82 
83 #endif // #ifndef NUMCPP_NO_USE_BOOST
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 bernoilli(uint32 n)
Definition: Special/bernoulli.hpp:48
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:775
std::uint32_t uint32
Definition: Types.hpp:40