Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor patches #542

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cyclops/evaluate/metrics/experimental/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Metrics for arrays that conform to the python array API standard."""
"""Metrics for arrays that conform to the Python array API standard."""
from cyclops.evaluate.metrics.experimental.accuracy import (
BinaryAccuracy,
MulticlassAccuracy,
Expand Down
6 changes: 3 additions & 3 deletions cyclops/evaluate/metrics/experimental/functional/accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def binary_accuracy(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -216,7 +216,7 @@ def multiclass_accuracy(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -378,7 +378,7 @@ def multilabel_accuracy(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down
12 changes: 6 additions & 6 deletions cyclops/evaluate/metrics/experimental/functional/f_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def binary_fbeta_score(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -276,7 +276,7 @@ def multiclass_fbeta_score(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -468,7 +468,7 @@ def multilabel_fbeta_score(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -593,7 +593,7 @@ def binary_f1_score(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -692,7 +692,7 @@ def multiclass_f1_score(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -824,7 +824,7 @@ def multilabel_f1_score(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def binary_npv(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -200,7 +200,7 @@ def multiclass_npv(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -360,7 +360,7 @@ def multilabel_npv(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def binary_precision(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -206,7 +206,7 @@ def multiclass_precision(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -364,7 +364,7 @@ def multilabel_precision(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -478,7 +478,7 @@ def binary_recall(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -589,7 +589,7 @@ def multiclass_recall(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -750,7 +750,7 @@ def multilabel_recall(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def binary_specificity(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -199,7 +199,7 @@ def multiclass_specificity(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down Expand Up @@ -359,7 +359,7 @@ def multilabel_specificity(

Raises
------
ValueError
TypeError
If the arrays `target` and `preds` are not compatible with the Python
array API standard.
ValueError
Expand Down
5 changes: 3 additions & 2 deletions cyclops/evaluate/metrics/experimental/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def add_state_default_factory(
"""
if not name.isidentifier():
raise ValueError(
f"Argument `name` must be a valid python identifier. Got `{name}`.",
f"Argument `name` must be a valid Python identifier. Got `{name}`.",
)
if not callable(default_factory):
raise TypeError(
Expand Down Expand Up @@ -286,12 +286,13 @@ def update(self, *args: Any, **kwargs: Any) -> None:
"not yet be defined.",
)
xp = apc.get_namespace(*arrays)
self._add_states(xp)

# move state variables to device of first array
device = apc.device(arrays[0])
self.to_device(device)

self._add_states(xp)

self._computed = None
self._update_count += 1

