NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
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>
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.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
size_type size() const noexcept
Definition: NdArrayCore.hpp:4524
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1365
const Shape & shape() const noexcept
Definition: NdArrayCore.hpp:4511
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1673
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 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