-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: add support for array-likes in polynomial evaluation #18662
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is logical, but see in-line for potential problems and a suggested solution. Regardless, it would be good to add tests with a list and masked array.
@@ -479,6 +479,7 @@ def __setstate__(self, dict): | |||
|
|||
def __call__(self, arg): | |||
off, scl = pu.mapparms(self.domain, self.window) | |||
arg = np.asarray(arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this, previously working calls using masked arrays would stop working - e.g.,
np.polynomial.Polynomial([1, 2])(np.ma.MaskedArray([3, 4], mask=[True, False]))
That particular part could be solved by making this np.asanyarray
- though I guess it is possible the polynomials are also used by, e.g., dask, in which case this would still be a problem.
@@ -479,6 +479,7 @@ def __setstate__(self, dict): | |||
|
|||
def __call__(self, arg): | |||
off, scl = pu.mapparms(self.domain, self.window) | |||
arg = np.asarray(arg) | |||
arg = off + scl*arg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simpler way to do the same thing might be to make sure scl
is an array scalar rather than a regular scalar, since array * list
already has the right behaviour of interpreting this list as an array. One can do it here by writing this as off + scl[...] * arg
- though it might make more sense to ensure scl
is an array scalar inside mapparms
.
ENH: add support for array-likes in polynomial evaluation
Closes #17949.
Adds an
asarray()
call in the polybase__call__
method so that evaluation works with array-likes too. See #17949 for the initial reproduced code example; after the above change, evaluation works as expected: