Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplication between ScalMat and AbstractZeros is ambiguous. #401

Open
Wu-Chenyang opened this issue Dec 17, 2024 · 0 comments
Open

Multiplication between ScalMat and AbstractZeros is ambiguous. #401

Wu-Chenyang opened this issue Dec 17, 2024 · 0 comments

Comments

@Wu-Chenyang
Copy link

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant