NumCpp  2.1.0
A C++ implementation of the Python Numpy library
bernoulli.hpp
Go to the documentation of this file.
1 #pragma once
30 
32 #include "NumCpp/Core/Types.hpp"
33 #include "NumCpp/NdArray.hpp"
34 
35 #include "boost/math/special_functions/bernoulli.hpp"
36 
37 namespace nc
38 {
39  namespace special
40  {
41  //============================================================================
42  // 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:
73  inline NdArray<double> bernoilli(const NdArray<uint32>& inArray)
74  {
75  NdArray<double> returnArray(inArray.shape());
76 
77  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), returnArray.begin(),
78  [](uint32 inValue) -> double
79  {
80  return bernoilli(inValue);
81  });
82 
83  return returnArray;
84  }
85  } // namespace special
86 } // namespace nc
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
nc::NdArray< double >
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:703
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
nc::special::bernoilli
double bernoilli(uint32 n)
Definition: bernoulli.hpp:50
nc
Definition: Coordinate.hpp:45
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091