Skip to content

[compiler] fix ndarray broadcasting with 0 sizes - #13751

Merged
danking merged 1 commit into
hail-is:mainfrom
patrick-schultz:empty-ndarray-fix
Oct 27, 2023
Merged

[compiler] fix ndarray broadcasting with 0 sizes#13751
danking merged 1 commit into
hail-is:mainfrom
patrick-schultz:empty-ndarray-fix

Conversation

@patrick-schultz

Copy link
Copy Markdown
Member

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.

@ehigham ehigham left a comment

Copy link
Copy Markdown
Member

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

danking commented Oct 26, 2023

Copy link
Copy Markdown
Contributor

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