Skip to content

Commit

Permalink
Merge pull request #66 from Evizero/jc/fix_test
Browse files Browse the repository at this point in the history
update dependency versions and fix broken tests
  • Loading branch information
johnnychen94 authored Aug 24, 2020
2 parents d136401 + d12716c commit 51172d8
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 52 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@ name: Run benchmarks

on:
pull_request:
types: [labeled, opened, synchronize, reopened]

jobs:
Benchmark:
runs-on: ubuntu-latest
# Only trigger the benchmark job when we add `run benchmark` label to the PR
if: contains(github.event.pull_request.labels.*.name, 'run benchmark')
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
- name: Cache artifacts
uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
version: 1.3
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- name: Install dependencies
run: julia -e 'using Pkg; pkg"add PkgBenchmark [email protected]"'
run: julia -e 'using Pkg; pkg"add JSON PkgBenchmark [email protected]"'
- name: Run benchmarks
run: julia -e 'using BenchmarkCI; BenchmarkCI.judge()'
- name: Post results
run: julia -e 'using BenchmarkCI; BenchmarkCI.postjudge()'
run: julia benchmark/run_benchmarks.jl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 changes: 23 additions & 1 deletion .github/workflows/juliapackage.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
name: Unit test

on:
create:
tags:
push:
branches:
- master
pull_request:
schedule:
- cron: '20 00 1 * *'

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
julia-version: ['1.0', '1', 'nightly']
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v1.0.0
- uses: actions/checkout@v2
- name: "Set up Julia"
uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}

- name: Cache artifacts
uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- name: "Unit Test"
uses: julia-actions/julia-runtest@master

- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info

14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
ComputationalResources = "0.3"
CoordinateTransformations = "0.5"
CoordinateTransformations = "0.5, 0.6"
FileIO = "1"
IdentityRanges = "0.3"
ImageCore = "0.8.1"
Expand All @@ -32,7 +32,7 @@ Interpolations = "0.8, 0.9, 0.10, 0.11, 0.12"
MLDataPattern = "0.4, 0.5"
MappedArrays = "0.1, 0.2"
OffsetArrays = "0.8, 0.9, 0.10, 0.11, 1"
Rotations = "0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13"
Rotations = "0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13, 1"
StaticArrays = "0.8, 0.9, 0.10, 0.11, 0.12"
julia = "1"

Expand Down
6 changes: 6 additions & 0 deletions benchmark/run_benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# To run it locally, BenchmarkCI should be added to root project
using BenchmarkCI
on_CI = haskey(ENV, "GITHUB_ACTIONS")

BenchmarkCI.judge()
on_CI ? BenchmarkCI.postjudge() : BenchmarkCI.displayjudgement()
2 changes: 1 addition & 1 deletion src/distortedview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Base.size(A::DistortedView) = map(length, axes(A))
Base.axes(A::DistortedView) = axes(A.parent)

function Base.showarg(io::IO, A::DistortedView, toplevel)
print(io, typeof(A).name, '(')
print(io, typeof(A).name.name, '(')
Base.showarg(io, parent(A), false)
print(io, ", ")
Base.showarg(io, A.grid, false)
Expand Down
4 changes: 2 additions & 2 deletions src/operations/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function Base.show(io::IO, op::CacheImageInto{<:AbstractArray})
print(io, "Cache into preallocated ")
print(io, summary(op.buffer))
else
print(io, typeof(op).name, "(")
print(io, typeof(op).name.name, "(")
Base.showarg(io, op.buffer, false)
print(io, ")")
end
Expand All @@ -141,7 +141,7 @@ function Base.show(io::IO, op::CacheImageInto{<:Tuple})
print(io, "Cache into preallocated ")
print(io, "(", join(map(summary, op.buffer), ", "), ")")
else
print(io, typeof(op).name, "((")
print(io, typeof(op).name.name, "((")
for (i, buffer) in enumerate(op.buffer)
Base.showarg(io, buffer, false)
i < length(op.buffer) && print(io, ", ")
Expand Down
4 changes: 2 additions & 2 deletions src/operations/crop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function Base.show(io::IO, op::Crop{N}) where N
end
else
print(io, "Augmentor.")
print(io, typeof(op).name, "{$N}($(op.indices))")
print(io, typeof(op).name.name, "{$N}($(op.indices))")
end
end

Expand Down Expand Up @@ -195,7 +195,7 @@ function Base.show(io::IO, op::CropNative{N}) where N
end
else
print(io, "Augmentor.")
print(io, typeof(op).name, "{$N}($(op.indices))")
print(io, typeof(op).name.name, "{$N}($(op.indices))")
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/operations/either.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function Base.show(io::IO, op::Either)
print(io, '.')
end
else
print(io, typeof(op).name, " (1 out of ", length(op.operations), " operation(s)):")
print(io, typeof(op).name.name, " (1 out of ", length(op.operations), " operation(s)):")
percent_int = map(c->round(Int, c*100), op.chances)
percent_float = map(c->round(c*100; digits=1), op.chances)
percent = if any(i != f for (i,f) in zip(percent_int,percent_float))
Expand Down
6 changes: 4 additions & 2 deletions src/operations/mapfun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ end
@inline supports_lazy(::Type{<:AggregateThenMapFun}) = true

