JuliaLang / LinearAlgebra.jl

Julia Linear Algebra standard library
Other
13 stars 0 forks source link

Lost generality of `_generic_matmatmul` in 1.11 #1095

Closed laggvar closed 1 month ago

laggvar commented 1 month ago

The following code is valid in 1.10.x but errors in 1.11:

struct Thing
    data::Float64
end

Base.zero(::Type{Thing}) = Thing(0.)
Base.zero(::Thing)       = Thing(0.)
Base.one(::Type{Thing})  = Thing(1.)
Base.one(::Thing)        = Thing(1.)
Base.:+(t::Thing...)     = +(getfield.(t, :data)...)
Base.:*(t::Thing...)     = *(getfield.(t, :data)...)

A = Thing.(randn(2,2))

A * A

The reason seems to be that A * A uses the five-argument mul! internally, which now performs a multiplication by alpha::Bool instead of checking isone(alpha) (https://github.com/JuliaLang/julia/pull/52038/files#diff-a454fe10464022052956170246cb4be7e2e71bc517e02c2ec0a9548fb6aaaf29R791).

Essentially: