NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
logaddexp.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cmath>
31
35#include "NumCpp/NdArray.hpp"
36
37namespace nc
38{
39 //============================================================================
40 // Method Description:
50 template<typename dtype>
51 auto logaddexp(dtype x1, dtype x2) noexcept
52 {
54
55 return std::log(std::exp(x1) + std::exp(x2));
56 }
57
58 //============================================================================
59 // Method Description:
69 template<typename dtype>
70 auto logaddexp(const NdArray<dtype>& x1, const NdArray<dtype>& x2)
71 {
72 if (x1.size() != x2.size())
73 {
74 THROW_INVALID_ARGUMENT_ERROR("Inputs 'x1', and 'x2' must be the same size");
75 }
76
77 NdArray<decltype(logaddexp(dtype{ 0 }, dtype{ 0 }))> returnArray(x1.shape());
79 x1.cend(),
80 x2.cbegin(),
81 returnArray.begin(),
82 [](dtype inX1, dtype inX2) noexcept -> auto { return logaddexp(inX1, inX2); });
83
84 return returnArray;
85 }
86} // 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:135
size_type size() const noexcept
Definition NdArrayCore.hpp:4600
const_iterator cbegin() const noexcept
Definition NdArrayCore.hpp:1361
const Shape & shape() const noexcept
Definition NdArrayCore.hpp:4587
const_iterator cend() const noexcept
Definition NdArrayCore.hpp:1669
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition StlAlgorithms.hpp:776
Definition Cartesian.hpp:39
auto logaddexp(dtype x1, dtype x2) noexcept
Definition logaddexp.hpp:51