-
Notifications
You must be signed in to change notification settings - Fork 34
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
Casting for special functions #14
Comments
After thinking about this for a while, I think it’s probably better to just explicitly generate the casted signatures at codegen time and add them to I’ll submit a PR soon(ish). |
Would it work to just add the cast at the function call site? I suppose the challenge is going to be when there's multiple matching implementations that might work. |
Also, looking forward to the PR, thanks! I'm hoping to ship a |
Yeah you’d have to make sure the signatures are sorted by specificity and check for exact matches first. In that scenario I’m also not sure how you can generate the casting function on the fly from the types in a way that compiles to efficient machine code. Quite possibly a lack of knowledge on my part though. If you can’t generate them on the fly, then you have to codegen them, and at that point you might as well just generate the full signature. (That’s been my train of thought at least.) |
IIRC in the Numba code base, the ufuncs just have a large spelled out maps of what's accepted, there may be no better way. I suppose however in this case the Numba type system can be leaned upon a bit so as to do something like: Suppose there's a special function
Something along the lines of: @overload(foo)
def ol_foo(x, y):
if not isinstance(y, types.Float): # y must be a float type
return None
if isinstance(x, types.Float):
def impl(x, y):
return foo(types.float64(x), types.float64(y))
return impl
elif isinstance(x, types.Integer):
def impl(x, y):
return foo(types.long_(x), types.float64(y))
return impl might work and could be ok to generate? This may take some iterating to get right but it'd be useful to establish a working pattern. |
Currently
numba_scipy.special
does no casting for special function arguments like thespecial
ufuncs do. A basic example is:(Note that most functions in
special
don't have specificfloat32
signatures, they just cast tofloat64
and then cast back.)This issue is to discuss: how should we handle the casting?
For
numba_special
I had a branch that handled this in the following way:numpy.can_cast
to see if the arguments can be safely upcast to an available kernelIt works but is maybe a little messy. Is there a better way to handle this?
The text was updated successfully, but these errors were encountered: