NumCpp  2.4.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 
33 #include "NumCpp/NdArray.hpp"
34 
35 #include <cmath>
36 #include <string>
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
58  template<typename dtype>
59  NdArray<bool> isclose(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2, double inRtol = 1e-05, double inAtol = 1e-08)
60  {
61  STATIC_ASSERT_FLOAT(dtype);
62 
63  if (inArray1.shape() != inArray2.shape())
64  {
65  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
66  }
67 
68  NdArray<bool> returnArray(inArray1.shape());
69  stl_algorithms::transform(inArray1.cbegin(), inArray1.cend(), inArray2.cbegin(), returnArray.begin(),
70  [inRtol, inAtol](dtype inValueA, dtype inValueB) noexcept -> bool
71  {
72  return std::abs(inValueA - inValueB) <= (inAtol + inRtol * std::abs(inValueB));
73  });
74 
75  return returnArray;
76  }
77 } // namespace nc
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4356
Error.hpp
nc::NdArray< bool >
nc::constants::e
constexpr double e
eulers number
Definition: Constants.hpp:41
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
NdArray.hpp
STATIC_ASSERT_FLOAT
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:43
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1487
nc
Definition: Coordinate.hpp:44
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:1143
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1087
nc::isclose
NdArray< bool > isclose(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2, double inRtol=1e-05, double inAtol=1e-08)
Definition: isclose.hpp:59