-
Notifications
You must be signed in to change notification settings - Fork 56
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
advertise ccolor
in writing generic code
#151
Labels
best practice
workflows and best practice that are useful in JuliaImages and/or Julia
Comments
The For example: julia> ccolor(HSV, Gray{Float32})
HSV{Float32}
julia> ccolor(HSV, Float32)
ERROR: in ccolor, no automatic conversion from Float32 and HSV (This is not a bug.) However, at least for gray and rgb colors, it should work as expected. So, I also feel |
johnnychen94
added
the
best practice
workflows and best practice that are useful in JuliaImages and/or Julia
label
Aug 21, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Functions in JuliaImages should accept both numerical array
AbstractArray{<:Number}
and colorant arrayAbstract{<:Colorant}
if possible.It is not uncommon to infer the return eltype in the beginning of the algorithm so as to pre-allocate array. I previously have two versions of codes to achieve this. The first version is:
Then one day I found out that
eltype(Float32) == Float32
, which make it possible to merge it into one method:As @kimikage pointed it out in JuliaGraphics/ColorTypes.jl#201,
ccolor
does a similar thing more reliably (I assume so?):I feel this worth documenting somewhere in the tutorials; otherwise, it's like a missing spell and people repeatedly reinvent it.
The text was updated successfully, but these errors were encountered: