Skip to content

[compiler] fix ndarray broadcasting with 0 sizes #13751

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

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

patrick-schultz
Copy link
Collaborator

Really bad example:

In [2]: a = hl.nd.array(2)

In [3]: empty = np.array([], np.int32).reshape((0, 2, 2))

In [4]: empty = hl.nd.array(empty)

In [5]: hl.eval(empty)
Out[5]: array([], shape=(0, 2, 2), dtype=int32)

In [6]: hl.eval(a + empty)
Out[6]:
array([[[       2, 55622722],
        [       2,        3]]], dtype=int32)

Result of sum of shape () with shape (0, 2, 2) should be shape (0, 2, 2) by standard numpy broadcasting rules. Instead, we try to produce a result with shape (1, 2, 2), which contains garbage data.

Copy link
Member

@ehigham ehigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great. glad to see tests enabled!

@danking danking added the WIP label Oct 26, 2023
@danking
Copy link
Contributor

danking commented Oct 26, 2023

WIP until I sort the release.

@danking danking merged commit 75ee439 into hail-is:main Oct 27, 2023
@patrick-schultz patrick-schultz deleted the empty-ndarray-fix branch January 2, 2025 13:45
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.

4 participants