-
Notifications
You must be signed in to change notification settings - Fork 71
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
Power ^ allocates #103
Comments
This is an unfortunate corner of the package at the moment: The allocation is due to the fact that the only way to get correct rounding for powers is using MPFR, so this is in fact converting the interval to a However, if you are happy to have a slightly wider interval, there is actually an exported function julia> @btime ($x)^2
3.266 μs (51 allocations: 2.02 KiB)
Interval(0.3183098861837905, 0.5000000000000003)
julia> @btime pow($x, 2)
69.124 ns (0 allocations: 0 bytes)
Interval(0.3183098861837905, 0.5000000000000003) We had a discussion in #14 about whether to make In any case, there should certainly be an easy way to choose to use fast powers: |
The problem with a special function like But I understand if you want to resolve this in a more general way. I made a suggestion in #56 for this. |
Actually you can just redefine julia> import Base: ^
julia> ^(x::Interval{Float64}, p::Integer) = pow(x, p) and similarly for By the way, I think the small power business has gone away in master? |
This came up on Discourse with a pretty significant performance impact: https://discourse.julialang.org/t/interval-arithmetic-computation-time/14633/3?u=rdeits |
By the way, the special handling of literal powers is still present in Julia 1.0, so it's totally possible to intercept integer literal powers and dispatch them to
|
You could also intercept small literal powers and dispatch them to an optimal sequence of inlined multiplications. |
This is definitely a bad situation. I think we should now reverse pow and ^ so that ^ is fast and pow is optimally accurate. Cc @lbenet |
At least, it is worth giving it a try. |
should be fixed in #388 |
Solved by PR #593. |
It seems that
x^2
currently allocates, which I think should not happen since Base has a special handling for these cases.I found this comment
So is this just not implemented or is there a specific reason to not include these?
The text was updated successfully, but these errors were encountered: