Skip to content

Commit

Permalink
Merge pull request #33 from JuliaImages/mdhe1248-jerry/AxisArray_test
Browse files Browse the repository at this point in the history
Fix scalar CartesianIndex
  • Loading branch information
timholy authored Sep 29, 2018
2 parents 1729ff3 + 1900a6f commit e3d48c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ImageMetadata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,16 @@ for AType in (ImageMeta, ImageMetaAxis)
end

@inline function Base.getindex(img::ImageMetaAxis, ax::Axis, I...)
copyproperties(img, img.data[ax, I...])
result = img.data[ax, I...]
maybe_wrap(img, result)
end
@inline function Base.getindex(img::ImageMetaAxis, i::Union{Integer,AbstractVector,Colon}, I...)
copyproperties(img, img.data[i, I...])
result = img.data[i, I...]
maybe_wrap(img, result)
end
maybe_wrap(img::ImageMeta{T}, result::T) where T = result
maybe_wrap(img::ImageMeta{T}, result::AbstractArray{T}) where T = copyproperties(img, result)


@inline function Base.setindex!(img::ImageMetaAxis, val, ax::Axis, I...)
setindex!(img.data, val, ax, I...)
Expand Down
9 changes: 9 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,13 @@ end
@inferred cv[1,1,1]
end

@testset "AxisArray_CartesianIndex" begin
M = reshape([1,2,3,4], 2,2)
M = AxisArray(M)
img = ImageMeta(M)
@test 1 == img[1, CartesianIndex(1)] #Int and cartesianindex
@test maximum(img,dims=2) == reshape([3,4],2,1)
@test mean(img,dims=1) == reshape([1.5,3.5], 1,2)
end

nothing

0 comments on commit e3d48c7

Please sign in to comment.