Hey,
we recently created IndexFunArrays.jl.
You can try it with:
julia> ] add IndexFunArrays
Initially we wanted a tool calculating output arrays using the index position. For that purpose we created a IndexFunArray (with size independent constant memory allocation) which calculates the value once accessed with getindex. It needs an index function and a output size:
julia> z = IndexFunArray(x -> sum(abs2.(x)), (3, 3)) # directly using the constructor and supplying a function to store in the array
3Ă—3 IndexFunArray{Int64, 2, var"#184#185"}:
2 5 10
5 8 13
10 13 18
julia> typeof(z) <: AbstractArray
true
julia> z[3,3] # use it like a normal array which then calculates the value
18
For convenience we already created several distance related wrapper and some window functions:
julia> rr2((4, 4))
4Ă—4 IndexFunArray{Float64, 2, IndexFunArrays.var"#4#5"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
8.0 5.0 4.0 5.0
5.0 2.0 1.0 2.0
4.0 1.0 0.0 1.0
5.0 2.0 1.0 2.0
julia> rr2((3,3), offset=CtrCorner)
3Ă—3 IndexFunArray{Float64, 2, IndexFunArrays.var"#4#5"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
0.0 1.0 4.0
1.0 2.0 5.0
4.0 5.0 8.0
julia> rr2((3,3), offset=(4,4))
3Ă—3 IndexFunArray{Float64, 2, IndexFunArrays.var"#4#5"{Float64, Tuple{Int64, Int64}, Tuple{Int64, Int64}}}:
18.0 13.0 10.0
13.0 8.0 5.0
10.0 5.0 2.0
The package works with other packages like LazyArrays or CUDA.
We were curious if there isn’t something similar already? Maybe some of you know more about.
We would be happy about feedback!
Thanks,
Felix