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
hypot.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cmath>
31#include <string>
32
36#include "NumCpp/NdArray.hpp"
37#include "NumCpp/Utils/sqr.hpp"
38
39namespace nc
40{
41 //============================================================================
42 // Method Description:
55 template<typename dtype>
56 double hypot(dtype inValue1, dtype inValue2) noexcept
57 {
59
60 return std::hypot(static_cast<double>(inValue1), static_cast<double>(inValue2));
61 }
62
63 //============================================================================
64 // Method Description:
78 template<typename dtype>
80 {
82
83#ifdef __cpp_lib_hypot
84 return std::hypot(static_cast<double>(inValue1), static_cast<double>(inValue2), static_cast<double>(inValue3));
85#else
86 return std::sqrt(utils::sqr(static_cast<double>(inValue1)) + utils::sqr(static_cast<double>(inValue2)) +
87 utils::sqr(static_cast<double>(inValue3)));
88#endif
89 }
90
91 //============================================================================
92 // Method Description:
105 template<typename dtype>
107 {
108 return broadcast::broadcaster<double>(inArray1,
109 inArray2,
110 [](dtype inValue1, dtype inValue2) noexcept -> double
111 { return hypot(inValue1, inValue2); });
112 }
113
114 //============================================================================
115 // Method Description:
129 template<typename dtype>
130 NdArray<double>
132 {
133 if (inArray1.size() != inArray2.size() || inArray1.size() != inArray3.size())
134 {
135 THROW_INVALID_ARGUMENT_ERROR("input array sizes are not consistant.");
136 }
137
139 for (typename NdArray<dtype>::size_type i = 0; i < inArray1.size(); ++i)
140 {
141 returnArray[i] = hypot(inArray1[i], inArray2[i], inArray3[i]);
142 }
143
144 return returnArray;
145 }
146} // 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
uint32 size_type
Definition NdArrayCore.hpp:156
constexpr dtype sqr(dtype inValue) noexcept
Definition sqr.hpp:42
Definition Cartesian.hpp:40
double hypot(dtype inValue1, dtype inValue2) noexcept
Definition hypot.hpp:56
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59