Testing

Contents

Testing#

Testing utilities for Nabla arrays.

nabla.utils.testing.allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]#

Returns True if two arrays are element-wise equal within a tolerance.

This function automatically converts Nabla Arrays to numpy arrays using .to_numpy() before comparison, providing a convenient way to compare Nabla arrays with each other or with numpy arrays/scalars.

Parameters:
  • a (Array | <MagicMock id='140511747871600'> | float | int) – Input array or scalar

  • b (Array | <MagicMock id='140511746858432'> | float | int) – Input array or scalar

  • rtol (float) – Relative tolerance parameter

  • atol (float) – Absolute tolerance parameter

  • equal_nan (bool) – Whether to compare NaN’s as equal

Returns:

True if the arrays are equal within the given tolerance

Return type:

bool

Examples

>>> import nabla as nb
>>> a = nb.array([1.0, 2.0, 3.0])
>>> b = nb.array([1.0, 2.0, 3.000001])
>>> nb.allclose(a, b)
True
>>> nb.allclose(a, np.array([1.0, 2.0, 3.0]))
True