MappedArrays.jl
MappedArrays.jl copied to clipboard
Pass more array information
Some trivial information queries become time-consuming because currently there's no way to pass this extra information. And it just falls back to apply the function again and again and again and becomes very inefficient.
using TestImages, ImageTransformations
img = testimage("cameraman")
As = mappedarray(θ->imrotate(img, θ, axes(img)), -π/4:π/16:π/4);
@btime size.($As); # 22.033 ms (136 allocations: 2.26 MiB)
@btime collect($As); # 22.880 ms (127 allocations: 2.26 MiB)
For this very specific case, axes
can be known prior.
I am not sure what there is to do here.
julia> f = θ->imrotate(img, θ, axes(img))
#11 (generic function with 1 method)
julia> typeof(f(π/4))
Matrix{ColorTypes.Gray{FixedPointNumbers.N0f8}} (alias for Array{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8, 8}}, 2})
julia> Base.return_types(f, (typeof(π/4),))
1-element Vector{Any}:
Any
Even if imrotate
was written such that the type was inferred correctly, the type itself does not contain information about axes
(unlike e.g. StaticArrays.StaticArray
, or Tuple
.).
Said differently, it does not seem like a MappedArrays.jl
issue. I don't know how to get the following answer without evaluating f
:
julia> axes(f(π/4))
(Base.OneTo(512), Base.OneTo(512))