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

Make constant interpolation dimensionally consistent #381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ickaser
Copy link
Contributor

@Ickaser Ickaser commented Jan 24, 2025

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

After 7.0 (which made good changes), the extrapolation procedures are not kind to Unitful numbers.

MWE:

t = range(0.0u"s", 10.0u"s", length = 11)
P = exp.(t/u"s")*u"W"

P_interp = ConstantInterpolation(P, t; extrapolation=ExtrapolationType.Constant)

P_interp(11u"s")

Without this PR, this produces a DimensionError:

ERROR: DimensionError: 1.0 W and 0.0 s W are not dimensionally compatible.
Stacktrace:
 [1] +(x::Quantity{Float64, 𝐋^2 𝐌 𝐓^-3, Unitful.FreeUnits{…}}, y::Quantity{Float64, 𝐋^2 𝐌 𝐓^-2, Unitful.FreeUnits{…}})
   @ Unitful C:\Users\iwheeler\.julia\packages\Unitful\nwwOk\src\quantities.jl:137
 [2] _extrapolate_left(A::ConstantInterpolation{…}, t::Quantity{…})
   @ DataInterpolations C:\Users\iwheeler\.julia\dev\DataInterpolations\src\interpolation_methods.jl:17
 [3] _interpolate
   @ C:\Users\iwheeler\.julia\packages\DataInterpolations\5Uosd\src\interpolation_methods.jl:3 [inlined]
 [4] AbstractInterpolation
   @ C:\Users\iwheeler\.julia\packages\DataInterpolations\5Uosd\src\DataInterpolations.jl:27 [inlined]
 [5] (::ConstantInterpolation{…})(u::Vector{…}, t::StepRangeLen{…})
   @ DataInterpolations C:\Users\iwheeler\.julia\dev\DataInterpolations\src\DataInterpolations.jl:56
 [6] (::ConstantInterpolation{…})(t::StepRangeLen{…})
   @ DataInterpolations C:\Users\iwheeler\.julia\dev\DataInterpolations\src\DataInterpolations.jl:31
 [7] top-level scope
   @ c:\Users\iwheeler\OneDrive - purdue.edu\Documents\LyoResearch\LyoPronto.jl_NIIMBL\scripts\mwe.jl:12

A related bug that prompted this involved typed_nan not having a definition for Unitful quantities, which is why I expand it to <:Number, not just <:AbstractFloat

(This PR was prepared in a hurry while I was distracted. Will take a second look later on and make sure this is consistent throughout.)

@ChrisRackauckas
Copy link
Member

Needs tests or this is guaranteed to regress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants