Skip to content

Add support for np.broadcast_arrays - #7660

Merged
sklam merged 14 commits into
numba:mainfrom
guilhermeleobas:guilhermeleobas/np-broadcast_arrays
Apr 1, 2022
Merged

sklam merged 14 commits into
numba:mainfrom
guilhermeleobas:guilhermeleobas/np-broadcast_arrays

Conversation

@guilhermeleobas

Copy link
Copy Markdown
Contributor

As title

@guilhermeleobas
guilhermeleobas force-pushed the guilhermeleobas/np-broadcast_arrays branch from bfe955a to a476255 Compare December 15, 2021 20:38
@guilhermeleobas
guilhermeleobas marked this pull request as ready for review December 16, 2021 17:07
@guilhermeleobas

Copy link
Copy Markdown
Contributor Author

PR is ready for review. @gmarkall, can you please change the label?

@stuartarchibald stuartarchibald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the patch, I've given this an initial review, the impl and testing look like they cover the use case broadcast_arrays() with one arg, but I think some refactoring could help further. Thanks again!

Comment thread numba/np/arrayobj.py Outdated
Comment thread numba/tests/test_array_manipulation.py
@stuartarchibald stuartarchibald added 4 - Waiting on author Waiting for author to respond to review Effort - medium Medium size effort needed and removed 3 - Ready for Review labels Jan 24, 2022
@guilhermeleobas

Copy link
Copy Markdown
Contributor Author

@stuartarchibald, when you have some time, can you update the label in this PR?

@stuartarchibald stuartarchibald added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 4 - Waiting on author Waiting for author to respond to review labels Jan 28, 2022

@stuartarchibald stuartarchibald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the patch. I've given this an initial review to provide some feedback and have left this inline. Once addressed I'd like to take another look to see if there's any corner cases that are potentially missing as the tests equivalent to those from NumPy seem to cover a lot of things but there may be some Numba specific issues. Thanks again!

Comment thread numba/np/arrayobj.py Outdated
Comment thread numba/np/arrayobj.py
Comment thread numba/tests/test_array_manipulation.py
@stuartarchibald stuartarchibald added 4 - Waiting on author Waiting for author to respond to review and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Feb 1, 2022
@guilhermeleobas

Copy link
Copy Markdown
Contributor Author

@stuartarchibald, when you have some time, can you update the label in this PR?

@stuartarchibald stuartarchibald removed the 4 - Waiting on author Waiting for author to respond to review label Feb 7, 2022
@stuartarchibald stuartarchibald added the 4 - Waiting on reviewer Waiting for reviewer to respond to author label Feb 7, 2022

@stuartarchibald stuartarchibald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the updates @guilhermeleobas. I've made a couple more remarks in relation to what is supported/not supported, please could you take a look? Many thanks.

Comment thread numba/np/arrayobj.py Outdated
Comment thread numba/np/arrayobj.py Outdated
@stuartarchibald stuartarchibald added 4 - Waiting on author Waiting for author to respond to review and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Feb 18, 2022

@stuartarchibald stuartarchibald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the update. There seems to be a remaining issue with handling tuples but otherwise this looks good.

Comment thread numba/np/arrayobj.py
Comment on lines +1425 to +1429
for idx, arg in enumerate(args):
if isinstance(arg, types.ArrayCompatible):
m = max(m, arg.ndim)
elif isinstance(arg, (types.Number, types.Boolean)):
m = max(m, 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This unfortunately doesn't work:

from numba import njit
import numpy as np

@njit
def foo(tupl):
    return np.broadcast_arrays(tupl, tupl)

print(foo((1,2)))

I think the issue is that this loop is not handling tuple types? Probably needs something like:

        elif isinstance(arg, types.BaseTuple):
            m = max(m, arg.count)

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@guilhermeleobas

Copy link
Copy Markdown
Contributor Author

Failure is not related to the changes introduced in this PR.

@stuartarchibald stuartarchibald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the update. One minor style alignment issue to fix, then will mark for merge.

Comment thread numba/tests/test_array_manipulation.py Outdated
Co-authored-by: stuartarchibald <stuartarchibald@users.noreply.github.com>
@guilhermeleobas

Copy link
Copy Markdown
Contributor Author

@stuartarchibald done!

@esc esc added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 4 - Waiting on author Waiting for author to respond to review labels Mar 30, 2022

@stuartarchibald stuartarchibald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the patch and fixes.

@stuartarchibald stuartarchibald added 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Mar 30, 2022
@sklam
sklam merged commit 55361c7 into numba:main Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to merge Review and testing done, is ready to merge Effort - medium Medium size effort needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants