Skip to content

Commit df73c25

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.
1 parent 37bb7ab commit df73c25

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ext/TimeVaryingInputs0DExt.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,16 @@ function TimeVaryingInputs.TimeVaryingInput(
108108

109109
if extrapolation_bc(method) isa PeriodicCalendar
110110
if extrapolation_bc(method) isa PeriodicCalendar{Nothing}
111+
if eltype(times) <: ITime
112+
t0 = times[begin]
113+
if !(isnothing(t0.epoch) || all(t -> t.epoch == t0.epoch, times))
114+
# promote if times have inconsistent epochs
115+
# this is a slow operation
116+
times = promote(times...)
117+
end
118+
end
111119
if !isequispaced(
112-
eltype(times) <: ITime ? [float.(promote(times...))...] : times,
120+
eltype(times) <: ITime ? floats.(time) : times,
113121
)
114122
error(
115123
"PeriodicCalendar() boundary condition cannot be used because data is defined at non uniform intervals of time",

0 commit comments

Comments
 (0)