Repository navigation
Validate Rust tensor element types - #32035
Merged
Akshay Sonawane (apsonawane) merged 2 commits intoAug 13, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens tensor element type handling in the ONNX Runtime Rust bindings by replacing an unchecked transmute with an explicit fallible conversion that reports undefined/unsupported types via OrtError.
Changes:
- Added
OrtError::UnsupportedTensorElementType(i64)to represent tensor element types not supported by the Rust binding. - Implemented
TryFrom<sys::ONNXTensorElementDataType>forTensorElementDataTypeand updated session IO inspection to use it instead oftransmute. - Added unit tests for supported, undefined, and unsupported tensor element type conversions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| rust/onnxruntime/src/session.rs | Switches session IO type extraction to use TensorElementDataType::try_from(...) instead of transmute. |
| rust/onnxruntime/src/lib.rs | Adds TryFrom conversion logic for TensorElementDataType plus unit tests. |
| rust/onnxruntime/src/error.rs | Introduces a new OrtError variant for unsupported tensor element types. |
π‘ Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ti-Tai Wang (titaiwangms)
approved these changes
Aug 13, 2026
Akshay Sonawane (apsonawane)
deleted the
fix/rust-tensor-element-type-conversion
branch
August 13, 2026 23:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves how tensor element types are handled in the ONNX Runtime Rust bindings. It introduces more robust error handling for unsupported and undefined tensor element types, replacing previous unchecked conversions with a safe and explicit conversion mechanism. The most important changes are:
Error Handling Improvements:
OrtError::UnsupportedTensorElementType(i64)variant to represent unsupported tensor types, and updated theUndefinedTensorElementTypeerror message for clarity.Type Conversion and Safety:
TryFrom<sys::ONNXTensorElementDataType>forTensorElementDataType, returning descriptive errors for undefined or unsupported types instead of using unsafetransmute.dangerousmodule to use the newtry_fromconversion for tensor element types, eliminating unsafe casting and ensuring errors are handled explicitly.Testing:
Code Cleanliness:
TryFrominsession.rsto support the new conversion logic.