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

Fix concatenation of zero dim states #229

Merged
merged 5 commits into from
May 5, 2021
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed metric calculation with unequal batch sizes ([#220](https://github.com/PyTorchLightning/metrics/pull/220))


- Fixed metric concatenation for list states for zero-dim input ([#229](https://github.com/PyTorchLightning/metrics/pull/229))


## [0.3.1] - 2021-04-21

- Cleaning remaining inconsistency and fix PL develop integration (
Expand Down
4 changes: 2 additions & 2 deletions torchmetrics/functional/regression/spearman.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def _spearman_corrcoef_update(preds: Tensor, target: Tensor) -> Tuple[Tensor, Te
f" Got preds: {preds.dtype} and target: {target.dtype}."
)
_check_same_shape(preds, target)

preds = preds.squeeze()
target = target.squeeze()
if preds.ndim > 1 or target.ndim > 1:
raise ValueError('Expected both predictions and target to be 1 dimensional tensors.')

return preds, target


Expand Down
7 changes: 4 additions & 3 deletions torchmetrics/utilities/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@
METRIC_EPS = 1e-6


def dim_zero_cat(x):
def dim_zero_cat(x: Union[Tensor, List[Tensor]]) -> Tensor:
x = x if isinstance(x, (list, tuple)) else [x]
x = [y.unsqueeze(0) if y.numel() == 1 and y.ndim == 0 else y for y in x]
return torch.cat(x, dim=0)


def dim_zero_sum(x):
def dim_zero_sum(x: Tensor) -> Tensor:
return torch.sum(x, dim=0)


def dim_zero_mean(x):
def dim_zero_mean(x: Tensor) -> Tensor:
return torch.mean(x, dim=0)


Expand Down