Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestep Arrays View #963

Merged
merged 6 commits into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/core/time_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,38 @@ function hasvalue(arr::TimestepArray{VariableTimestep{A_TIMES}, T, N, ti},
return A_TIMES[1] <= gettime(ts) <= last_period(arr) && all([1 <= idx <= size(arr, i) for (i, idx) in enumerate(idxs)])
end

#
# View Methods
#

function _missing_view_data_check(data, t)
if data[1] === missing
throw(MissingException("Cannot get index; data is missing. You may have tried to access a value in timestep $t that has not yet been computed."))
else
return data
end
end

function _missing_data_view_check(data)
if data[1] === missing
throw(MissingException("Cannot get index; data is missing."))
else
return data
end
end

# TimestepArray methods - incomplete - could expand to include all possible permutations

function Base.view(arr::TimestepArray{FixedTimestep{A_FIRST, A_STEP, A_LAST}, T, N, ti}, idxs::Union{FixedTimestep{T_FIRST, T_STEP, T_LAST}, AnyIndex}...) where {A_FIRST, A_STEP, A_LAST, T_FIRST, T_STEP, T_LAST, T, N, ti}
idxs1, ts, idxs2 = idxs[1:ti - 1], idxs[ti], idxs[ti + 1:end]
return _missing_data_view_check(view(arr.data, idxs1..., ts.t, idxs2...))
end

function Base.view(arr::TimestepArray{VariableTimestep{A_TIMES}, T, N, ti}, idxs::Union{VariableTimestep{T_TIMES}, AnyIndex}...) where {A_TIMES, T_TIMES, T, N, ti}
idxs1, ts, idxs2 = idxs[1:ti - 1], idxs[ti], idxs[ti + 1:end]
return _missing_data_view_check(view(arr.data, idxs1..., ts.t, idxs2...))
end

##
## DEPRECATIONS - Should move from warning --> error --> removal
##
Expand Down