MappedArrays.jl icon indicating copy to clipboard operation
MappedArrays.jl copied to clipboard

Pass more array information

Open johnnychen94 opened this issue 3 years ago • 1 comments

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.

johnnychen94 avatar Apr 14 '21 09:04 johnnychen94

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))

goretkin avatar Apr 14 '21 21:04 goretkin