From 733e32bebf8176bc0843b9679029d3ae147047b9 Mon Sep 17 00:00:00 2001 From: JohnnyChen Date: Wed, 18 Dec 2019 06:37:14 +0800 Subject: [PATCH] fix commit "WIP: update 1.0" --- src/distortedview.jl | 11 ++--------- src/operation.jl | 2 ++ test/operations/tst_distortions.jl | 11 +++++++++-- test/tst_operations.jl | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/distortedview.jl b/src/distortedview.jl index 62f3996e..4de4e0d3 100644 --- a/src/distortedview.jl +++ b/src/distortedview.jl @@ -6,21 +6,14 @@ struct DistortedView{T,P<:AbstractMatrix,E<:AbstractExtrapolation,G,D} <: Abstra function DistortedView(parent::AbstractMatrix{T}, grid::AbstractArray{Float64,3}) where T @assert size(grid,1) == 2 + # to compare two DistortedViews, their `axes` should be the same + parent = plain_axes(parent) etp = ImageTransformations.box_extrapolation(parent, Flat()) field = ImageTransformations.box_extrapolation(grid, 0.0) new{T,typeof(parent),typeof(etp),typeof(grid),typeof(field)}(parent, etp, grid, field) end end -# TODO: update1.0: check if these two methods are unnecessary -function DistortedView(A::Union{OffsetArray, SubArray}, - grid::AbstractArray{Float64, 3}) - DistortedView(parent(A), grid) -end -function DistortedView(A::InvWarpedView, grid::AbstractArray{Float64, 3}) - DistortedView(collect(A), grid) -end - Base.parent(A::DistortedView) = A.parent Base.size(A::DistortedView) = map(length, axes(A)) Base.axes(A::DistortedView) = axes(A.parent) diff --git a/src/operation.jl b/src/operation.jl index a6e5ef95..477ab276 100644 --- a/src/operation.jl +++ b/src/operation.jl @@ -63,6 +63,8 @@ for FUN in (:applyeager, :applylazy, :applypermute, end function applyeager(op::Operation, img::AbstractArray, param) + # TODO: we don't need wrappers for eager mode, so we might want to + # add plain_array to it as well for the sake of simplicity contiguous(applylazy(op, img, param)) end diff --git a/test/operations/tst_distortions.jl b/test/operations/tst_distortions.jl index b01e21a6..5dc3816c 100644 --- a/test/operations/tst_distortions.jl +++ b/test/operations/tst_distortions.jl @@ -122,8 +122,15 @@ res = @inferred(Augmentor.applylazy(ElasticDistortion(4,4), img)) @test size(res) == size(rect) @test typeof(res) <: Augmentor.DistortedView{eltype(rect)} - # @test parent(res) == img # TODO: update1.0: - # @test parent(res) === img # TODO: update1.0: + @test parent(res) == rect + # wapper type may change, but storage data isn't copied + if img isa InvWarpedView + @test parent(parent(res)) === img + elseif img isa SubArray + @test parent(parent(res)) === rect + else + @test parent(parent(res)) === rect + end end end @testset "multiple images" begin diff --git a/test/tst_operations.jl b/test/tst_operations.jl index c2803b48..73e05990 100644 --- a/test/tst_operations.jl +++ b/test/tst_operations.jl @@ -172,7 +172,7 @@ ops = (Rotate180(), ElasticDistortion(5)) @test_throws MethodError Augmentor.unroll_applyaffine(ops, square) v = @inferred Augmentor.unroll_applylazy(ops, square) @test v isa Augmentor.DistortedView - @test_broken parent(v) === view(square, 3:-1:1, 3:-1:1) # TODO: update1.0 + @test parent(v) === view(square, 3:-1:1, 3:-1:1) end ops = (Rotate180(), CropSize(2,2))