ChainRules.jl icon indicating copy to clipboard operation
ChainRules.jl copied to clipboard

`@fastmath maximum` broken on 1.10

Open mcabbott opened this issue 2 years ago • 0 comments
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],)

mcabbott avatar Jan 23 '23 06:01 mcabbott