Skip to content

Commit

Permalink
Merge pull request #860 from mimiframework/timestep-perf
Browse files Browse the repository at this point in the history
Make a timestep getindex faster
  • Loading branch information
lrennels authored Oct 22, 2021
2 parents 6ea889e + 5fdd679 commit 1bebba9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/core/time_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ function Base.getindex(v::TimestepVector, ts::VariableTimestep{TIMES}) where {TI
end

function Base.getindex(v::TimestepVector{FixedTimestep{FIRST, STEP, LAST}, T_data}, ts::TimestepValue{T_time}) where {T_data, FIRST, STEP, LAST, T_time}
t = _get_time_value_position([FIRST:STEP:LAST...], ts)
t, remainder = divrem(ts.value - FIRST, STEP)
remainder==0 || error("Invalid index.")

t += ts.offset + 1

0 < t <= length(FIRST:STEP:LAST) || error("Invalid index.")

v.data isa SubArray ? view_offset = v.data.offset1 : view_offset = 0
t = t - view_offset
data = v.data[t]
Expand Down

0 comments on commit 1bebba9

Please sign in to comment.