NumCpp  2.1.0
A C++ implementation of the Python Numpy library
hypot.hpp
Go to the documentation of this file.
1 #pragma once
30 
34 #include "NumCpp/NdArray.hpp"
35 #include "NumCpp/Utils/sqr.hpp"
36 
37 #include <cmath>
38 #include <string>
39 
40 namespace nc
41 {
42  //============================================================================
43  // Method Description:
57  template<typename dtype>
58  double hypot(dtype inValue1, dtype inValue2) noexcept
59  {
61 
62  return std::sqrt(utils::sqr(static_cast<double>(inValue1)) +
63  utils::sqr(static_cast<double>(inValue2)));
64  }
65 
66  //============================================================================
67  // Method Description:
82  template<typename dtype>
83  double hypot(dtype inValue1, dtype inValue2, dtype inValue3) noexcept
84  {
86 
87  return std::sqrt(utils::sqr(static_cast<double>(inValue1)) +
88  utils::sqr(static_cast<double>(inValue2)) +
89  utils::sqr(static_cast<double>(inValue3)));
90  }
91 
92  //============================================================================
93  // Method Description:
107  template<typename dtype>
108  NdArray<double> hypot(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
109  {
110  if (inArray1.shape() != inArray2.shape())
111  {
112  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
113  }
114 
115  NdArray<dtype> returnArray(inArray1.shape());
116 
117  stl_algorithms::transform(inArray1.cbegin(), inArray1.cend(), inArray2.cbegin(), returnArray.begin(),
118  [](dtype inValue1, dtype inValue2) noexcept -> double
119  {
120  return hypot(inValue1, inValue2);
121  });
122 
123  return returnArray;
124  }
125 } // namespace nc
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::sqrt
auto sqrt(dtype inValue) noexcept
Definition: sqrt.hpp:51
nc::NdArray< double >
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:703
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
nc::hypot
double hypot(dtype inValue1, dtype inValue2) noexcept
Definition: hypot.hpp:58
nc
Definition: Coordinate.hpp:45
sqr.hpp
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
nc::utils::sqr
constexpr dtype sqr(dtype inValue) noexcept
Definition: sqr.hpp:45
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091