NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
logaddexp2.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cmath>
31#include <complex>
32
36#include "NumCpp/NdArray.hpp"
38
39namespace 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>
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.cend(),
82 x2.cbegin(),
83 returnArray.begin(),
84 [](dtype inX1, dtype inX2) noexcept -> auto { return logaddexp2(inX1, inX2); });
85
86 return returnArray;
87 }
88} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition StlAlgorithms.hpp:775
auto powerf(dtype1 inValue, const dtype2 inPower) noexcept
Definition Utils/powerf.hpp:47
Definition Cartesian.hpp:40
auto logaddexp(dtype x1, dtype x2) noexcept
Definition logaddexp.hpp:53
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
auto logaddexp2(dtype x1, dtype x2) noexcept
Definition logaddexp2.hpp:53