NumCpp  2.1.0
A C++ implementation of the Python Numpy library
allclose.hpp
Go to the documentation of this file.
1 #pragma once
30 
33 #include "NumCpp/Functions/abs.hpp"
34 #include "NumCpp/Functions/all.hpp"
35 #include "NumCpp/NdArray.hpp"
36 
37 #include <cmath>
38 #include <string>
39 
40 namespace nc
41 {
42  //============================================================================
43  // Method Description:
55  template<typename dtype>
56  bool allclose(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2, double inTolerance = 1e-5)
57  {
59 
60  if (inArray1.shape() != inArray2.shape())
61  {
62  THROW_INVALID_ARGUMENT_ERROR("input array dimensions are not consistant.");
63  }
64 
65  for (uint32 i = 0; i < inArray1.size(); ++i)
66  {
67  if (std::abs(inArray1[i] - inArray2[i]) > inTolerance)
68  {
69  return false;
70  }
71  }
72 
73  return true;
74  }
75 } // 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
abs.hpp
nc::NdArray< dtype >
nc::constants::e
constexpr double e
eulers number
Definition: Constants.hpp:42
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
NdArray.hpp
nc::NdArray::size
size_type size() const noexcept
Definition: NdArrayCore.hpp:4326
nc::allclose
bool allclose(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2, double inTolerance=1e-5)
Definition: allclose.hpp:56
nc
Definition: Coordinate.hpp:45
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
all.hpp
nc::abs
auto abs(dtype inValue) noexcept
Definition: abs.hpp:52