NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
allclose.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cmath>
31
34#include "NumCpp/NdArray.hpp"
35
36namespace nc
37{
38 //============================================================================
39 // Method Description:
50 template<typename dtype>
51 bool allclose(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2, double inTolerance = 1e-5)
52 {
54
55 if (inArray1.shape() != inArray2.shape())
56 {
57 THROW_INVALID_ARGUMENT_ERROR("input array dimensions are not consistant.");
58 }
59
60 for (uint32 i = 0; i < inArray1.size(); ++i)
61 {
62 if (std::abs(inArray1[i] - inArray2[i]) > inTolerance)
63 {
64 return false;
65 }
66 }
67
68 return true;
69 }
70} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
size_type size() const noexcept
Definition NdArrayCore.hpp:4600
const Shape & shape() const noexcept
Definition NdArrayCore.hpp:4587
Definition Cartesian.hpp:39
bool allclose(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2, double inTolerance=1e-5)
Definition allclose.hpp:51
std::uint32_t uint32
Definition Types.hpp:40