-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix #11512 (disable computation for Complex BigInt/BigFloat type) #14979
Conversation
Clarification on the way the error is raised. It is used to avoid the GC frame introduded due to string interpolation in the error branch. Another way is to have a non-inline function to throw the error instead. |
@@ -370,7 +378,14 @@ for f in ("i", "ix", "j", "jx", "k", "kx", "y", "yx") | |||
bfn = symbol("bessel", f) | |||
@eval begin | |||
$bfn(nu::Real, z::Complex64) = Complex64($bfn(Float64(nu), Complex128(z))) | |||
$bfn(nu::Real, z::Complex) = $bfn(Float64(nu), Complex128(z)) | |||
$bfn{T}(nu::Real, z::Complex{T}) = if T === BigInt | |||
throw(ArgumentError("Bessel is currently not supported for type Complex{BigInt} (see #11512)")) |
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.
Note the style guidelines in CONTRIBUTING.md specify 4-space indent, not tabs. It's also preferable to use function
syntax once the definition requires multiple lines.
a9d87d5
to
edea98f
Compare
In #11512, only BigFloat is mentioned. I don't know if |
function airy{T}(k::Number, z::Complex{T}) | ||
if T === BigInt | ||
throw(ArgumentError("Airy is currently not supported for type Complex{BigInt} (see #11512)")) | ||
elseif T == BigFloat |
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.
one of ==
or ===
should be used consistently here
I think this would be handled via dispatch: for The Bessel case is a bit more complicated, but we should be able to do this via |
How can this work with the generic signature removed? I don't think we want to define |
And I think it is better to not define a method to raise error for |
…type) We implement an explicit type checking and disable Complex{BigInt} and Complex{BigFloat}. Currently only do for Bessel and Airy function.
@yuyichao Why would we need to do that? We can just define airy{T<:Integer}(k::Integer, z::Complex{T}) = airy(k, float(z)) |
Actually, we could keep it generic, with just airy(k::Integer, z::Complex) = airy(k, float(z)) |
There's also |
Agreed, but we should be able to do this via dispatch, rather than have explicit branches in functions. |
What should work is: airy(k::Integer, z::Complex) = airy(k, float(z))
airy(k::Integer, z::Complex{BigFloat}) = throw(MethodError(airy, typeof((k,z))) |
No, it will make it impossible to support that in a package. The branch is written in a way that is constant folded away and generate not runtime overhead. |
How will that make it impossible to support? Just re-define The whole point of multiple dispatch is that we don't need branches on types cluttering up our code! |
It will give a warning. |
Is that a huge problem? I'm willing to pay that to avoid 6 lines of completely useless boilerplate code Alternatively, we could do it via airy(k::Integer, z::Complex) = _airy(k, float(z)) where |
For other functions which have the same problem (e.g. |
That doesn't seem right to me. A more generic solution would be something like |
@andreasnoack That's the same as calling |
Certain logic is still much cleaner when expressed as branches. This one can indeed use a For |
And if we do it this way, we should probably leave a comment about the intended behavior. |
You are right. Time for more coffee. I think an explicit |
Actually, a better solution might be airy(k::Integer, z::Complex) = airy(k, float(z))
airy{T<:AbstractFloat}(k::Integer, z::Complex{T}) = throw(MethodError(airy, typeof((k,z))) This should then (1) avoid throwing a warning if defined for |
I've made the changes in #15119 instead. |
We implement an explicit type checking and disable Complex{BigInt} and Complex{BigFloat}.
Currently only do for Bessel and Airy function.