onnxruntime
2b801da6 - Validate Rust tensor element types (#32035)

Commit
88 days ago
Validate Rust tensor element types (#32035) 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:** * Added a new `OrtError::UnsupportedTensorElementType(i64)` variant to represent unsupported tensor types, and updated the `UndefinedTensorElementType` error message for clarity. **Type Conversion and Safety:** * Implemented `TryFrom<sys::ONNXTensorElementDataType>` for `TensorElementDataType`, returning descriptive errors for undefined or unsupported types instead of using unsafe `transmute`. * Updated code in `dangerous` module to use the new `try_from` conversion for tensor element types, eliminating unsafe casting and ensuring errors are handled explicitly. **Testing:** * Added unit tests to verify that supported types convert successfully, undefined types return the correct error, and unsupported types are properly rejected. **Code Cleanliness:** * Added necessary imports for `TryFrom` in `session.rs` to support the new conversion logic.
Author
Parents
Loading