Skip to content

ndarray::simd re-exports + checked i64 arithmetic for ONNX shape ops - #401

Merged
AdaWorldAPI merged 2 commits into
masterfrom
ccr-45a41fb4-0j3i0l
Oct 30, 2026
Merged

AdaWorldAPI merged 2 commits into
masterfrom
ccr-45a41fb4-0j3i0l

Conversation

@AdaWorldAPI

@AdaWorldAPI AdaWorldAPI commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Two independent commits.

1. 7257896 — re-exports through ndarray::simd

Plain pub use, no wrappers, no behaviour change:

  • hpc::vml: vsexp, vsln, vssqrt, vsabs, vsadd, vsmul, vsdiv, vssin, vscos, vspow, vstanh, vserf, vsfloor, vsceil, vsround, vsneg, vstrunc
  • hpc::activations: sigmoid_f32, softmax_f32, log_softmax_f32, softmax_axis_f32, log_softmax_axis_f32
  • hpc::amx_matmul: matmul_f32_batched, MatmulError, gated #[cfg(target_arch = "x86_64")] like the module

matmul_f32 itself is not re-exported: under runtime-dispatch the name simd::matmul_f32 already belongs to the simd_runtime trampoline, which has a different signature.

Tests: tests/simd_facade_reexports.rs (4) checks each simd:: path gives bit-identical output to its hpc:: home. Disable run: dropping vserf from the re-export fails the build with E0425.

2. df04b87 — hpc::checked_i64 (the Tract-requested int64 wishlist)

Signatures:

pub enum I64Op { Add, Sub, Mul, Div }
pub enum I64ArithError {
    Overflow { op: I64Op, position: usize, lhs: i64, rhs: i64 },
    DivisionByZero { position: usize, lhs: i64 },
    LengthMismatch { lhs: usize, rhs: usize, out: usize },
    RangeZeroDelta,
    RangeExceedsCapacity { len: u64, capacity: usize },
}
pub fn checked_i64(op: I64Op, lhs: i64, rhs: i64) -> Result<i64, I64ArithError>;
pub fn checked_binary_i64(op: I64Op, lhs: &[i64], rhs: &[i64], out: &mut [i64]) -> Result<(), I64ArithError>;
pub fn range_len_i64(start: i64, limit: i64, delta: i64) -> Result<u64, I64ArithError>;
pub fn range_i64(start: i64, limit: i64, delta: i64, out: &mut [i64]) -> Result<usize, I64ArithError>;

