Skip to content

Commit

Permalink
Merge pull request #36 from JuliaImages/cs/subarray
Browse files Browse the repository at this point in the history
add custom summary for Colorant SubArray
  • Loading branch information
timholy authored May 7, 2017
2 parents 2db10f8 + e5422d3 commit c686fc1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ end

Base.summary{T<:FixedPoint,N,AA,F}(A::MappedArray{T,N,AA,F,typeof(reinterpret)}) = summary_build(A)

# SubArray of Colorant

_showindices(io, indices) = print(io, indices)
if VERSION < v"0.6.0-dev.2068" # PR #19730
_showindices(io, ::Colon) = print(io, ':')
else
_showindices(io, ::Base.Slice) = print(io, ':')
end
function ShowItLikeYouBuildIt.showarg{T<:Colorant,N}(io::IO, A::SubArray{T,N})
print(io, "view(")
showarg(io, parent(A))
print(io, ", ")
for (i, indices) in enumerate(A.indexes)
_showindices(io, indices)
i < length(A.indexes) && print(io, ", ")
end
print(io, ')')
end

Base.summary{T<:Colorant,N}(A::SubArray{T,N}) = summary_build(A)


## Specializations of other containers based on a color or fixed-point eltype
# These may be going too far, but let's see how it works out
function ShowItLikeYouBuildIt.showarg{T<:Union{FixedPoint,Colorant},N}(io::IO, A::Array{T,N})
Expand Down
2 changes: 2 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ end

@testset "show" begin
rgb32 = rand(RGB{Float32}, 3, 5)
v = view(rgb32, 2:3, :)
@test summary(v) == "2×5 view(::Array{RGB{Float32},2}, 2:3, :) with element type ColorTypes.RGB{Float32}"
a = ChannelView(rgb32)
@test summary(a) == "3×3×5 ChannelView(::Array{RGB{Float32},2}) with element type Float32"
num64 = rand(3,5)
Expand Down

0 comments on commit c686fc1

Please sign in to comment.