ChainRules.jl
ChainRules.jl copied to clipboard
`@fastmath maximum` broken on 1.10
trafficstars
julia> using Zygote, BenchmarkTools
julia> @macroexpand1 @fastmath maximum(x) # this is new
:(Base.FastMath.maximum_fast(x))
julia> VERSION
v"1.10.0-DEV.421"
julia> gradient(x -> sum(maximum(x; dims=1)), [1,3,2])
([0.0, 1.0, 0.0],)
julia> @fastmath gradient(x -> sum(maximum(x; dims=1)), [1,3,2])
ERROR: Mutating arrays is not supported -- called setindex!(Vector{Int64}, ...)
julia> @btime gradient(x -> maximum(x), $([1,3,2]))
min 1.113 μs, mean 1.214 μs (15 allocations, 528 bytes)
([0.0, 1.0, 0.0],)
julia> @btime @fastmath gradient(x -> maximum(x), $([1,3,2])) # also misses the rule
min 28.541 μs, mean 29.743 μs (159 allocations, 5.94 KiB)
([0.0, 1.0, 0.0],)