You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ColorTypes defines parametric colors, e.g., RGB{UFixed8} and Gray{Float32}. Often when working with colors, one might want to say convert(Gray, c) without worrying about the element type. ColorTypes contains a traits-function, ccolor ("concrete color"), which performs inferrable "concretization" of the type, so that convert(Gray, ::RGB{UFixed8}) -> Gray{UFixed8} and convert(Gray, ::RGB{Float64}) -> Gray{Float64}. Naturally, if the user asks for type that's already concrete, convert(Gray{Float32}, ::RGB{UFixed8}), that's what s/he gets.
Now let's say I want to override this method to make sure that, when T is a Colorant, it's a concrete Colorant. Here's what I tried:
julia>using Colors
julia>import Base: convert
julia> S =TypeVar(:S)
S
julia>@evalfunctionconvert{T<:Colorant,n}(::Type{Array{T,n}}, x::BitArray{n})
# Specify the type concretely, then invoke the general algorithm on# the concrete typeinvoke(convert, (Type{Array{$S,n}}, BitArray{n}), Array{ccolor(T,Gray{Bool}),n}, x)
end
convert (generic function with 602 methods)
julia> b =bitrand(3,4)
3x4 BitArray{2}:falsetruefalsetruetruetruetruefalsefalsefalsetruefalse
julia>convert(Array{Gray}, b)
ERROR: invoke: argument type error
inconvert(::Type{Array{ColorTypes.Gray{T<:Union{AbstractFloat,Bool,FixedPointNumbers.FixedPoint{T<:Integer,f}}},N}}, ::BitArray{2}) at ./bitarray.jl:294ineval(::Module, ::Any) at ./boot.jl:237
It clearly invokes the correct method, but then I get a mismatch in the type.
Is there any reasonable solution?
The text was updated successfully, but these errors were encountered:
ColorTypes defines parametric colors, e.g.,
RGB{UFixed8}
andGray{Float32}
. Often when working with colors, one might want to sayconvert(Gray, c)
without worrying about the element type. ColorTypes contains a traits-function,ccolor
("concrete color"), which performs inferrable "concretization" of the type, so thatconvert(Gray, ::RGB{UFixed8}) -> Gray{UFixed8}
andconvert(Gray, ::RGB{Float64}) -> Gray{Float64}
. Naturally, if the user asks for type that's already concrete,convert(Gray{Float32}, ::RGB{UFixed8})
, that's what s/he gets.Now let's say I want to override this method to make sure that, when
T
is aColorant
, it's a concreteColorant
. Here's what I tried:It clearly invokes the correct method, but then I get a mismatch in the type.
Is there any reasonable solution?
The text was updated successfully, but these errors were encountered: