-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
prevent unnecessary repeated squaring calculation #58720
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
prevent unnecessary repeated squaring calculation #58720
Conversation
Hello! I am a bot. Thank you for your pull request! I have assigned
Note: If you are a Julia committer, please make sure that your organization membership is public. |
69f72f5
to
e82b63c
Compare
Benchmark: julia> using BenchmarkTools
julia> @btime m^Int(2) setup=m=rand(1:10,100,100);
457.701 μs (6 allocations: 156.42 KiB)
julia> @eval Base @assume_effects :terminates_locally function power_by_squaring(x_, p::Integer; mul=*)
[...]
end
power_by_squaring (generic function with 3 methods)
julia> @btime m^Int(2) setup=m=rand(1:10,100,100);
230.714 μs (3 allocations: 78.21 KiB) |
julia> using LazyArrays
julia> ApplyArray(exp, [1 2; 3 4]) ^ Int(2)
ERROR: MethodError: Cannot `convert` an object of type
ApplyArray{Float64,2,typeof(exp),Tuple{Matrix{Int64}}} to an object of type
ApplyArray{Float64,2,typeof(*),Tuple{ApplyMatrix{Float64, typeof(exp), Tuple{Matrix{Int64}}},ApplyMatrix{Float64, typeof(exp), Tuple{Matrix{Int64}}}}}
The function `convert` exists, but no method is defined for this combination of argument types.
Closest candidates are:
(::Type{ApplyArray{T, N, F, Args}} where {T, N, F, Args<:Tuple})(::Any, ::Any)
@ LazyArrays ~/.julia/packages/LazyArrays/ltmzk/src/lazyapplying.jl:196
convert(::Type{T}, ::T) where T
@ Base Base_compiler.jl:136
convert(::Type{T}, ::LinearAlgebra.Factorization) where T<:AbstractArray
@ LinearAlgebra ~/tmp/jl/jl/julia-e82b63cced/share/julia/stdlib/v1.13/LinearAlgebra/src/factorization.jl:104
...
Stacktrace:
[1] power_by_squaring(x_::ApplyMatrix{Float64, typeof(exp), Tuple{Matrix{Int64}}}, p::Int64; mul::typeof(*))
@ Base ./intfuncs.jl:361
[2] power_by_squaring(x_::ApplyMatrix{Float64, typeof(exp), Tuple{Matrix{Int64}}}, p::Int64)
@ Base ./intfuncs.jl:353
[3] _power_by_squaring
@ ~/.julia/packages/ArrayLayouts/B2wRU/src/mul.jl:486 [inlined]
[4] power_by_squaring
@ ~/.julia/packages/ArrayLayouts/B2wRU/src/mul.jl:494 [inlined]
[5] ^(A::ApplyMatrix{Float64, typeof(exp), Tuple{Matrix{Int64}}}, p::Int64)
@ LinearAlgebra ~/tmp/jl/jl/julia-e82b63cced/share/julia/stdlib/v1.13/LinearAlgebra/src/dense.jl:558
[6] top-level scope
@ REPL[2]:1 IMO the proper fix might be for LazyArrays.jl to implement their own exponentiation, however I could also try to make this PR less disruptive by using |
2e3578f
to
a196d0b
Compare
I don't think we should be checking for |
336dfa3
to
6e29b5c
Compare
The current version of the PR doesn't use |
The registered package in question will be broken for an unrelated reason now anyway by PR JuliaLang#58720, so there's no sense in trying to protect it any more. In any case, it doesn't make sense to hold back the language just to protect a single broken package.
bump |
This is somewhat ugly, but it seems reasonable enough. |
I suppose labelling as "merge me" is OK. |
TODO: notify affected packages of breakage. |
Fixes #58719