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

Block: Allow any AbstractDateTime #35

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/TimeDag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using AssociativeWindowAggregation
using Bijections
using DataStructures
using Dates
import Dates: AbstractDateTime
using LightGraphs
using LinearAlgebra
using PrettyTables
Expand Down
15 changes: 8 additions & 7 deletions src/block.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ validity of `times` & `values`.
with functions that accept blocks (e.g. [`TimeDag.run_node!`](@ref)), you must not
modify `times` or `values` members.
"""
struct Block{T,VTimes<:AbstractVector{DateTime},VValues<:AbstractVector{T}}
struct Block{T,D<:AbstractDateTime,VTimes<:AbstractVector{D},VValues<:AbstractVector{T}}
times::VTimes
values::VValues

function Block(
::UncheckedConstruction, times::VTimes, values::VValues
) where {T,VTimes<:AbstractVector{DateTime},VValues<:AbstractVector{T}}
return new{T,VTimes,VValues}(times, values)
) where {T,D<:AbstractDateTime,VTimes<:AbstractVector{D},VValues<:AbstractVector{T}}
return new{T,D,VTimes,VValues}(times, values)
end

function Block(
times::VTimes, values::VValues
) where {T,VTimes<:AbstractVector{DateTime},VValues<:AbstractVector{T}}
) where {T,D<:AbstractDateTime,VTimes<:AbstractVector{D},VValues<:AbstractVector{T}}
if length(times) != length(values)
throw(
ArgumentError(
Expand All @@ -74,15 +74,16 @@ struct Block{T,VTimes<:AbstractVector{DateTime},VValues<:AbstractVector{T}}
# TODO
# -> How make times & values immutable? Subclass of AbstractVector that doesn't
# implement setindex! ?
return new{T,VTimes,VValues}(times, values)
return new{T,D,VTimes,VValues}(times, values)
end
end

Block{T}() where {T} = Block(unchecked, DateTime[], T[])
Block{T,D}() where {T,D} = Block(unchecked, D[], T[])

function Block(
knots::Union{AbstractVector{Tuple{DateTime,T}},AbstractVector{Pair{DateTime,T}}}
) where {T}
knots::Union{AbstractVector{Tuple{D,T}},AbstractVector{Pair{D,T}}}
) where {T,D}
n = length(knots)
times = _allocate_times(n)
values = _allocate_values(T, n)
Expand Down