NumCpp  2.5.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
allclose.hpp
Go to the documentation of this file.
1 #pragma once
29 
32 #include "NumCpp/Functions/abs.hpp"
33 #include "NumCpp/Functions/all.hpp"
34 #include "NumCpp/NdArray.hpp"
35 
36 #include <cmath>
37 #include <string>
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
54  template<typename dtype>
55  bool allclose(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2, double inTolerance = 1e-5)
56  {
58 
59  if (inArray1.shape() != inArray2.shape())
60  {
61  THROW_INVALID_ARGUMENT_ERROR("input array dimensions are not consistant.");
62  }
63 
64  for (uint32 i = 0; i < inArray1.size(); ++i)
65  {
66  if (std::abs(inArray1[i] - inArray2[i]) > inTolerance)
67  {
68  return false;
69  }
70  }
71 
72  return true;
73  }
74 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
size_type size() const noexcept
Definition: NdArrayCore.hpp:4497
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4483
constexpr double e
eulers number
Definition: Constants.hpp:41
Definition: Coordinate.hpp:45
auto abs(dtype inValue) noexcept
Definition: abs.hpp:51
bool allclose(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2, double inTolerance=1e-5)
Definition: allclose.hpp:55
std::uint32_t uint32
Definition: Types.hpp:40