Initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
//! Activation operator code generation.
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
use crate::ir::Node;
|
||||
use crate::error::Result;
|
||||
use super::sanitize_name;
|
||||
|
||||
/// Generate softmax operation.
|
||||
pub fn generate_softmax(node: &Node) -> Result<TokenStream> {
|
||||
let input = &node.inputs[0];
|
||||
let output = &node.outputs[0];
|
||||
|
||||
let in_ident = quote::format_ident!("{}", sanitize_name(input));
|
||||
let out_ident = quote::format_ident!("{}", sanitize_name(output));
|
||||
|
||||
// Get axis attribute (default -1)
|
||||
let axis = node.get_int("axis").unwrap_or(-1);
|
||||
|
||||
Ok(quote! {
|
||||
let #out_ident = #in_ident.softmax(#axis)?;
|
||||
})
|
||||
}
|
||||
|
||||
/// Generate leaky ReLU operation.
|
||||
pub fn generate_leaky_relu(node: &Node) -> Result<TokenStream> {
|
||||
let input = &node.inputs[0];
|
||||
let output = &node.outputs[0];
|
||||
|
||||
let in_ident = quote::format_ident!("{}", sanitize_name(input));
|
||||
let out_ident = quote::format_ident!("{}", sanitize_name(output));
|
||||
|
||||
// Get alpha attribute (default 0.01)
|
||||
let alpha = node.get_float("alpha").unwrap_or(0.01);
|
||||
|
||||
Ok(quote! {
|
||||
let #out_ident = #in_ident.leaky_relu(#alpha)?;
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user