Commit 6fd9d98
Fall back from unsafe_trunc in UniformStep kernel for non-float ratio types (#101)
* Fall back from unsafe_trunc in UniformStep kernel for non-float ratio types
The closed-form UniformStep kernels compute an integer index offset with
`unsafe_trunc(Int, floor(f))` / `unsafe_trunc(Int, ceil(f))`. `unsafe_trunc`
is only defined for hardware floats and `BigFloat`; for a `Rational` ratio
type it has no method, so a uniform `Rational` vector — which `Auto` resolves
to `KIND_UNIFORM_STEP` — threw a `MethodError` on every search.
`f` is already clamped to the in-range interval before truncation, so replace
the raw `unsafe_trunc` with a small dispatch helper: keep `unsafe_trunc` on
the `Base.IEEEFloat` hot path (in-range, so the range check is redundant) and
fall back to the checked `floor(Int, ·)` / `ceil(Int, ·)` for every other
ordered `Real` — which those types support and which is exact for the
clamped `f`. The IEEEFloat hot path is unchanged.
Adds a UniformStep regression testset over uniform `Rational{Int}`,
`Rational{BigInt}`, and `BigFloat` vectors, checking search results against
`Base`.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FvBXVKGujjeaCB3iLwsDeG
* QA: avoid non-public Base.IEEEFloat in UniformStep truncation helper
ExplicitImports' `all_qualified_accesses_are_public` check flags
`Base.IEEEFloat` — it is neither exported nor declared `public` in Base.
Spell out the hardware-float union `Union{Float16, Float32, Float64}`
(each of which is public) via a local `const` instead. No behavior change.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FvBXVKGujjeaCB3iLwsDeG
---------
Co-authored-by: ChrisRackauckas-Claude <accounts@chrisrackauckas.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 1351a3a commit 6fd9d98
2 files changed
Lines changed: 46 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
579 | 579 | | |
580 | 580 | | |
581 | 581 | | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
582 | 596 | | |
583 | 597 | | |
584 | 598 | | |
| |||
605 | 619 | | |
606 | 620 | | |
607 | 621 | | |
608 | | - | |
| 622 | + | |
609 | 623 | | |
610 | 624 | | |
611 | 625 | | |
| |||
640 | 654 | | |
641 | 655 | | |
642 | 656 | | |
643 | | - | |
| 657 | + | |
644 | 658 | | |
645 | 659 | | |
646 | 660 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1445 | 1445 | | |
1446 | 1446 | | |
1447 | 1447 | | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
0 commit comments