function applyeager(op::AggregateThenMapFun, img::AbstractArray, param)
agg = op.aggfun(img)
# promote the result to float type because `aggfun` might not widely support `Gray{N0f8}`/`N0f8` types well
# e.g, type instability in https://github.com/JuliaGraphics/ColorVectorSpace.jl/issues/134
agg = op.aggfun(of_eltype(floattype(eltype(img)), img))
plain_array(map(x -> op.mapfun(x, agg), img))
end

function applylazy(op::AggregateThenMapFun, img::AbstractArray, param)
agg = op.aggfun(img)
agg = op.aggfun(of_eltype(floattype(eltype(img)), img))
mappedarray(x -> op.mapfun(x, agg), img)
end

Expand Down
2 changes: 1 addition & 1 deletion src/operations/scale.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ function Base.show(io::IO, op::Scale{N}) where N
else
print(io, "Augmentor.")
fct = length(op.factors[1]) == 1 ? map(first,op.factors) : op.factors
print(io, typeof(op).name, "{$N}($(fct))")
print(io, typeof(op).name.name, "{$N}($(fct))")
end
end
2 changes: 1 addition & 1 deletion src/operations/zoom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ function Base.show(io::IO, op::Zoom{N}) where N
else
fct = length(op.factors[1]) == 1 ? map(first,op.factors) : op.factors
print(io, "Augmentor.")
print(io, typeof(op).name, "{$N}($(fct))")
print(io, typeof(op).name.name, "{$N}($(fct))")
end
end
2 changes: 1 addition & 1 deletion src/pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function Base.show(io::IO, pipeline::Pipeline)
end
else
k = length("$n")
print(io, "$n-step $(typeof(pipeline).name):")
print(io, "$n-step Augmentor.$(typeof(pipeline).name.name):")
for (i, op) in enumerate(ops)
println(io)
print(io, lpad(string(i), k+1, " "), ".) ")
Expand Down
11 changes: 7 additions & 4 deletions test/operations/tst_cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ end
@test typeof(@inferred(CacheImage(buf))) <: Augmentor.CacheImageInto
op = @inferred CacheImage(buf)
@test Augmentor.CacheImageInto(buf) === op
@test str_show(op) == "Augmentor.CacheImageInto(::Array{Gray{N0f8},2})"
@test endswith("CacheImageInto(::Array{Gray{N0f8},2})", str_show(op))

@test str_showconst(op) == "CacheImage(Array{Gray{N0f8}}(2, 3))"
op2 = @inferred CacheImage(Array{Gray{N0f8}}(undef, 2, 3))
@test typeof(op) == typeof(op2)
@test typeof(op.buffer) == typeof(op2.buffer)
@test size(op.buffer) == size(op2.buffer)
@test str_showcompact(op) == "Cache into preallocated 2×3 Array{Gray{N0f8},2} with eltype Gray{Normed{UInt8,8}}"
@test str_showcompact(op) == "Cache into preallocated 2×3 Array{Gray{N0f8},2} with eltype Gray{Normed{UInt8,8}}" ||
str_showcompact(op) == "Cache into preallocated 2×3 Array{Gray{N0f8},2} with eltype Gray{N0f8}"

v = Augmentor.applylazy(Resize(2,3), camera)
res = @inferred Augmentor.applyeager(op, v)
Expand Down Expand Up @@ -116,13 +118,14 @@ end
op = @inferred CacheImage(buf1,buf2)
@test op === @inferred CacheImage((buf1,buf2))
@test Augmentor.CacheImageInto((buf1,buf2)) === op
@test str_show(op) == "Augmentor.CacheImageInto((::Array{Gray{N0f8},2}, ::Array{RGB{N0f8},2}))"
@test endswith("CacheImageInto((::Array{Gray{N0f8},2}, ::Array{RGB{N0f8},2}))", str_show(op))
@test str_showconst(op) == "CacheImage(Array{Gray{N0f8}}(3, 3), Array{RGB{N0f8}}(2, 3))"
op2 = @inferred CacheImage(Array{Gray{N0f8}}(undef, 3, 3), Array{RGB{N0f8}}(undef, 2, 3))
@test typeof(op) == typeof(op2)
@test typeof(op.buffer) == typeof(op2.buffer)
@test size.(op.buffer) === size.(op2.buffer)
@test str_showcompact(op) == "Cache into preallocated (3×3 Array{Gray{N0f8},2} with eltype Gray{Normed{UInt8,8}}, 2×3 Array{RGB{N0f8},2} with eltype RGB{Normed{UInt8,8}})"
@test str_showcompact(op) == "Cache into preallocated (3×3 Array{Gray{N0f8},2} with eltype Gray{Normed{UInt8,8}}, 2×3 Array{RGB{N0f8},2} with eltype RGB{Normed{UInt8,8}})" ||
str_showcompact(op) == "Cache into preallocated (3×3 Array{Gray{N0f8},2} with eltype Gray{N0f8}, 2×3 Array{RGB{N0f8},2} with eltype RGB{N0f8})"

