access by UnitRange not implemented/performance issue with .x
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- julia
- Domain
- performance
Research direction
Start with ArrayPartition range indexing and the solution .x access shown in the issue's reproductions, then run the provided BenchmarkTools examples to compare them with flat arrays. Done means u0[1:4] works without a DimensionMismatch and the reported ArrayPartition access slowdown is addressed or its scope is clearly separated.
Written by the indexing model from the issue text.
Description
Access linearly works, but accessing via range does not:
u0=ArrayPartition(rand(1,2),rand(1,3))
u0[1:4]
DimensionMismatch("output array is the wrong size; expected (Base.OneTo(4),), got (5,)")
Although it can be avoided by something like u0[:][1:4]
Somewhat related, there seems to be quite a noticeable performance hit when accessing the solution's .x tuple. e.g.
using DifferentialEquations,RecursiveArrayTools
function eqn_flat(du,u,p,t)
du .= 0.3 .* u
end
function eqn(du,u,p,t)
for i in 1:RecursiveArrayTools.npartitions(u)
du.x[i] .= 0.3 .* u.x[i]
end
end
u0 = ArrayPartition([rand(2,2) for i in 1:20]...)
u0f = rand(2,2,20)
tspan=(0.0,30.0)
prob = ODEProblem(eqn,u0,tspan)
prob_f = ODEProblem(eqn_flat,u0f,tspan)
sol = solve(prob,Tsit5());
sol_f = solve(prob_f,Tsit5());
if one then wants to do further processing on the, e.g. first 10 2-by-2 matrices solution,
function process(sol)
f=[sol(tx)[:,:,j] for tx in 0:0.01:30, j in 1:10]
end
function process_x(sol)
f=[sol(tx).x[j] for tx in 0:0.01:30, j in 1:10]
end
function process_x_all(sol)
f=[reshape(sol(tx)[:][1:40],2,2,10) for tx in 0:0.01:30]
end
using BenchmarkTools
@btime process(sol_f);
67.081 ms (1050096 allocations: 39.59 MiB)
(julia default matrices method)
@btime process_x(sol);
254.091 ms (1649858 allocations: 84.89 MiB)
(access via.xtuple)
if we use : and change 2d comprehension to 1d, using process_x_all
@btime process_x_all(sol);
26.270 ms (182996 allocations: 12.20 MiB)
@btime process_x_all(sol_f);
6.594 ms (111015 allocations: 7.16 MiB)
of course, with the flat solution we do not need [:]
function process_x_all_flat(sol)
f=[reshape(sol(tx)[1:40],2,2,10) for tx in 0:0.01:30]
end
@btime process_x_all_flat(sol_f);
6.435 ms (108014 allocations: 5.06 MiB)
either way, looks like there's a 3~4x slowdown when accessing ArrayPartition.
- Dominant language
- Julia
- Stars
- 233
- Forks
- 76
- Avg merge
- 5h 33m
- Merged PRs (30d)
- 11
Contributor guide
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.
More from SciML/RecursiveArrayTools.jl
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
SciML/RecursiveArrayTools.jl#255 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
SciML/RecursiveArrayTools.jl#662 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
SciML/RecursiveArrayTools.jl#661 ·
-
JET: similar_type(::Any) no-matching-method in RecursiveArrayToolsRaggedArrays (pre-existing QA red) Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
SciML/RecursiveArrayTools.jl#620 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
SciML/RecursiveArrayTools.jl#619 ·
All issues in SciML/RecursiveArrayTools.jl
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
interpolate! from a Float32 LatitudeLongitudeGrid fails on Metal: Float64 division in find_λ_range Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
CliMA/Oceananigans.jl#6056 ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
JuliaPluto/PlutoPlotly.jl#72 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
epiforecasts/BVDOutbreakSize#811 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
SciML/NonlinearSolve.jl#1310 · 1 comment ·