NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
logaddexp.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cmath>
31#include <complex>
32
37#include "NumCpp/NdArray.hpp"
38
39namespace nc
40{
41 //============================================================================
42 // Method Description:
52 template<typename dtype>
53 auto logaddexp(dtype x1, dtype x2) noexcept
54 {
56
57 return std::log(std::exp(x1) + std::exp(x2));
58 }
59
60 //============================================================================
61 // Method Description:
71 template<typename dtype>
72 auto logaddexp(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 logaddexp(inX1, inX2); });
85
86 return returnArray;
87 }
88} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:56
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
Definition: Cartesian.hpp:40
auto log(dtype inValue) noexcept
Definition: log.hpp:50
auto logaddexp(dtype x1, dtype x2) noexcept
Definition: logaddexp.hpp:53
auto exp(dtype inValue) noexcept
Definition: exp.hpp:49