-
Notifications
You must be signed in to change notification settings - Fork 116
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
Polyval handles non-array as second argument #601
Polyval handles non-array as second argument #601
Conversation
code/numpy/poly.c
Outdated
} | ||
if(!ndarray_object_is_array_like(o_x)) { | ||
// Try to convert o_x to a list | ||
o_x = mp_obj_new_list(1, &o_x); |
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.
What happens, if o_x
can't be converted to a list?
Whenever there is a user-facing change, increment the version number in Line 36 in 47ad73a
|
I'm trying to understand what this PR wants to solve: you call the function micropython-ulab/code/ndarray.c Line 217 in 47ad73a
micropython-ulab/code/numpy/poly.c Lines 238 to 247 in 45d6375
|
I just needed Polyval to handle scalar and not only lists. Otherwise,
raises a The big flaw is that it returns a list in both case which is not Numpy's behavior, so I have to rework this anyway. |
You could call the micropython-ulab/code/ndarray.c Line 1690 in 47ad73a
|
45d6375
to
ff8766c
Compare
ff8766c
to
42c8b9c
Compare
@v923z , thanks for the suggestion. |
if(!ndarray_object_is_array_like(o_x)) { | ||
return mp_obj_new_float(poly_eval(mp_obj_get_float(o_x), p, plen)); | ||
} | ||
|
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.
What happens, if the input is not array-like, but not a float, either? E.g., what do you do with a complex scalar?
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.
It will happen the same as if the input is array-like, with non-float elements: a type error such as
TypeError: can't convert complex to float
This would allow the evaluation of a polynomial at single value, as allowed in numpy.
https://numpy.org/doc/stable/reference/generated/numpy.polyval.html