NumCpp  2.9.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
logaddexp2.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <cmath>
31 #include <complex>
32 
36 #include "NumCpp/NdArray.hpp"
37 #include "NumCpp/Utils/powerf.hpp"
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
52  template<typename dtype>
53  auto logaddexp2(dtype x1, dtype x2) noexcept
54  {
56 
57  return std::log2(utils::powerf(2, x1) + utils::powerf(2, x2));
58  }
59 
60  //============================================================================
61  // Method Description:
71  template<typename dtype>
72  auto logaddexp2(const NdArray<dtype>& x1, const NdArray<dtype>& x2)
73  {
74  if (x1.size() != x2.size())
75  {
76  THROW_INVALID_ARGUMENT_ERROR("Inputs 'x1', and 'x2' must be the same size");
77  }
78 
79  NdArray<decltype(logaddexp(dtype{ 0 }, dtype{ 0 }))> returnArray(x1.shape());
81  x1.cbegin(),
82  x1.cend(),
83  x2.cbegin(),
84  returnArray.begin(),
85  [](dtype inX1, dtype inX2) noexcept -> auto{ return logaddexp2(inX1, inX2); });
86 
87  return returnArray;
88  }
89 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
size_type size() const noexcept
Definition: NdArrayCore.hpp:4105
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1221
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4092
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1529
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:784
auto powerf(dtype1 inValue, const dtype2 inPower) noexcept
Definition: Utils/powerf.hpp:49
Definition: Coordinate.hpp:45
auto log2(dtype inValue) noexcept
Definition: log2.hpp:49
auto logaddexp(dtype x1, dtype x2) noexcept
Definition: logaddexp.hpp:53
auto logaddexp2(dtype x1, dtype x2) noexcept
Definition: logaddexp2.hpp:53