NumCpp
2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
allclose.hpp
Go to the documentation of this file.
1
#pragma once
29
30
#include "
NumCpp/Core/Internal/Error.hpp
"
31
#include "
NumCpp/Core/Internal/StaticAsserts.hpp
"
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 = 1
e
-5)
56
{
57
STATIC_ASSERT_ARITHMETIC
(dtype);
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
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition:
NdArrayCore.hpp:4356
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition:
StaticAsserts.hpp:37
abs.hpp
nc::NdArray< dtype >
nc::constants::e
constexpr double e
eulers number
Definition:
Constants.hpp:41
nc::uint32
std::uint32_t uint32
Definition:
Types.hpp:40
NdArray.hpp
nc::NdArray::size
size_type size() const noexcept
Definition:
NdArrayCore.hpp:4370
nc::allclose
bool allclose(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2, double inTolerance=1e-5)
Definition:
allclose.hpp:55
nc
Definition:
Coordinate.hpp:44
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition:
Error.hpp:36
all.hpp
nc::abs
auto abs(dtype inValue) noexcept
Definition:
abs.hpp:51
include
NumCpp
Functions
allclose.hpp
Generated by
1.8.17