Skip to content

Commit

Permalink
Fix concatenation of zero dim states (#229)
Browse files Browse the repository at this point in the history
* fix

* changelog

Co-authored-by: Jirka Borovec <[email protected]>
  • Loading branch information
SkafteNicki and Borda authored May 5, 2021
1 parent b75beea commit 33864db
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
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

0 comments on commit 33864db

Please sign in to comment.