Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of_eltype instead of convert lambda #95

Merged
merged 2 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/operations/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function applyeager(op::ConvertEltype{T}, img::AbstractArray, param) where T
end

function applylazy(op::ConvertEltype{T}, img::AbstractArray, param) where T
mappedarray(c->convert(T,c), img)
of_eltype(T, img)
end

function showconstruction(io::IO, op::ConvertEltype)
Expand Down
29 changes: 22 additions & 7 deletions test/operations/tst_convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,45 +57,45 @@
@test @inferred(Augmentor.supports_lazy(typeof(ConvertEltype(Gray{N0f8})))) === true
let img = @inferred(Augmentor.applylazy(ConvertEltype(Gray{Float32}), OffsetArray(rect,-2,-1)))
@test parent(parent(img)) === rect
@test typeof(img) <: ReadonlyMappedArray{Gray{Float32},2}
@test typeof(img) <: MappedArray{Gray{Float32},2}
@test axes(img) == (OffsetRange(-1:0), OffsetRange(0:2))
@test img[0,0] isa Gray{Float32}
@test collect(img) == convert.(Gray{Float32}, rect)
end
let img = @inferred(Augmentor.applylazy(ConvertEltype(Gray{Float32}), Augmentor.prepareaffine(rect)))
@test parent(parent(parent(parent(img)))) === rect
@test typeof(img) <: ReadonlyMappedArray{Gray{Float32},2}
@test typeof(img) <: MappedArray{Gray{Float32},2}
@test axes(img) === (1:2, 1:3)
@test img[1,1] isa Gray{Float32}
@test collect(img) == convert.(Gray{Float32}, rect)
end
let img = @inferred(Augmentor.applylazy(ConvertEltype(Gray{Float32}), view(rect, IdentityRange(1:2), IdentityRange(1:3))))
@test parent(parent(img)) === rect
@test typeof(img) <: ReadonlyMappedArray{Gray{Float32},2}
@test typeof(img) <: MappedArray{Gray{Float32},2}
@test axes(img) === (1:2, 1:3)
@test img[1,1] isa Gray{Float32}
@test collect(img) == convert.(Gray{Float32}, rect)
end
let img = @inferred(Augmentor.applylazy(ConvertEltype(Gray{Float32}), rgb_rect))
@test parent(img) === rgb_rect
@test axes(img) === (Base.OneTo(2), Base.OneTo(3))
@test typeof(img) <: ReadonlyMappedArray{Gray{Float32},2}
@test typeof(img) <: MappedArray{Gray{Float32},2}
@test img == convert.(Gray{Float32}, rgb_rect)
end
let img = @inferred(Augmentor.applylazy(ConvertEltype(Float32), checkers))
@test parent(img) === checkers
@test axes(img) === (Base.OneTo(3), Base.OneTo(5))
@test typeof(img) <: ReadonlyMappedArray{Float32,2}
@test typeof(img) <: MappedArray{Float32,2}
@test img == convert(Array{Float32}, checkers)
end
let img = @inferred(Augmentor.applylazy(ConvertEltype(RGB{N0f8}), checkers))
@test parent(img) === checkers
@test typeof(img) <: ReadonlyMappedArray{RGB{N0f8},2}
@test typeof(img) <: MappedArray{RGB{N0f8},2}
@test img == convert.(RGB, checkers)
end
let img = @inferred(Augmentor.applylazy(ConvertEltype(RGB{Float64}), checkers))
@test parent(img) === checkers
@test typeof(img) <: ReadonlyMappedArray{RGB{Float64},2}
@test typeof(img) <: MappedArray{RGB{Float64},2}
@test img == convert.(RGB{Float64}, checkers)
end
end
Expand All @@ -108,4 +108,19 @@
@testset "permute" begin
@test Augmentor.supports_permute(ConvertEltype) === false
end
@testset "inference" begin
img = testpattern()
let pl = ConvertEltype(Gray)
aug_img = @inferred(augment(img, pl))
@test eltype(aug_img) <: Gray
end
let pl = SplitChannels() |> ConvertEltype(Gray)
aug_img = @inferred(augment(img, pl))
@test eltype(aug_img) <: Gray{N0f8}
end
let pl = ConvertEltype(Gray) |> SplitChannels()
aug_img = @inferred(augment(img, pl))
@test eltype(aug_img) <: N0f8
end
end
end