Main functions¶
Comparison¶
coola.objects_are_allclose ¶
objects_are_allclose(
actual: Any,
expected: Any,
*,
rtol: float = 1e-05,
atol: float = 1e-08,
equal_nan: bool = False,
show_difference: bool = False,
tester: BaseEqualityTester | None = None
) -> bool
Indicate if two objects are equal within a tolerance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
actual
|
Any
|
The actual input. |
required |
expected
|
Any
|
The expected input. |
required |
rtol
|
float
|
The relative tolerance parameter. |
1e-05
|
atol
|
float
|
The absolute tolerance parameter. |
1e-08
|
equal_nan
|
bool
|
If |
False
|
show_difference
|
bool
|
If |
False
|
tester
|
BaseEqualityTester | None
|
The equality tester. If |
None
|
Returns:
Type | Description |
---|---|
bool
|
|
Example usage:
>>> import torch
>>> from coola import objects_are_allclose
>>> objects_are_allclose(
... [torch.ones(2, 3), torch.zeros(2)],
... [torch.ones(2, 3), torch.zeros(2)],
... )
True
>>> objects_are_allclose(
... [torch.ones(2, 3), torch.ones(2)],
... [torch.ones(2, 3), torch.zeros(2)],
... )
False
>>> objects_are_allclose(
... [torch.ones(2, 3) + 1e-7, torch.ones(2)],
... [torch.ones(2, 3), torch.ones(2) - 1e-7],
... rtol=0,
... atol=1e-8,
... )
False
coola.objects_are_equal ¶
objects_are_equal(
actual: Any,
expected: Any,
*,
equal_nan: bool = False,
show_difference: bool = False,
tester: BaseEqualityTester | None = None
) -> bool
Indicate if two objects are equal or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
actual
|
Any
|
The actual input. |
required |
expected
|
Any
|
The expected input. |
required |
equal_nan
|
bool
|
If |
False
|
show_difference
|
bool
|
If |
False
|
tester
|
BaseEqualityTester | None
|
The equality tester. If |
None
|
Returns:
Type | Description |
---|---|
bool
|
|
Example usage:
>>> import torch
>>> from coola import objects_are_equal
>>> objects_are_equal(
... [torch.ones(2, 3), torch.zeros(2)],
... [torch.ones(2, 3), torch.zeros(2)],
... )
True
>>> objects_are_equal([torch.ones(2, 3), torch.ones(2)], [torch.ones(2, 3), torch.zeros(2)])
False
Summary¶
coola.summary ¶
summary(
value: Any,
max_depth: int = 1,
summarizer: BaseSummarizer | None = None,
) -> str
Summarize the input value in a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Any
|
The value to summarize. |
required |
max_depth
|
int
|
The maximum depth to summarize if the input is nested. |
1
|
summarizer
|
BaseSummarizer | None
|
The summarization strategy. If |
None
|
Returns:
Type | Description |
---|---|
str
|
The summary as a string. |
Example usage:
>>> from coola import summary
>>> print(summary(1))
<class 'int'> 1
>>> print(summary(["abc", "def"]))
<class 'list'> (length=2)
(0): abc
(1): def
>>> print(summary([[0, 1, 2], {"key1": "abc", "key2": "def"}]))
<class 'list'> (length=2)
(0): [0, 1, 2]
(1): {'key1': 'abc', 'key2': 'def'}
>>> print(summary([[0, 1, 2], {"key1": "abc", "key2": "def"}], max_depth=2))
<class 'list'> (length=2)
(0): <class 'list'> (length=3)
(0): 0
(1): 1
(2): 2
(1): <class 'dict'> (length=2)
(key1): abc
(key2): def
coola.summarizer_options ¶
summarizer_options(**kwargs: Any) -> None
Context manager that temporarily changes the summarizer options.
Accepted arguments are same as set_summarizer_options
.
The context manager temporary change the configuration of
Summarizer
. This context manager has no effect if
Summarizer
is not used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Any
|
Accepted arguments are same as
|
{}
|
Example usage:
>>> from coola import summarizer_options, summary
>>> print(summary("abcdefghijklmnopqrstuvwxyz"))
<class 'str'> abcdefghijklmnopqrstuvwxyz
>>> with summarizer_options(max_characters=10):
... print(summary("abcdefghijklmnopqrstuvwxyz"))
...
<class 'str'> abcdefghij...
>>> print(summary("abcdefghijklmnopqrstuvwxyz"))
<class 'str'> abcdefghijklmnopqrstuvwxyz
coola.set_summarizer_options ¶
set_summarizer_options(
max_characters: int | None = None,
max_items: int | None = None,
num_spaces: int | None = None,
) -> None
Set the Summarizer
options.
Note: It is recommended to use summarizer_options
rather than
this function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_characters
|
int | None
|
The maximum number of characters
to show. If |
None
|
max_items
|
int | None
|
The maximum number of items to show.
If |
None
|
num_spaces
|
int | None
|
The number of spaces for indentation.
If |
None
|
Example usage:
>>> from coola import set_summarizer_options, summary
>>> print(summary("abcdefghijklmnopqrstuvwxyz"))
<class 'str'> abcdefghijklmnopqrstuvwxyz
>>> set_summarizer_options(max_characters=10)
>>> print(summary("abcdefghijklmnopqrstuvwxyz"))
<class 'str'> abcdefghij...
>>> set_summarizer_options(max_characters=-1)
>>> print(summary("abcdefghijklmnopqrstuvwxyz"))
<class 'str'> abcdefghijklmnopqrstuvwxyz