Skip to content
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

Support for np.roll #3563

Merged
merged 5 commits into from Jan 8, 2019
Merged

Support for np.roll #3563

merged 5 commits into from Jan 8, 2019

Conversation

rjenc29
Copy link
Contributor

@rjenc29 rjenc29 commented Dec 5, 2018

Initial commit for CI.

@rjenc29
Copy link
Contributor Author

rjenc29 commented Dec 6, 2018

I think the CI failure is unrelated; I reckon it would pass on retry.

I have implemented the first two (mandatory) arguments.

Let me know what you think if you get a mo.

@rjenc29 rjenc29 changed the title [WIP] Support for np.roll Support for np.roll Dec 6, 2018
@codecov-io
Copy link

codecov-io commented Dec 6, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@62d9a79). Click here to learn what that means.
The diff coverage is 82.6%.

@@            Coverage Diff            @@
##             master    #3563   +/-   ##
=========================================
  Coverage          ?   80.49%           
=========================================
  Files             ?      395           
  Lines             ?    81347           
  Branches          ?     9261           
=========================================
  Hits              ?    65479           
  Misses            ?    14437           
  Partials          ?     1431

Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. In general the implementation etc looks good. I've made a few minor comments, once addressed this should be good to merge. Thanks again.

@@ -292,6 +292,7 @@ The following top-level functions are supported:
* :func:`numpy.partition` (only the 2 first arguments)
* :func:`numpy.ravel` (no order argument; 'C' order only)
* :func:`numpy.reshape` (no order argument; 'C' order only)
* :func:`numpy.roll` (only the 2 first arguments)
Copy link
Contributor

Choose a reason for hiding this comment

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

Whilst implied by lack of axis support, perhaps this should also explicitly mention that only integer value for shift is supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

yield np.array([])
yield (9,)
yield np.asfortranarray(np.array([[1.1, np.nan], [np.inf, 7.8]]))
yield np.array([])
Copy link
Contributor

Choose a reason for hiding this comment

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

this input is duplicated from about 3 lines up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

raise TypingError('shift must be an integer')

def np_roll_impl(a, shift):
arr = _asarray(a)
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like this makes scalar inputs into arrays, but then this is not converted back to a scalar on return? e.g.

from numba import njit
import numpy as np

z = 1
def foo(z):
    ff = np.roll(z, 1)
    return ff

expect = foo(z)
got = njit(foo)(z)

print(type(expect), expect.ndim, expect)
print(type(got), got.ndim, got)
np.testing.assert_allclose(got, expect)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bah - it's a 0D array regardless of shift.

I thought this would be a one-liner but my tests fail depending on what order I run them in, which I appreciate is somewhat suboptimal :)

Here's a simple repro:

from numba import njit
from numba.extending import overload, types
import numpy as np


def foo(a, shift):
    pass


@overload(foo)
def foo_impl(a, shift):

    def foo_impl_0d(a, shift):
        return np.array(a)

    if isinstance(a, (types.Boolean, types.Number)):
        return foo_impl_0d

@njit
def foo_quickly(a, shift):
    return foo(a, shift)


def check_stuff(a_values):
    for idx, a in enumerate(a_values):
        got = foo_quickly(a, 1).item(0)
        assert got is a, 'got {0} but expected {1}'.format(got, a)


if __name__ == '__main__':

    # this passes
    check_stuff([False, True])
    check_stuff([0, 1])

    # comment out the above and un-comment the below: fails
    # check_stuff([0, 1])
    # check_stuff([False, True])

Per the comments, the assertions pass if I run the tests in one order, but fail if I switch the order.

If you inspect the signatures of foo_quickly then the former case ends up with [(bool, int64), (int64, int64)] whilst the latter only has [(int64, int64)]).

Have I made some festive mishap?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs #3612

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I simply swapped the test order - #3612 would mean I didn't have to, but I figured just as easy to order the tests.

@stuartarchibald stuartarchibald added 4 - Waiting on author Waiting for author to respond to review and removed 3 - Ready for Review labels Dec 11, 2018
@rjenc29
Copy link
Contributor Author

rjenc29 commented Dec 11, 2018

Thanks vm for the review - I will address these points asap

@seibert seibert added this to In Progress in Active Dec 11, 2018
@stuartarchibald stuartarchibald moved this from In Progress to Reviewed... discussion/fixes taking place in Active Dec 20, 2018
@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 Dec 27, 2018
@stuartarchibald
Copy link
Contributor

Think that this needs a conflict resolve and then perhaps a sprinkling of np.asarray now that that is working?

@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 Jan 3, 2019
@rjenc29
Copy link
Contributor Author

rjenc29 commented Jan 3, 2019

Yep, leave it with me (the same is probably true of most / all of my other PRs). I will ping you once done.

@stuartarchibald stuartarchibald added 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on author Waiting for author to respond to review labels Jan 7, 2019
@seibert seibert merged commit bf692cf into numba:master Jan 8, 2019
Active automation moved this from Reviewed... discussion/fixes taking place to Done Jan 8, 2019
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
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants