NumCpp  2.1.0
A C++ implementation of the Python Numpy library
isclose.hpp
Go to the documentation of this file.
1 #pragma once
30 
34 #include "NumCpp/NdArray.hpp"
35 
36 #include <cmath>
37 #include <string>
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
59  template<typename dtype>
60  NdArray<bool> isclose(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2, double inRtol = 1e-05, double inAtol = 1e-08)
61  {
62  STATIC_ASSERT_FLOAT(dtype);
63 
64  if (inArray1.shape() != inArray2.shape())
65  {
66  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
67  }
68 
69  NdArray<bool> returnArray(inArray1.shape());
70  stl_algorithms::transform(inArray1.cbegin(), inArray1.cend(), inArray2.cbegin(), returnArray.begin(),
71  [inRtol, inAtol](dtype inValueA, dtype inValueB) noexcept -> bool
72  {
73  return std::abs(inValueA - inValueB) <= (inAtol + inRtol * std::abs(inValueB));
74  });
75 
76  return returnArray;
77  }
78 } // namespace nc
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
Error.hpp
nc::NdArray< bool >
nc::constants::e
constexpr double e
eulers number
Definition: Constants.hpp:42
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:703
NdArray.hpp
STATIC_ASSERT_FLOAT
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:44
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
nc
Definition: Coordinate.hpp:45
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
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091
nc::isclose
NdArray< bool > isclose(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2, double inRtol=1e-05, double inAtol=1e-08)
Definition: isclose.hpp:60