Skip to main content

onnx_ir/node/
unsupported.rs

1//! Placeholder node types for unsupported/unimplemented ONNX operations
2//!
3//! These operations are part of the ONNX spec but don't have full implementations yet.
4//! They are defined here as placeholders to maintain type safety and allow the graph
5//! to be parsed even when it contains unsupported operations.
6
7use crate::ir::{Argument, Node, RawNode};
8use crate::processor::{
9    InputSpec, NodeProcessor, NodeSpec, OutputPreferences, OutputSpec, ProcessError,
10};
11
12/// Generic placeholder for unsupported operations
13macro_rules! define_placeholder_node {
14    ($($name:ident),* $(,)?) => {
15        $(
16            #[derive(Debug, Clone)]
17            pub struct $name {
18                pub name: String,
19                pub inputs: Vec<Argument>,
20                pub outputs: Vec<Argument>,
21            }
22
23            impl ::core::fmt::Display for $name {
24                fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
25                    let type_name = stringify!($name);
26                    let op_name = type_name.strip_suffix("Node").unwrap_or(type_name);
27                    write!(f, "{} {:?}\n", op_name, self.name)?;
28                    write!(f, "  Inputs:\n")?;
29                    for arg in &self.inputs {
30                        write!(f, "    {arg}\n")?;
31                    }
32                    write!(f, "  Outputs:\n")?;
33                    for arg in &self.outputs {
34                        write!(f, "    {arg}\n")?;
35                    }
36                    Ok(())
37                }
38            }
39        )*
40    };
41}
42
43define_placeholder_node! {
44    AffineGridNode,
45    AveragePoolNode,
46    CenterCropPadNode,
47    CompressNode,
48    ConcatFromSequenceNode,
49    ConvNode,
50    ConvIntegerNode,
51    ConvTransposeNode,
52
53    DequantizeLinearNode,
54    DynamicQuantizeLinearNode,
55    HardmaxNode,
56    ImNode,
57    ImageDecoderNode,
58    LpPoolNode,
59    MaxPoolNode,
60    MaxRoiPoolNode,
61    MaxUnpoolNode,
62    MultinomialNode,
63    NegativeLogLikelihoodLossNode,
64    OptionalNode,
65    OptionalGetElementNode,
66    OptionalHasElementNode,
67    QLinearConvNode,
68    QuantizeLinearNode,
69    RMSNormalizationNode,
70    RegexFullMatchNode,
71    ReverseSequenceNode,
72    RoiAlignNode,
73    RotaryEmbeddingNode,
74    SequenceAtNode,
75    SequenceConstructNode,
76    SequenceEmptyNode,
77    SequenceEraseNode,
78    SequenceInsertNode,
79    SequenceLengthNode,
80    SequenceMapNode,
81    ShrinkNode,
82    SoftmaxCrossEntropyLossNode,
83    SplitToSequenceNode,
84    StringConcatNode,
85    StringNormalizerNode,
86    StringSplitNode,
87    SwishNode,
88    TensorScatterNode,
89    TfIdfVectorizerNode,
90    UniqueNode,
91}
92
93/// Generic processor for unsupported operations
94///
95/// This processor creates placeholder nodes for operations that don't have full implementations.
96/// It performs basic input/output validation but doesn't extract any configuration.
97pub(crate) struct UnsupportedProcessor;
98
99impl NodeProcessor for UnsupportedProcessor {
100    type Config = ();
101
102    fn spec(&self) -> NodeSpec {
103        NodeSpec {
104            min_opset: 1,
105            max_opset: None,
106            // Accept any number of inputs/outputs
107            inputs: InputSpec::AtLeast(0),
108            outputs: OutputSpec::Range(0, usize::MAX),
109        }
110    }
111
112    fn infer_types(
113        &self,
114        _node: &mut RawNode,
115        _opset: usize,
116        _output_preferences: &OutputPreferences,
117    ) -> Result<(), ProcessError> {
118        // Unsupported nodes keep whatever types were provided in the ONNX file.
119        Ok(())
120    }
121
122    fn extract_config(&self, _node: &RawNode, _opset: usize) -> Result<Self::Config, ProcessError> {
123        Ok(())
124    }
125
126    fn build_node(&self, builder: RawNode, _opset: usize) -> Result<Node, ProcessError> {
127        use crate::ir::NodeType;
128
129        Ok(match builder.node_type {
130            NodeType::Unique => Node::Unique(UniqueNode {
131                name: builder.name,
132                inputs: builder.inputs,
133                outputs: builder.outputs,
134            }),
135            other => {
136                return Err(ProcessError::Custom(format!(
137                    "Unsupported node type: {other:?}"
138                )));
139            }
140        })
141    }
142}