1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//! # RunNX: A Minimal ONNX Runtime in Rust
//!
//! This crate provides a minimal, verifiable implementation of an ONNX runtime
//! focused on educational purposes and simplicity while maintaining performance.
//!
//! ## Key Features
//!
//! - **Dual Format Support**: Both JSON and binary ONNX protobuf formats
//! - **Auto-detection**: Automatic format detection based on file extension
//! - **Simple Architecture**: Easy to understand and extend
//! - **Type Safety**: Leverages Rust's type system for memory safety
//! - **Performance**: Efficient tensor operations using ndarray
//! - **Verifiable**: Comprehensive tests and clear documentation
//!
//! ## Quick Start
//!
//! ```rust
//! use runnx::{Model, Tensor};
//! use ndarray::Array2;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Load a model (supports both JSON and ONNX binary formats)
//! // let model = Model::from_file("model.onnx")?; // Auto-detects format
//! // let model = Model::from_file("model.json")?; // Auto-detects format
//!
//! // Create a simple tensor
//! let input = Tensor::from_array(Array2::from_elem((2, 3), 1.0));
//! let weights = Tensor::from_array(Array2::from_elem((3, 4), 0.5));
//!
//! // Perform matrix multiplication
//! let result = input.matmul(&weights)?;
//! println!("Result shape: {:?}", result.shape());
//! # Ok(())
//! # }
//! ```
//!
//! ## Format Support
//!
//! RunNX supports both formats with automatic detection:
//!
//! - **JSON Format** (`.json`): Human-readable, easy to debug
//! - **ONNX Binary** (`.onnx`): Compact, standard ONNX protobuf format
//!
//! ```rust
//! use runnx::Model;
//!
//! # fn example() -> runnx::Result<()> {
//! // Auto-detection based on extension
//! let json_model = Model::from_file("model.json")?;
//! let onnx_model = Model::from_file("model.onnx")?;
//!
//! // Explicit format specification
//! let json_model = Model::from_json_file("model.json")?;
//! let onnx_model = Model::from_onnx_file("model.onnx")?;
//!
//! // Save in different formats
//! json_model.to_onnx_file("converted.onnx")?;
//! onnx_model.to_json_file("converted.json")?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Architecture Overview
//!
//! The runtime consists of several core components:
//!
//! - [`Model`] - ONNX model representation
//! - [`Graph`] - Computational graph with nodes and edges
//! - [`Tensor`] - N-dimensional array with type safety
//! - [`operators`] - ONNX operation implementations
//! - [`runtime`] - Execution engine
//!
//! ## Error Handling
//!
//! All operations return [`Result`] types with descriptive error messages.
//! The main error type is [`OnnxError`] which covers various failure modes.
pub
// Re-export main types
pub use ;
pub use ;
pub use Model;
pub use Runtime;
pub use Tensor;
// Re-export commonly used external types
pub use ndarray;
/// Version of the RunNX crate
pub const VERSION: &str = env!;