NumCpp  2.8.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
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
39 {
40  namespace special
41  {
42  //============================================================================
43  // Method Description:
50  inline double bernoilli(uint32 n)
51  {
52  if (n == 1)
53  {
54  return 0.5;
55  }
56  if (n % 2 != 0)
57  {
58  return 0.0;
59  }
60 
61  return boost::math::bernoulli_b2n<double>(n / 2);
62  }
63 
64  //============================================================================
65  // Method Description:
72  inline NdArray<double> bernoilli(const NdArray<uint32>& inArray)
73  {
74  NdArray<double> returnArray(inArray.shape());
75 
77  inArray.cend(),
78  returnArray.begin(),
79  [](uint32 inValue) -> double { return bernoilli(inValue); });
80 
81  return returnArray;
82  }
83  } // namespace special
84 } // namespace nc
85 
86 #endif // #ifndef NUMCPP_NO_USE_BOOST
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1221
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4276
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1529
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
double bernoilli(uint32 n)
Definition: bernoulli.hpp:50
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:784
Definition: Coordinate.hpp:45
std::uint32_t uint32
Definition: Types.hpp:40