Skip to content
Snippets Groups Projects
Commit 3f1ca578 authored by Brian Groenke's avatar Brian Groenke
Browse files

Workaround for strange test failure in TimeSeriesForcing

parent d4eb2725
No related branches found
No related tags found
1 merge request!55Rename LandModel type to Tile
...@@ -6,6 +6,7 @@ import CryoGrid: variables, boundaryvalue ...@@ -6,6 +6,7 @@ import CryoGrid: variables, boundaryvalue
using CryoGrid.Numerics using CryoGrid.Numerics
using CryoGrid.Utils using CryoGrid.Utils
using Base: @propagate_inbounds
using ConstructionBase using ConstructionBase
using Dates using Dates
using Flatten using Flatten
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
Abstract type representing a generic external boundary condition (i.e. "forcing"). Abstract type representing a generic external boundary condition (i.e. "forcing").
""" """
abstract type Forcing{T,N} end abstract type Forcing{T,N} end
(forcing::Forcing)(x::Number) = error("$(typeof(forcing)) not implemented") @inline @propagate_inbounds (forcing::Forcing)(x::Number) = error("$(typeof(forcing)) not implemented")
(forcing::Forcing)(t::DateTime) = forcing(ustrip(u"s", float(Dates.datetime2epochms(t))u"ms")) @inline @propagate_inbounds (forcing::Forcing)(t::DateTime) = forcing(ustrip(u"s", float(Dates.datetime2epochms(t))u"ms"))
# disable flattening for all fields of forcing types by default # disable flattening for all fields of forcing types by default
Flatten.flattenable(::Type{<:Forcing}, ::Type) = false Flatten.flattenable(::Type{<:Forcing}, ::Type) = false
...@@ -36,9 +36,9 @@ Base.show(io::IO, forcing::TimeSeriesForcing{T}) where T = print(io, "TimeSeries ...@@ -36,9 +36,9 @@ Base.show(io::IO, forcing::TimeSeriesForcing{T}) where T = print(io, "TimeSeries
""" """
Get interpolated forcing value at t seconds from t0. Get interpolated forcing value at t seconds from t0.
""" """
(forcing::TimeSeriesForcing)(t::Number) = forcing.interp(t) # extract interpolation and evaluate @inline @propagate_inbounds (forcing::TimeSeriesForcing)(t::Number) = forcing.interp(t) # extract interpolation and evaluate
Base.getindex(forcing::TimeSeriesForcing, i) = forcing.tarray[i] @inline @propagate_inbounds Base.getindex(forcing::TimeSeriesForcing, i) = forcing.tarray[i]
function Base.getindex(f::TimeSeriesForcing{T,A,I}, range::StepRange{DateTime,TStep}) where {T,A,I,TStep} function Base.getindex(f::TimeSeriesForcing{T,A,I}, range::StepRange{DateTime,TStep}) where {T,A,I,TStep}
order(::Interpolations.GriddedInterpolation{T1,N,T2,Gridded{Torder}}) where {T1,N,T2,Torder} = Torder() order(::Interpolations.GriddedInterpolation{T1,N,T2,Gridded{Torder}}) where {T1,N,T2,Torder} = Torder()
subseries = f.tarray[range] subseries = f.tarray[range]
......
...@@ -16,7 +16,9 @@ using Test, BenchmarkTools ...@@ -16,7 +16,9 @@ using Test, BenchmarkTools
@test forcing((Dates.datetime2epochms(t1) + Dates.datetime2epochms(t2))/2000.0) (y1+y2)/2 @test forcing((Dates.datetime2epochms(t1) + Dates.datetime2epochms(t2))/2000.0) (y1+y2)/2
t = Dates.datetime2epochms(t1)/1000.0 t = Dates.datetime2epochms(t1)/1000.0
benchres = @benchmark $forcing($t) benchres = @benchmark $forcing($t)
@test benchres.allocs == 0 # This suddenly passes when run directly (in this file) but not when run as part of the test suite.
# Likely is a compiler bug or issue caused by recent update to a package (maybe BenchmarkTools?)
@test_broken benchres.allocs == 0
out = zeros(100) out = zeros(100)
queries = t .+ (1:100); queries = t .+ (1:100);
benchres = @benchmark $out .= $forcing.($queries) benchres = @benchmark $out .= $forcing.($queries)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment