Skip to content

Commit

Permalink
Use of_eltype instead of convert lambda (#95)
Browse files Browse the repository at this point in the history
This commit changes `mappedarray(c->convert(T,c), img)` to `of_eltype(T, img)`. It results into `MappedArray` instead of `ReadonlyMappedArray`, and it is more descriptive too.
  • Loading branch information
barucden authored Aug 9, 2021
1 parent 8a0de3c commit b3a1873
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
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

0 comments on commit b3a1873

Please sign in to comment.