NumCpp  2.7.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 
33 #include "NumCpp/Core/Types.hpp"
34 #include "NumCpp/NdArray.hpp"
35 
36 #include "boost/math/special_functions/bernoulli.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 
76  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), returnArray.begin(),
77  [](uint32 inValue) -> double
78  {
79  return bernoilli(inValue);
80  });
81 
82  return returnArray;
83  }
84  } // namespace special
85 } // namespace nc
86 
87 #endif // #ifndef NUMCPP_NO_USE_BOOST
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1216
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4283
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1524
iterator begin() noexcept
Definition: NdArrayCore.hpp:1166
double bernoilli(uint32 n)
Definition: bernoulli.hpp:50
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
Definition: Coordinate.hpp:45
std::uint32_t uint32
Definition: Types.hpp:40