diff --git a/src/Matrix.jl b/src/Matrix.jl index 122886f09c..1500b199a0 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -1178,6 +1178,9 @@ end function Base.promote(x::MatrixElem{S}, y::MatrixElem{T}) where {S <: NCRingElement, T <: NCRingElement} + if S === T + return x, y + end U = promote_rule_sym(S, T) if U === S return x, change_base_ring(base_ring(x), y) @@ -1200,6 +1203,9 @@ end function Base.promote(x::MatrixElem{S}, y::Vector{T}) where {S <: NCRingElement, T <: NCRingElement} + if S === T + return x, y + end U = promote_rule_sym(S, T) if U === S return x, map(base_ring(x), y)::Vector{S} # Julia needs help here @@ -1222,6 +1228,9 @@ end *(x::Vector, y::MatrixElem) = *(promote(x, y)...) function Base.promote(x::MatElem{S}, y::T) where {S <: NCRingElement, T <: NCRingElement} + if S === T + return x, y + end U = promote_rule_sym(S, T) if U === S return x, base_ring(x)(y) diff --git a/src/NCRings.jl b/src/NCRings.jl index 7b5c27a77b..00274184a5 100644 --- a/src/NCRings.jl +++ b/src/NCRings.jl @@ -34,6 +34,9 @@ function promote_rule_sym(::Type{T}, ::Type{S}) where {T, S} end @inline function try_promote(x::S, y::T) where {S <: NCRingElem, T <: NCRingElem} + if S === T + return x, y + end U = promote_rule_sym(S, T) if S === U return true, x, parent(x)(y)