Skip to content

Commit 00ae122

Browse files
committed
Change TVI0d constructor to conditionally promote
Promoting a large number of ITimes is expensive, so this modifies the behavior to only do so if needed. fixes
1 parent 37bb7ab commit 00ae122

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

ext/TimeVaryingInputs0DExt.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ function TimeVaryingInputs.TimeVaryingInput(
105105
"LinearPeriodFillingInterpolation is not supported when the input data is 1D",
106106
)
107107
end
108-
108+
if eltype(times) <: ITime && eltype(times) isa UnionAll
109+
times = [promote(times...)...]
110+
end
109111
if extrapolation_bc(method) isa PeriodicCalendar
110112
if extrapolation_bc(method) isa PeriodicCalendar{Nothing}
111-
if !isequispaced(
112-
eltype(times) <: ITime ? [float.(promote(times...))...] : times,
113-
)
113+
if !isequispaced(eltype(times) <: ITime ? float.(times) : times)
114114
error(
115115
"PeriodicCalendar() boundary condition cannot be used because data is defined at non uniform intervals of time",
116116
)

test/time_varying_inputs.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ end
7676
method = TimeVaryingInputs.LinearPeriodFillingInterpolation(),
7777
)
7878

79+
# test promote when some input times do not contain an epoch
80+
promotion_tvi = TimeVaryingInputs.TimeVaryingInput(
81+
[ITime(0; epoch = DateTime(2010)), ITime(1)],
82+
ys,
83+
)
84+
@test all(t -> t.epoch == DateTime(2010), promotion_tvi.times)
85+
7986
# Test PeriodicCalendar with non simple duration
8087
@test_throws ErrorException TimeVaryingInputs.PeriodicCalendar(
8188
Month(2),

0 commit comments

Comments
 (0)