-
Notifications
You must be signed in to change notification settings - Fork 20
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
mean(img) type instability when img is of eltype Gray{N0f8} #134
Comments
Perhaps @timholy already knows about this problem. JuliaMath/FixedPointNumbers.jl#183 is listed in #131 (comment). Julia v1.5.0 has already been released, so I think it's worth fixing separately. |
Thanks for spotting this!
A return type of julia> using ImageCore, Statistics
julia> x = rand(Gray{N0f8}, 4, 4);
julia> mean(x)
ERROR: MethodError: no method matching /(::Gray{Normed{UInt8,8}}, ::Int64)
Closest candidates are:
/(::Graphics.Vec2, ::Real) at /home/tim/.julia/packages/Graphics/GTY20/src/Graphics.jl:111
/(::Missing, ::Number) at missing.jl:115
/(::BigInt, ::Union{Int16, Int32, Int64, Int8, UInt16, UInt32, UInt64, UInt8}) at gmp.jl:540
...
Stacktrace:
[1] _mean(::typeof(identity), ::Array{Gray{Normed{UInt8,8}},2}, ::Colon) at /home/tim/src/julia-1/usr/share/julia/stdlib/v1.5/Statistics/src/Statistics.jl:176
[2] mean(::Array{Gray{Normed{UInt8,8}},2}; dims::Function) at /home/tim/src/julia-1/usr/share/julia/stdlib/v1.5/Statistics/src/Statistics.jl:164
[3] mean(::Array{Gray{Normed{UInt8,8}},2}) at /home/tim/src/julia-1/usr/share/julia/stdlib/v1.5/Statistics/src/Statistics.jl:164
[4] top-level scope at REPL[3]:1
julia> using ColorVectorSpace
julia> mean(x)
Gray{Float32}(0.5892157f0) so it's inferrable only as an error. The possibility of a julia> x = [0.4N0f8, 0.6N0f8]
2-element Array{N0f8,1} with eltype Normed{UInt8,8}:
0.4N0f8
0.6N0f8
julia> sum(x)/2
0.5
julia> sum(x./2)
0.5f0 which seems less than ideal. I suspect the right answer is that we should change the accumulator type to |
However, Of course, it is possible to define accumulator types for color types separately from I'm in favor of rethinking the specifications, but I think it's better to repair the backwards compatibility first. FixedPointNumbers v0.9 will take a bit longer to be released. |
I think your edited comment suggests we pretty much agree on how to proceed, but to be sure there's no misunderstanding let me make sure I've explained my viewpoint. Just because something has been in a code base for a long time does not mean it's right. As we strive for 1.0, we should do what's right. Julia's usage is growing rapidly, and the number of users 10 years from now will dwarf the size of the community now. Since we're not at 1.0, we should aim for as much logical consistency as we can even if we have to make some breaking changes. |
But yes, it's fine to make non-breaking changes first, as long as that doesn't start holding back dependent packages in some way. (I can't see how this one would.) |
My best guess is that if we consistently use |
I'm fine with the In the first place, I think it is worth doing some specialization in terms of accuracy and speed. Again, this is not only an issue with the nightly build, but also with v1.5. |
which is good, but once I load
ColorVectorSpace
, it isn't anymore:Both
Gray{Float32}
andN0f8
are good here.The text was updated successfully, but these errors were encountered: