Skip to content

BUG: ensure out=None is never passed on to __array_ufunc__. - #12

Merged
charris merged 1 commit into
charris:enable-numpy_ufuncfrom
mhvk:ufunc-override-out-none-fix
Apr 5, 2017
Merged

charris merged 1 commit into
charris:enable-numpy_ufuncfrom
mhvk:ufunc-override-out-none-fix

Conversation

@mhvk

@mhvk mhvk commented Apr 4, 2017

Copy link
Copy Markdown

A fix to a problem pointed out by @eric-wieser, where a single None could end up being present in the out keyword argument. I think this is fine to just merge (it adds some tests too).

Comment thread numpy/core/tests/test_umath.py Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

np.modf(a, out=None) would be good here too

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I haven't included that since it is deprecated to give an explicit out argument which is not a tuple for nout=2:

In [2]: np.modf(1., out=None)
/usr/bin/ipython3:1: DeprecationWarning: passing a single array to the 'out' keyword argument of a ufunc with
more than one output will result in an error in the future

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Until it's removed, I think that we need to continue to support it, which includes having a test-case here.

Comment thread numpy/core/tests/test_umath.py Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does np.modf(a, b) get normalized to __array_ufunc__(..., out=(b, None)) here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, the tuple is guaranteed to have the right number of elements.

@mhvk
mhvk force-pushed the ufunc-override-out-none-fix branch from f34fb60 to 9e7a318 Compare April 5, 2017 00:47
@mhvk

mhvk commented Apr 5, 2017

Copy link
Copy Markdown
Author

@eric-wieser - well, that little comment of yours triggered a big avalanche: turns out there was very little checking that arguments were in fact correct. This was code from before I started to work on it, and I had hoped to leave it alone... Anyway, this now is a substantially larger PR, with a lot of extra tests; I hope you can have another look...

Comment thread numpy/core/src/private/ufunc_override.c Outdated

@eric-wieser eric-wieser Apr 5, 2017 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What am I missing here - can't we use ufunc->nin and ->nout?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not as long as we're passing np.dot and np.matmul through here... I think I should start collecting to-do clean-up items...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added this to numpy#8892

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If we're passing non-ufuncs in, then we should change the signature to PyObject* to make it clear that no properties can be depended on.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm going to add a big warning note for now: this is outside of the scope of this should-have-been-small fix -- but I'll also mention it as a possible issue in the main thread.

@eric-wieser eric-wieser Apr 5, 2017 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm somewhat concerned that upcasting a pointer is allowed to (although practically, will not) invoke undefined behaviour in a C compiler, so I think it's very important we change that to PyObject* until we work out a better way to indicate matmul and dot

@charris
charris force-pushed the enable-numpy_ufunc branch from 9e159d9 to ffc836a Compare April 5, 2017 10:30
@charris

charris commented Apr 5, 2017

Copy link
Copy Markdown
Owner

Why are there 18 commits here? Looks like a merge was done instead of a rebase.

@mhvk

mhvk commented Apr 5, 2017

Copy link
Copy Markdown
Author

I think this is because #11 was merged. Anyway, I'll fix.

As part of this, it turns out the number of output arguments nout
was needed, so that was passed in. Also, testing showed that arguments
passed in both as positional and keyword arguments were not caught,
so a duplication check was added.
@mhvk
mhvk force-pushed the ufunc-override-out-none-fix branch from 9e7a318 to 63c911d Compare April 5, 2017 13:39
@mhvk

mhvk commented Apr 5, 2017

Copy link
Copy Markdown
Author

OK, the rebase -i immediately gave me a single commit; not sure why github thought it needed so many.

@charris

charris commented Apr 5, 2017 •

Copy link
Copy Markdown
Owner

I think what happened is that I rebased the main PR after merging #11.

@charris
charris merged this pull request into charris:enable-numpy_ufunc Apr 5, 2017
@charris

charris commented Apr 5, 2017

Copy link
Copy Markdown
Owner

Let's get it all together, thanks Marten.

@mhvk
mhvk deleted the ufunc-override-out-none-fix branch April 5, 2017 15:27
charris pushed a commit that referenced this pull request Nov 21, 2021
commit 9c833bed5879d77e625556260690c349de18b433
Author: Thomas Li <[email protected]>
Date:   Wed Nov 17 16:21:27 2021 -0800

    Add Windows config to GHA

    update script [wheel build]

    typo [wheel build]

    fix typo? [wheel build]

    fix linux builds? [wheel build]

    typo [wheel build]

    add license and pin to windows 2016

    skip tests [wheel build]

    pin to windows 2019 instead [wheel build]

    try to find out the error on windows [wheel build]

    maybe fix? [wheel build]

    maybe fix? [wheel build]

    fix? [wheel build]

    cleanup [wheel build]

    Add Windows config to GHA

    update script [wheel build]

    typo [wheel build]

    fix typo? [wheel build]

    fix linux builds? [wheel build]

    typo [wheel build]

    add license and pin to windows 2016

    skip tests [wheel build]

    pin to windows 2019 instead [wheel build]

    try to find out the error on windows [wheel build]

    maybe fix? [wheel build]

    maybe fix? [wheel build]

    fix? [wheel build]

    cleanup [wheel build]

    Update LICENSE_win32.txt

    Update LICENSE_win32.txt

    Add Windows config to GHA

    update script [wheel build]

    typo [wheel build]

    fix typo? [wheel build]

    fix linux builds? [wheel build]

    typo [wheel build]

    add license and pin to windows 2016

    skip tests [wheel build]

    pin to windows 2019 instead [wheel build]

    try to find out the error on windows [wheel build]

    maybe fix? [wheel build]

    maybe fix? [wheel build]

    fix? [wheel build]

    cleanup [wheel build]

    Update LICENSE_win32.txt

    Update LICENSE_win32.txt

    Update cibw_test_command.sh

commit 4bd12df
Author: Thomas Li <[email protected]>
Date:   Mon Nov 15 17:28:47 2021 -0800

    # This is a combination of 14 commits.
    # This is the 1st commit message:

    Add Windows config to GHA
    # This is the commit message #2:

    update script [wheel build]
    # This is the commit message #3:

    typo [wheel build]
    # This is the commit message #4:

    fix typo? [wheel build]
    # This is the commit message #5:

    fix linux builds? [wheel build]
    # This is the commit message #6:

    typo [wheel build]
    # This is the commit message #7:

    add license and pin to windows 2016
    # This is the commit message #8:

    skip tests [wheel build]
    # This is the commit message #9:

    pin to windows 2019 instead [wheel build]
    # This is the commit message #10:

    try to find out the error on windows [wheel build]
    # This is the commit message #11:

    maybe fix? [wheel build]
    # This is the commit message #12:

    maybe fix? [wheel build]
    # This is the commit message #13:

    fix? [wheel build]
    # This is the commit message #14:

    cleanup [wheel build]
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.

3 participants