NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
allclose.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cmath>
31#include <string>
32
37#include "NumCpp/NdArray.hpp"
38
39namespace nc
40{
41 //============================================================================
42 // Method Description:
53 template<typename dtype>
54 bool allclose(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2, double inTolerance = 1e-5)
55 {
57
58 if (inArray1.shape() != inArray2.shape())
59 {
60 THROW_INVALID_ARGUMENT_ERROR("input array dimensions are not consistant.");
61 }
62
63 for (uint32 i = 0; i < inArray1.size(); ++i)
64 {
65 if (std::abs(inArray1[i] - inArray2[i]) > inTolerance)
66 {
67 return false;
68 }
69 }
70
71 return true;
72 }
73} // 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:139
size_type size() const noexcept
Definition: NdArrayCore.hpp:4524
const Shape & shape() const noexcept
Definition: NdArrayCore.hpp:4511
constexpr double e
eulers number
Definition: Core/Constants.hpp:37
Definition: Cartesian.hpp:40
auto abs(dtype inValue) noexcept
Definition: abs.hpp:49
bool allclose(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2, double inTolerance=1e-5)
Definition: allclose.hpp:54
std::uint32_t uint32
Definition: Types.hpp:40