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

similar(::ChannelView, S, dims) has ambiguous intent #48

Closed
timholy opened this issue Sep 5, 2017 · 2 comments
Closed

similar(::ChannelView, S, dims) has ambiguous intent #48

timholy opened this issue Sep 5, 2017 · 2 comments

Comments

@timholy
Copy link
Member

timholy commented Sep 5, 2017

As reported on gitter:

julia> a = rand(RGB4{N0f8}, 100, 100);

julia> x = channelview(a);

julia> x[1,:,:]
ERROR: DimensionMismatch("new array has 100 color channels, must have 3")
Stacktrace:
 [1] check_ncolorchan(::Array{ColorTypes.RGB4{FixedPointNumbers.Normed{UInt8,8}},2}, ::Tuple{Int64,Int64}) at /home/tim/.julia/v0.6/ImageCore/src/colorchannels.jl:356
 [2] similar at /home/tim/.julia/v0.6/ImageCore/src/colorchannels.jl:117 [inlined]
 [3] similar(::ImageCore.ChannelView{FixedPointNumbers.Normed{UInt8,8},3,Array{ColorTypes.RGB4{FixedPointNumbers.Normed{UInt8,8}},2}}, ::Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}) at ./abstractarray.jl:521
 [4] macro expansion at ./multidimensional.jl:458 [inlined]
 [5] _unsafe_getindex(::IndexCartesian, ::ImageCore.ChannelView{FixedPointNumbers.Normed{UInt8,8},3,Array{ColorTypes.RGB4{FixedPointNumbers.Normed{UInt8,8}},2}}, ::Int64, ::Base.Slice{Base.OneTo{Int64}}, ::Base.Slice{Base.OneTo{Int64}}) at ./multidimensional.jl:453
 [6] macro expansion at ./multidimensional.jl:442 [inlined]
 [7] _getindex at ./multidimensional.jl:438 [inlined]
 [8] getindex(::ImageCore.ChannelView{FixedPointNumbers.Normed{UInt8,8},3,Array{ColorTypes.RGB4{FixedPointNumbers.Normed{UInt8,8}},2}}, ::Int64, ::Colon, ::Colon) at ./abstractarray.jl:882

This is actually far nastier than it might seem. The offending method is here. The problem is that method is presuming that what you're doing is trying to create another ChannelView, and so it's making sure that the new underlying array has a shape consistent with the first dimension being a color channel. But unfortunately similar gets used in two different ways.

I haven't spent much time thinking about it (deadlines...), but this doesn't seem to be entirely trivial to fix while preserving type-stability.

@timholy
Copy link
Member Author

timholy commented Sep 5, 2017

Note it doesn't happen with RGB because channelview returns an Array in such cases.

@timholy
Copy link
Member Author

timholy commented Aug 14, 2018

Now that we use ReinterpretArray, this is no longer an issue.

@timholy timholy closed this as completed Aug 14, 2018
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