Policy, shared by every operation through checked_i64:

  • A result outside i64 is refused with the operation, output position and operands. Never wrapped, never saturated.
  • Div truncates toward zero (ORT integer division). Zero divisor → DivisionByZero; i64::MIN / -1 → Overflow.
  • Operands are flat slices of the output's length or length 1 (scalar broadcast). Any other length → LengthMismatch. N-d broadcasting stays in Tract's graph.
  • On any refusal out is unchanged: every element is checked before out is written.
  • Range follows ONNX: max(ceil((limit - start) / delta), 0) elements, computed exactly in i128. A range running the wrong way is empty. delta == 0 → RangeZeroDelta. A range longer than out → RangeExceedsCapacity (the bound is the caller's buffer). The full i64::MIN..i64::MAX span reports len = u64::MAX.

Negative fixtures (all in negative_fixtures_refuse_with_their_information and its neighbours):

input refusal
Add(i64::MAX, 1) Overflow { op: Add, position: 0, lhs: i64::MAX, rhs: 1 }
Sub(i64::MIN, 1) Overflow { op: Sub, .. }
Mul(3_037_000_500, 3_037_000_500) Overflow { op: Mul, .. }
Mul(i64::MIN, -1) Overflow { op: Mul, .. }
Div(i64::MIN, -1) Overflow { op: Div, .. }
Div(5, 0) DivisionByZero { position: 0, lhs: 5 }
Add([1, 2, i64::MAX, 4], [1]) Overflow { position: 2, .. }, out unchanged
Div([6, 6, 6, 6], [3, 2, 1, 0]) DivisionByZero { position: 3, lhs: 6 }, out unchanged
lengths 2 and 4 into 4 LengthMismatch { lhs: 2, rhs: 4, out: 4 }
Range(0, 10, 0) RangeZeroDelta
Range(0, 5, 1) into 4 slots RangeExceedsCapacity { len: 5, capacity: 4 }, out unchanged

Tests (7 unit + 3 doctests), all pass on x86_64 and i686:

  • every pair from a 13-value edge set (including i64::MIN, i64::MAX, ±√2⁶³ and ±2³²) × 4 ops against exact i128 arithmetic: each result either matches, or is refused exactly when the exact value does not fit;
  • truncation toward zero, distinguished from floor division (-7 / 2 = -3, not -4);
  • Range against a reference loop over start, limit ∈ [-9, 9] and 7 deltas, plus both ends of i64.

Disable runs, each red then restored:

disable failing test
D1 Add wraps 3 tests
D2 zero-divisor check removed 3 tests
D3 check-before-write pass removed slices_broadcast_… (out written on refusal)
D4 position not reported slices_broadcast_…
D5 length check weakened unsupported_broadcasting_refuses
D6 delta == 0 accepted range_refuses_zero_delta_and_overlong_output
D7 range truncated to capacity range_refuses_zero_delta_and_overlong_output

No shape graph, no ONNX interpreter, no new generic types. Not re-exported through ndarray::simd: this is plain scalar arithmetic, not SIMD.

Checks

  • cargo clippy --features std --all-targets -D warnings: clean.
  • aarch64 cargo check --tests: clean (commit 1).
  • --features std,runtime-dispatch: clean, no name collision.
  • FACET STRIDE guard on the diff: clean.

Not merged automatically.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XAqKMPh2Seh2WLccCksAdY

…darray::simd

Plain pub use re-exports of hpc::vml (vsexp, vsln, vssqrt, vsabs, vsadd,
vsmul, vsdiv, vssin, vscos, vspow, vstanh, vserf, vsfloor, vsceil, vsround,
vsneg, vstrunc), hpc::activations (sigmoid_f32, softmax_f32,
log_softmax_f32, softmax_axis_f32, log_softmax_axis_f32) and, under the
same target_arch = "x86_64" gate as its module, hpc::amx_matmul's
matmul_f32_batched and MatmulError. No wrappers. matmul_f32 is not
re-exported because under runtime-dispatch that simd:: name is the
simd_runtime trampoline.

tests/simd_facade_reexports.rs checks each simd:: path gives bit-identical
output to its hpc:: home.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XAqKMPh2Seh2WLccCksAdY
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 26d42511-71f1-4044-9b3e-439db69d46b6
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

hpc::checked_i64 has one policy for every operation: a result outside
i64 is refused with the operation, output position and operands, never
wrapped or saturated. Div truncates toward zero; a zero divisor and
i64::MIN / -1 are refused. checked_binary_i64 takes flat slices where a
length-1 operand broadcasts, refuses any other length, and leaves out
unchanged on refusal. range_i64 follows ONNX Range, computes the length
exactly in i128, refuses delta 0 and a range longer than out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XAqKMPh2Seh2WLccCksAdY
@AdaWorldAPI AdaWorldAPI changed the title Re-export VML words, activations and batched f32 matmul through ndarray::simd ndarray::simd re-exports + checked i64 arithmetic for ONNX shape ops Oct 30, 2026
@AdaWorldAPI
AdaWorldAPI marked this pull request as ready for review October 30, 2026 11:26
@AdaWorldAPI
AdaWorldAPI merged commit e55d3a0 into master Oct 30, 2026
31 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T11:28:05.704513Z df04b87 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

AdaWorldAPI pushed a commit that referenced this pull request Oct 30, 2026
Records #402, plus the rows #400 and #401 moved. New dots N22-N26: the
adders as facade words with no consumer yet, the exp speed-up reaching
every exp-based word, AVX2 select mask packing as a second array-backed
cost, NEON scalar fcmp/csel in simd_exp_f32, and the transactional
Abacus against the non-transactional eager counter. Fruit L20, L21, H12,
H13; PR C not planned.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XAqKMPh2Seh2WLccCksAdY
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