Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix type instability in interpolating_time_indices(::Clamp, …)#5732

Merged
xkykai merged 1 commit into
mainfrom
xk/fix-clamp-time-indices-type-instability
Jun 27, 2026
Merged

Fix type instability in interpolating_time_indices(::Clamp, …)#5732
xkykai merged 1 commit into
mainfrom
xk/fix-clamp-time-indices-type-instability

Conversation

@xkykai

@xkykai xkykai commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5731.

interpolating_time_indices(::Clamp, times, t) built its clamped index tuples with a literal 0 for the fractional time index, while the in-range tuple used the Float64 value ñ:

beyond_indices    = (0, n₂, n₂)
before_indices    = (0, n₁, n₁)
unclamped_indices = (ñ, n₁, n₂)

The ifelse over these tuples then inferred as Union{Tuple{Int,Int,Int}, Tuple{Float64,Int,Int}} — a type instability.

This also produces a Reactant compile warning on every compile ("ifelse with different element-types in Reactant works by promoting the element-type to the common type"), since Reactant maps ifelse element-wise over tuples. Because Clamp() is the default time-indexing mode for FieldTimeSeries, this fired for essentially any Reactant-compiled model interpolating time series data.

Fix

Replace the literal 0 with zero(ñ) so all branches share an element type, matching the pattern already used in the sibling find_time_index function:

beyond_indices    = (zero(ñ), n₂, n₂)
before_indices    = (zero(ñ), n₁, n₁)

🤖 Generated with Claude Code

The clamped index tuples used literal `0` for the fractional time index
while the in-range tuple used the `Float64` value `ñ`, so the `ifelse`
result inferred as `Union{Tuple{Int,Int,Int}, Tuple{Float64,Int,Int}}`.

Use `zero(ñ)` so all branches share an element type, matching the
pattern already used in `find_time_index`. This also removes the
Reactant compile warning about `ifelse` promoting mixed element-types,
which fired for any Reactant-compiled model interpolating a
FieldTimeSeries (Clamp is the default time-indexing mode).

Closes #5731

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@xkykai xkykai merged commit 21fedcd into main Jun 27, 2026
87 of 89 checks passed
@xkykai xkykai deleted the xk/fix-clamp-time-indices-type-instability branch June 27, 2026 17:22
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.

Type-unstable ifelse over tuples in interpolating_time_indices(::Clamp, …) (mixed Int/Float64 slot)

2 participants