JuliaArrays / JuliaArrays/MappedArrays.jl
Avoid repeating the calculation, retain the results
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 88
- Forks
- 15
- PR merge metrics
- No merged PRs in 30d
Description
It would be really cool if the calculated result of some cell in an array was somehow saved for repeated access:
fun(x) = (sleep(1/3); 2x)
x = rand(3)
fun.(x) # this takes about 1 second
mx = mappedarray(fun, x); # this is ultra quick
for i in 1:3 # first iteration should take 1/3 seconds, the two subsequent iterations should be instantaneous
mx[1]
end # they're not, this loop takes about a second to complete
The rational behind this is that with normal arrays you pay computation time for the map for ALL the cells (while you really might not need all of them), but that's a one-time cost, repeated access is cheap. With mapped arrays you pay the calculation price only for the cells you need, winning, but if you need to access them repeatedly then this gain in time can be quickly lost.
Note that I think I can get this by using Memoize and @memoizeing the mapped function...
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the mappedarray entry point and how indexed access invokes the mapped function. Define the behavior for retaining results so the first access computes a cell and repeated access avoids recomputation, while preserving lazy evaluation for cells that have not been accessed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100