NumCpp  2.3.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
hypot.hpp
Go to the documentation of this file.
1 #pragma once
29 
33 #include "NumCpp/NdArray.hpp"
34 #include "NumCpp/Utils/sqr.hpp"
35 
36 #include <cmath>
37 #include <string>
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
56  template<typename dtype>
57  double hypot(dtype inValue1, dtype inValue2) noexcept
58  {
60 
61  return std::sqrt(utils::sqr(static_cast<double>(inValue1)) +
62  utils::sqr(static_cast<double>(inValue2)));
63  }
64 
65  //============================================================================
66  // Method Description:
81  template<typename dtype>
82  double hypot(dtype inValue1, dtype inValue2, dtype inValue3) noexcept
83  {
85 
86  return std::sqrt(utils::sqr(static_cast<double>(inValue1)) +
87  utils::sqr(static_cast<double>(inValue2)) +
88  utils::sqr(static_cast<double>(inValue3)));
89  }
90 
91  //============================================================================
92  // Method Description:
106  template<typename dtype>
107  NdArray<double> hypot(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
108  {
109  if (inArray1.shape() != inArray2.shape())
110  {
111  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
112  }
113 
114  NdArray<dtype> returnArray(inArray1.shape());
115 
116  stl_algorithms::transform(inArray1.cbegin(), inArray1.cend(), inArray2.cbegin(), returnArray.begin(),
117  [](dtype inValue1, dtype inValue2) noexcept -> double
118  {
119  return hypot(inValue1, inValue2);
120  });
121 
122  return returnArray;
123  }
124 } // namespace nc
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4311
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
nc::sqrt
auto sqrt(dtype inValue) noexcept
Definition: sqrt.hpp:50
nc::NdArray< double >
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1490
nc::hypot
double hypot(dtype inValue1, dtype inValue2) noexcept
Definition: hypot.hpp:57
nc
Definition: Coordinate.hpp:44
sqr.hpp
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1146
nc::utils::sqr
constexpr dtype sqr(dtype inValue) noexcept
Definition: sqr.hpp:44
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1090