NumCpp  2.4.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 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:
52  inline double bernoilli(uint32 n)
53  {
54  if (n == 1)
55  {
56  return 0.5;
57  }
58  if (n % 2 != 0)
59  {
60  return 0.0;
61  }
62 
63  return boost::math::bernoulli_b2n<double>(n / 2);
64  }
65 
66  //============================================================================
67  // Method Description:
76  inline NdArray<double> bernoilli(const NdArray<uint32>& inArray)
77  {
78  NdArray<double> returnArray(inArray.shape());
79 
80  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), returnArray.begin(),
81  [](uint32 inValue) -> double
82  {
83  return bernoilli(inValue);
84  });
85 
86  return returnArray;
87  }
88  } // namespace special
89 } // namespace nc
90 
91 #endif // #ifndef NO_USE_BOOST
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4356
nc::NdArray< double >
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:40
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1487
nc::special::bernoilli
double bernoilli(uint32 n)
Definition: bernoulli.hpp:52
nc
Definition: Coordinate.hpp:44
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1143
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1087