Skip to content

Multiplication between ScalMat and AbstractZeros is ambiguous. #401

Closed
@Wu-Chenyang

Description

@Wu-Chenyang

The following code runs into errors.

julia> using PDMats, FillArrays
julia> ScalMat(3, 1) * Zeros(3)
ERROR: MethodError: *(::ScalMat{Int64}, ::Zeros{Float64, 1, Tuple{Base.OneTo{Int64}}}) is ambiguous.

Candidates:
  *(a::ScalMat, x::AbstractVector)
    @ PDMats ~/.julia/packages/PDMats/cAM9h/src/scalmat.jl:43
  *(a::AbstractMatrix{T}, b::FillArrays.AbstractZeros{T, 1} where T) where T
    @ FillArrays ~/.julia/packages/FillArrays/lVl4c/src/fillalgebra.jl:103

Possible fix, define
  *(::ScalMat{T}, ::FillArrays.AbstractZeros{T, 1} where T) where T<:Real

Similarly, the matrix multiplication also fails.

julia> ScalMat(3,1) * Zeros(3,3)
ERROR: MethodError: *(::ScalMat{Int64}, ::Zeros{Float64, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}) is ambiguous.

Candidates:
  *(a::ScalMat, x::AbstractMatrix)
    @ PDMats ~/.julia/packages/PDMats/cAM9h/src/scalmat.jl:47
  *(a::AbstractMatrix, b::AbstractZeros{T, 2} where T)
    @ FillArrays ~/.julia/packages/FillArrays/lVl4c/src/fillalgebra.jl:98

Possible fix, define
  *(::ScalMat, ::AbstractZeros{T, 2} where T)

Higher dimensional multiplication wouldn't run into this problem because there isn't a method between ScalMat and AbstractArray. Therefore, an easy fix is, as suggested, implementing two extra methods in FillArraysPDMatsExt.jl. Appending the following code to the end of FillArraysPDMatsExt.jl should work.

using FillArrays: mult_zeros, AbstractZeros
Base.:*(a::ScalMat, b::AbstractZeros{T, 1} where T) = mult_zeros(a, b)
Base.:*(a::ScalMat, b::AbstractZeros{T, 2} where T) = mult_zeros(a, b)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions