NumCpp  2.9.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
isclose.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <cmath>
31 #include <string>
32 
36 #include "NumCpp/NdArray.hpp"
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
57  template<typename dtype>
59  const NdArray<dtype>& inArray2,
60  double inRtol = 1e-05,
61  double inAtol = 1e-08)
62  {
63  STATIC_ASSERT_FLOAT(dtype);
64 
65  if (inArray1.shape() != inArray2.shape())
66  {
67  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
68  }
69 
70  NdArray<bool> returnArray(inArray1.shape());
72  inArray1.cend(),
73  inArray2.cbegin(),
74  returnArray.begin(),
75  [inRtol, inAtol](dtype inValueA, dtype inValueB) noexcept -> bool
76  { return std::abs(inValueA - inValueB) <= (inAtol + inRtol * std::abs(inValueB)); });
77 
78  return returnArray;
79  }
80 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:45
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1221
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4092
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1529
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
constexpr double e
eulers number
Definition: Constants.hpp:41
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:784
Definition: Coordinate.hpp:45
NdArray< bool > isclose(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2, double inRtol=1e-05, double inAtol=1e-08)
Definition: isclose.hpp:58