@test buf1 == square
@test buf2 == rgb_rect
Expand Down
6 changes: 4 additions & 2 deletions test/operations/tst_channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ end
@test_throws MethodError CombineChannels(Float64)
@test typeof(@inferred(CombineChannels(RGB))) <: CombineChannels <: Augmentor.Operation
@test typeof(@inferred(CombineChannels(RGB{N0f8}))) <: CombineChannels <: Augmentor.Operation
@test str_show(CombineChannels(RGB)) == "Augmentor.CombineChannels(RGB{Any})"
@test str_show(CombineChannels(RGB)) == "Augmentor.CombineChannels(RGB{Any})" ||
str_show(CombineChannels(RGB)) == "Augmentor.CombineChannels(RGB)"
@test str_show(CombineChannels(Gray{N0f8})) == "Augmentor.CombineChannels(Gray{N0f8})"
@test str_showconst(CombineChannels(RGB{N0f8})) == "CombineChannels(RGB{N0f8})"
@test str_showcompact(CombineChannels(Gray)) == "Combine color channels into colorant Gray{Any}"
@test str_showcompact(CombineChannels(Gray)) == "Combine color channels into colorant Gray{Any}" ||
str_showcompact(CombineChannels(Gray)) == "Combine color channels into colorant Gray"
end
@testset "eager" begin
@test Augmentor.supports_eager(CombineChannels) === false
Expand Down
6 changes: 4 additions & 2 deletions test/operations/tst_convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
@test typeof(@inferred(ConvertEltype(RGB))) <: ConvertEltype <: Augmentor.Operation
@test typeof(@inferred(ConvertEltype(RGB{N0f8}))) <: ConvertEltype <: Augmentor.Operation
@test str_show(ConvertEltype(Float64)) == "Augmentor.ConvertEltype(Float64)"
@test str_show(ConvertEltype(RGB)) == "Augmentor.ConvertEltype(RGB{Any})"
@test str_show(ConvertEltype(RGB)) == "Augmentor.ConvertEltype(RGB{Any})" ||
str_show(ConvertEltype(RGB)) == "Augmentor.ConvertEltype(RGB)"
@test str_show(ConvertEltype(Gray{N0f8})) == "Augmentor.ConvertEltype(Gray{N0f8})"
@test str_showconst(ConvertEltype(Float64)) == "ConvertEltype(Float64)"
@test str_showconst(ConvertEltype(RGB{N0f8})) == "ConvertEltype(RGB{N0f8})"
@test str_showcompact(ConvertEltype(Float64)) == "Convert eltype to Float64"
@test str_showcompact(ConvertEltype(Gray)) == "Convert eltype to Gray{Any}"
@test str_showcompact(ConvertEltype(Gray)) == "Convert eltype to Gray{Any}" ||
str_showcompact(ConvertEltype(Gray)) == "Convert eltype to Gray"
end
@testset "eager" begin
@test Augmentor.supports_eager(ConvertEltype) === true
Expand Down
19 changes: 11 additions & 8 deletions test/operations/tst_mapfun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ end
@testset "eager" begin
@test_throws MethodError Augmentor.applyeager(AggregateThenMapFun(mean, identity), nothing)
@test Augmentor.supports_eager(AggregateThenMapFun) === true
m = mean(rect)
m = floattype(eltype(rect)).(mean(rect))
img_out = map(x->x-m, rect)
imgs = [
rect,
Expand All @@ -101,13 +101,14 @@ end
@test eltype(res) <: Gray{N0f8}
@test typeof(axes(img_in)) <: NTuple{2,Base.OneTo} ? typeof(res) <: Array : typeof(res) <: Array
res = @inferred(Augmentor.applyeager(AggregateThenMapFun(mean, (x,a)->x-a), img_in))
@test res == img_out
@test res img_out
@test typeof(res) == typeof(img_out)
end
img = OffsetArray(rgb_rect, -2, -1)
res = @inferred(Augmentor.applyeager(AggregateThenMapFun(mean, (x,a)->x-a), img))
@test res collect(img .- mean(rgb_rect))
@test typeof(res) <: Array{RGB{Float64}}
@test typeof(res) <: Array
@test eltype(res) <: RGB{<:AbstractFloat} # could be either Float32 / Float64
end
end
@testset "affine" begin
Expand All @@ -123,15 +124,17 @@ end
@test parent(res) === rect
@test res isa ReadonlyMappedArray
res = @inferred(Augmentor.applylazy(AggregateThenMapFun(mean, (x,a)->x-a), rgb_rect))
@test res == mappedarray(x->x-mean(rgb_rect), rgb_rect)
@test res mappedarray(x->x-mean(rgb_rect), rgb_rect)
@test parent(res) === rgb_rect
@test typeof(res) <: MappedArrays.ReadonlyMappedArray{ColorTypes.RGB{Float64}}
@test typeof(res) <: MappedArrays.ReadonlyMappedArray
@test eltype(res) <: RGB{<:AbstractFloat} # could be either Float32 / Float64
img = OffsetArray(rgb_rect, -2, -1)
res = @inferred(Augmentor.applylazy(AggregateThenMapFun(mean, (x,a)->x-a), img))
@test res == mappedarray(x->x-mean(rgb_rect), img)
@test res mappedarray(x->x-mean(rgb_rect), img)
@test parent(res) === img
@test typeof(res) <: MappedArrays.ReadonlyMappedArray{ColorTypes.RGB{Float64}}
@test @inferred(getindex(res,0,0)) isa RGB{Float64}
@test typeof(res) <: MappedArrays.ReadonlyMappedArray
@test eltype(res) <: RGB{<:AbstractFloat} # could be either Float32 / Float64
@test @inferred(getindex(res,0,0)) isa RGB{<:AbstractFloat}
end
@testset "view" begin
@test Augmentor.supports_view(AggregateThenMapFun) === false
Expand Down
12 changes: 9 additions & 3 deletions test/tst_distortedview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,22 @@ end
@test parent(dv) === camera
@test size(dv) == size(camera)
@test eltype(dv) == eltype(camera)
@test summary(dv) == "512×512 Augmentor.DistortedView(::Array{Gray{N0f8},2}, ::Array{Float64,3} as 3×3 vector field) with eltype Gray{Normed{UInt8,8}}"
@test summary(dv) == "512×512 Augmentor.DistortedView(::Array{Gray{N0f8},2}, ::Array{Float64,3} as 3×3 vector field) with eltype Gray{Normed{UInt8,8}}" ||
summary(dv) == "512×512 DistortedView(::Array{Gray{N0f8},2}, ::Array{Float64,3} as 3×3 vector field) with eltype Gray{Normed{UInt8,8}}" ||
summary(dv) == "512×512 DistortedView(::Array{Gray{N0f8},2}, ::Array{Float64,3} as 3×3 vector field) with eltype Gray{N0f8}"
@test_reference "reference/distort_static.txt" dv

camerao = OffsetArray(camera, (-5,-10))
dv2 = @inferred Augmentor.DistortedView(camerao, A)
@test size(dv2) == size(camera)
@test eltype(dv2) == eltype(camera)
@test summary(dv2) == "512×512 Augmentor.DistortedView(::Array{Gray{N0f8},2}, ::Array{Float64,3} as 3×3 vector field) with eltype Gray{Normed{UInt8,8}}"
@test summary(dv2) == "512×512 Augmentor.DistortedView(::Array{Gray{N0f8},2}, ::Array{Float64,3} as 3×3 vector field) with eltype Gray{Normed{UInt8,8}}" ||
summary(dv2) == "512×512 DistortedView(::Array{Gray{N0f8},2}, ::Array{Float64,3} as 3×3 vector field) with eltype Gray{Normed{UInt8,8}}" ||
summary(dv2) == "512×512 DistortedView(::Array{Gray{N0f8},2}, ::Array{Float64,3} as 3×3 vector field) with eltype Gray{N0f8}"
@test_reference "reference/distort_static.txt" dv2

v = view(Augmentor.DistortedView(rand(10,10), A), 2:8, 3:10)
@test summary(v) == "7×8 view(Augmentor.DistortedView(::Array{Float64,2}, ::Array{Float64,3} as 3×3 vector field), 2:8, 3:10) with eltype Float64"
@test summary(v) == "7×8 view(Augmentor.DistortedView(::Array{Float64,2}, ::Array{Float64,3} as 3×3 vector field), 2:8, 3:10) with eltype Float64" ||
summary(v) == "7×8 view(DistortedView(::Array{Float64,2}, ::Array{Float64,3} as 3×3 vector field), 2:8, 3:10) with eltype Float64" ||
summary(v) == "7×8 view(DistortedView(::Matrix{Float64}, ::Array{Float64,3} as 3×3 vector field), 2:8, 3:10) with eltype Float64"
end

0 comments on commit 51172d8

Please sign in to comment.