Expand Down
2 changes: 1 addition & 1 deletion cyclops/evaluate/metrics/experimental/metric_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ArrayEncoder(json.JSONEncoder):
def default(self, obj: Any) -> Any:
"""Return a JSON-serializable representation of the object.

Objects conforming to the array API standard are converted to python lists
Objects conforming to the array API standard are converted to Python lists
via numpy. Arrays are moved to the CPU before converting to numpy.
"""
if apc.is_array_api_obj(obj):
Expand Down
4 changes: 2 additions & 2 deletions cyclops/evaluate/metrics/experimental/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@
) -> None:
"""Perform basic validation of `target` and `preds`."""
if not apc.is_array_api_obj(target):
raise ValueError(
raise TypeError(

Check warning on line 65 in cyclops/evaluate/metrics/experimental/utils/validation.py

View check run for this annotation

Codecov / codecov/patch

cyclops/evaluate/metrics/experimental/utils/validation.py#L65

Added line #L65 was not covered by tests
"Expected `target` to be an array-API-compatible object, but got "
f"{type(target)}.",
)

if not apc.is_array_api_obj(preds):
raise ValueError(
raise TypeError(

Check warning on line 71 in cyclops/evaluate/metrics/experimental/utils/validation.py

View check run for this annotation

Codecov / codecov/patch

cyclops/evaluate/metrics/experimental/utils/validation.py#L71

Added line #L71 was not covered by tests
"Expected `preds` to be an array-API-compatible object, but got "
f"{type(preds)}.",
)
Expand Down
2 changes: 1 addition & 1 deletion cyclops/models/wrappers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def set_params(cls, **params):


def set_random_seed(seed: int, deterministic: bool = False) -> None:
"""Set a random seed for python, numpy and PyTorch globally.
"""Set a random seed for Python, numpy and PyTorch globally.

Parameters
----------
Expand Down
4 changes: 2 additions & 2 deletions cyclops/report/model_card/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ def add_field(self, name: str, value: Any) -> None:
Raises
------
ValueError
If the field name is not a valid python identifier.
If the field name is not a valid Python identifier.

"""
if not name.isidentifier() or keyword.iskeyword(name):
raise ValueError(
f"Expected `field_name` to be a valid python identifier."
f"Expected `field_name` to be a valid Python identifier."
f" Got {name} instead.",
)

Expand Down
2 changes: 1 addition & 1 deletion tests/cyclops/evaluate/metrics/experimental/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def custom_fn(xp, _):

with pytest.raises(
ValueError,
match="Argument `name` must be a valid python identifier. Got `h6!`.",
match="Argument `name` must be a valid Python identifier. Got `h6!`.",
):
metric.add_state_default_factory("h6!", list) # type: ignore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_metrics_floordiv(second_operand, expected_result):
"""Test that `floordiv` operator works and returns an operator metric."""
first_metric = DummyMetric(
anp.asarray(
5, # python scalars can only be promoted with floating-point arrays
5, # Python scalars can only be promoted with floating-point arrays
dtype=anp.float32 if isinstance(second_operand, float) else None,
),
)
Expand All @@ -164,7 +164,7 @@ def test_metrics_ge(second_operand, expected_result):
"""Test that `ge` operator works and returns an operator metric."""
first_metric = DummyMetric(
anp.asarray(
5, # python scalars can only be promoted with floating-point arrays
5, # Python scalars can only be promoted with floating-point arrays
dtype=anp.float32 if isinstance(second_operand, float) else None,
),
)
Expand All @@ -189,7 +189,7 @@ def test_metrics_gt(second_operand, expected_result):
"""Test that `gt` operator works and returns an operator metric."""
first_metric = DummyMetric(
anp.asarray(
5, # python scalars can only be promoted with floating-point arrays
5, # Python scalars can only be promoted with floating-point arrays
dtype=anp.float32 if isinstance(second_operand, float) else None,
),
)
Expand Down Expand Up @@ -224,7 +224,7 @@ def test_metrics_le(second_operand, expected_result):
"""Test that `le` operator works and returns an operator metric."""
first_metric = DummyMetric(
anp.asarray(
5, # python scalars can only be promoted with floating-point arrays
5, # Python scalars can only be promoted with floating-point arrays
dtype=anp.float32 if isinstance(second_operand, float) else None,
),
)
Expand All @@ -249,7 +249,7 @@ def test_metrics_lt(second_operand, expected_result):
"""Test that `lt` operator works and returns an operator metric."""
first_metric = DummyMetric(
anp.asarray(
5, # python scalars can only be promoted with floating-point arrays
5, # Python scalars can only be promoted with floating-point arrays
dtype=anp.float32 if isinstance(second_operand, float) else None,
),
)
Expand Down Expand Up @@ -292,7 +292,7 @@ def test_metrics_mod(second_operand, expected_result):
"""Test that `mod` operator works and returns an operator metric."""
first_metric = DummyMetric(
anp.asarray(
5, # python scalars can only be promoted with floating-point arrays
5, # Python scalars can only be promoted with floating-point arrays
dtype=anp.float32 if isinstance(second_operand, float) else None,
),
)
Expand All @@ -317,7 +317,7 @@ def test_metrics_mul(second_operand, expected_result):
"""Test that `mul` operator works and returns an operator metric."""
first_metric = DummyMetric(
anp.asarray(
2, # python scalars can only be promoted with floating-point arrays
2, # Python scalars can only be promoted with floating-point arrays
dtype=anp.float32 if isinstance(second_operand, float) else None,
),
)
Expand Down Expand Up @@ -350,7 +350,7 @@ def test_metrics_ne(second_operand, expected_result):
"""Test that `!=` operator works and returns an operator metric."""
first_metric = DummyMetric(
anp.asarray(
2, # python scalars can only be promoted with floating-point arrays
2, # Python scalars can only be promoted with floating-point arrays
dtype=anp.float32 if isinstance(second_operand, float) else None,
),
)
Expand Down
Loading