Skip to content

Commit

Permalink
Merge pull request #32 from JuliaImages/teh/inference
Browse files Browse the repository at this point in the history
Test inference on Unitful AxisArrays
  • Loading branch information
timholy authored Sep 29, 2018
2 parents 5ee4c5f + f942f3c commit 1729ff3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ script:
jobs:
include:
- stage: deploy
julia: 0.7
julia: 1.0
os: linux
script:
- julia -e 'import Pkg; Pkg.clone(pwd()); Pkg.build("ImageMetadata")'
Expand Down
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Documenter, ImageMetadata

makedocs(modules = [ImageMetadata],
format = Documenter.Formats.HTML,
format = :html,
sitename = "ImageMetadata",
pages = ["intro.md", "reference.md"])

deploydocs(repo = "github.com/JuliaImages/ImageMetadata.jl.git",
julia = "0.5",
julia = "1.0",
target = "build",
deps = nothing,
make = nothing)
Expand Down
4 changes: 1 addition & 3 deletions docs/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ data
properties
copyproperties
shareproperties
getindexim
viewim
spatialproperties
ImageCore.spacedirections
ImageMetadata.spacedirections
permutedims
```
6 changes: 2 additions & 4 deletions src/ImageMetadata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export
`ImageMeta` is an AbstractArray that can have metadata, stored in a dictionary.
Construct an image with `ImageMeta(A, props)` (for a properties dictionary
`props`), or with `Image(A, prop1=val1, prop2=val2, ...)`.
`props`), or with `ImageMeta(A, prop1=val1, prop2=val2, ...)`.
"""
mutable struct ImageMeta{T,N,A<:AbstractArray} <: AbstractArray{T,N}
data::A
Expand Down Expand Up @@ -310,9 +310,7 @@ function permutedims(img::ImageMeta, perm)
permutedims_props!(copyproperties(img, permutedims(img.data, perm)), ip)
end

"""
Note: `adjoint` does not recurse into ImageMeta properties.
"""
# Note: `adjoint` does not recurse into ImageMeta properties.
function Base.adjoint(img::ImageMeta{T,2}) where {T<:Real}
ip = sortperm([2,1][[coords_spatial(img)...]])
permutedims_props!(copyproperties(img, adjoint(img.data)), ip)
Expand Down
2 changes: 1 addition & 1 deletion test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SimpleTraits

Unitful
28 changes: 23 additions & 5 deletions test/core.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FixedPointNumbers, Colors, ColorVectorSpace, SimpleTraits, ImageAxes, ImageMetadata, AxisArrays
using Compat
using Test
import Dates: now
using Unitful: m

@testset "indexing" begin
# 1d images
Expand Down Expand Up @@ -89,11 +89,14 @@ import Dates: now
end
# Test bounds-checking removal by @inbounds
if Base.JLOptions().check_bounds != 1 && Base.JLOptions().can_inline == 1
a = zeros(3)
sizehint!(a, 10) # make sure we don't cause a segfault
set5!(x) = @inbounds x[5] = 1.234
get5(x) = @inbounds x[5]
aa = zeros(3)
sizehint!(aa, 10) # make sure we don't cause a segfault
a = ImageMeta(aa)
@test_throws BoundsError a[5]
@inbounds a[5] = 1.234
@inbounds val = a[5]
set5!(a)
val = get5(a)
@test val == 1.234
a = zeros(3,5)
end
Expand Down Expand Up @@ -340,4 +343,19 @@ end
@test_throws ErrorException M'
end

@testset "Inference" begin
# Heavily-nested types tax Julia's inference capabilities
a = rand(N2f14, 3, 5, 2)
a1 = a[1,1,1]
aa = AxisArray(a, Axis{:y}(0:2), Axis{:x}(0:4), Axis{:z}(0:1))
cv = colorview(RGB, aa, zeroarray, aa)
@test @inferred(cv[1,1,1]) == RGB(a1, zero(a1), a1)
au = AxisArray(a, Axis{:y}(0m:1m:2m), Axis{:x}(0m:1m:4m), Axis{:z}(0m:1m:1m))
cv = colorview(RGB, au, zeroarray, au)
@test @inferred(cv[1,1,1]) == RGB(a1, zero(a1), a1)
am = ImageMeta(au)
cv = colorview(RGB, am, zeroarray, am)
@inferred cv[1,1,1]
end

nothing

0 comments on commit 1729ff3

Please sign in to comment.