NumCpp  2.3.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
bernoulli.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 #include "boost/math/special_functions/bernoulli.hpp"
35 
36 namespace nc
37 {
38  namespace special
39  {
40  //============================================================================
41  // Method Description:
49  inline double bernoilli(uint32 n)
50  {
51  if (n == 1)
52  {
53  return 0.5;
54  }
55  if (n % 2 != 0)
56  {
57  return 0.0;
58  }
59 
60  return boost::math::bernoulli_b2n<double>(n / 2);
61  }
62 
63  //============================================================================
64  // 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
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4311
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:1490
nc::special::bernoilli
double bernoilli(uint32 n)
Definition: bernoulli.hpp:49
nc
Definition: Coordinate.hpp:44
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1146
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1090