Skip to main content

onnx_ir/node/
softplus.rs

1//! # Softplus Operation
2//!
3//! Element-wise softplus activation operation: y = ln(exp(x) + 1).
4//!
5//! **ONNX Spec**: <https://onnx.ai/onnx/operators/onnx__Softplus.html>
6//!
7//! ## Type Constraints
8//!
9//! T: Float tensor types
10//!
11//! ## Opset Versions
12//! - **Opset 1**: Initial support
13
14use crate::ir::{Argument, Node, RawNode};
15use crate::processor::{
16    InputSpec, NodeProcessor, NodeSpec, OutputPreferences, OutputSpec, ProcessError, same_as_input,
17    validate_opset,
18};
19use onnx_ir_derive::NodeBuilder;
20
21/// Node representation for Softplus operation
22#[derive(Debug, Clone, NodeBuilder)]
23pub struct SoftplusNode {
24    pub name: String,
25    pub inputs: Vec<Argument>,
26    pub outputs: Vec<Argument>,
27}
28
29/// Node processor for softplus operation
30pub(crate) struct SoftplusProcessor;
31
32impl NodeProcessor for SoftplusProcessor {
33    type Config = ();
34
35    fn spec(&self) -> NodeSpec {
36        NodeSpec {
37            min_opset: 1,
38            max_opset: None,
39            inputs: InputSpec::Exact(1),
40            outputs: OutputSpec::Exact(1),
41        }
42    }
43
44    fn infer_types(
45        &self,
46        node: &mut RawNode,
47        opset: usize,
48        _output_preferences: &OutputPreferences,
49    ) -> Result<(), ProcessError> {
50        validate_opset(opset, 1)?;
51        same_as_input(node);
52        Ok(())
53    }
54
55    fn build_node(&self, builder: RawNode, _opset: usize) -> Result<Node, ProcessError> {
56        Ok(Node::Softplus(SoftplusNode {
57            name: builder.name,
58            inputs: builder.inputs,
59            outputs: builder.outputs,
60        }))
61    }
62}