Skip to content

Fix calculation of number of elements in tensor for Size([]) tensors - #1

Open
dvmazur wants to merge 1 commit into
dominik-schwabe:mainfrom
dvmazur:main
Open

Fix calculation of number of elements in tensor for Size([]) tensors#1
dvmazur wants to merge 1 commit into
dominik-schwabe:mainfrom
dvmazur:main

Conversation

@dvmazur

@dvmazur dvmazur commented Nov 13, 2025

Copy link
Copy Markdown

Hi, Dominik!

Thanks for your work on the library!

I was playing around with pydantic-tensor and found and edge case related to the calculation of the number of elements in a tensor. In PyTorch it is possible to have a []-shaped tensor (torch.tensor(0)), not to be confused with a [0]-shaped one (torch.tensor([]))! The latter case is handled correctly, but the former triggers a ValueError when reduce is applied over the empty iterator.

The fix is quite simple as you can see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant