JuliaGraphics / ColorTypes.jl

Basic color definitions and traits
Other
77 stars 35 forks source link

ERROR: MethodError: no method matching zero(::Gray{Float64}) #219

Closed schneiderfelipe closed 3 years ago

schneiderfelipe commented 3 years ago

Apparently, Gray.(A) is only defined for some matrix types, but not for, e.g., LinearAlgebra.UpperTriangular matrices:

julia> using LinearAlgebra, Colors

julia> A = rand(3, 3)
3×3 Array{Float64,2}:
 0.717871  0.265517   0.215277
 0.901667  0.0204098  0.358058
 0.583615  0.47894    0.42068

julia> Gray.(A)  # works fine
3×3 Array{Gray{Float64},2} with eltype Gray{Float64}:
 Gray{Float64}(0.717871)  Gray{Float64}(0.265517)   Gray{Float64}(0.215277)
 Gray{Float64}(0.901667)  Gray{Float64}(0.0204098)  Gray{Float64}(0.358058)
 Gray{Float64}(0.583615)  Gray{Float64}(0.47894)    Gray{Float64}(0.42068)

julia> Gray.(UpperTriangular(A))
3×3 UpperTriangular{Gray{Float64},Array{Gray{Float64},2}}:
Error showing value of type UpperTriangular{Gray{Float64},Array{Gray{Float64},2}}:
ERROR: MethodError: no method matching zero(::Gray{Float64})
(@v1.4) pkg> status Colors
Status `~/.julia/environments/v1.4/Project.toml`
  [5ae59095] Colors v0.12.6
timholy commented 3 years ago

Oh, that's interesting: it's defined for the type but not the value.

It works if you say using ColorVectorSpace. I am planning on moving more definitions from CVS to ColorTypes.

I'll transfer this issue to ColorTypes.

schneiderfelipe commented 3 years ago

It works if you say using ColorVectorSpace. I am planning on moving more definitions from CVS to ColorTypes.

Thanks, @timholy, using ColorVectorSpace indeed solves the issue for me.