Home¶
Overview¶
coola is a Python library that provides simple functions to check in a single line if two
complex/nested objects are equal or not.
coola was initially designed to work
with PyTorch Tensors
and NumPy ndarray, but it
is possible to extend it to support other data structures.
Motivation¶
Let's imagine you have the following dictionaries that contain both a PyTorch Tensor and a
NumPy ndarray.
You want to check if the two dictionaries are equal or not.
By default, Python does not provide an easy way to check if the two dictionaries are equal or not.
It is not possible to use the default equality operator == because it will raise an error.
The coola library was developed to fill this gap. coola provides a function objects_are_equal
that can indicate if two complex/nested objects are equal or not.
>>> import numpy
>>> import torch
>>> from coola import objects_are_equal
>>> data1 = {"torch": torch.ones(2, 3), "numpy": numpy.zeros((2, 3))}
>>> data2 = {"torch": torch.zeros(2, 3), "numpy": numpy.ones((2, 3))}
>>> objects_are_equal(data1, data2)
False
coola also provides a function objects_are_allclose that can indicate if two complex/nested
objects are equal within a tolerance or not.
>>> import numpy
>>> import torch
>>> from coola import objects_are_allclose
>>> data1 = {"torch": torch.ones(2, 3), "numpy": numpy.zeros((2, 3))}
>>> data2 = {"torch": torch.zeros(2, 3), "numpy": numpy.ones((2, 3))}
>>> objects_are_allclose(data1, data2, atol=1e-6)
False
API stability¶
While
coola is in development stage, no API is guaranteed to be stable from one
release to the next. In fact, it is very likely that the API will change multiple times before a
stable 1.0.0 release. In practice, this means that upgrading coola to a new version will
possibly break any code that was using the old version of coola.
License¶
coola is licensed under BSD 3-Clause "New" or "Revised" license available
in LICENSE file.