concision_macros/
lib.rs

1/*
2    appellation: concision-macros <library>
3    authors: @FL03
4*/
5//! # concision-macros
6//!
7//! this crate defines various procedural macros for the `concision` crate working to
8//! streamline the process of creating and developing custom neural networks.
9//!
10
11pub(crate) mod ast;
12pub(crate) mod attr;
13pub(crate) mod impls;
14pub(crate) mod kw;
15
16use self::ast::ModelAst;
17use proc_macro::TokenStream;
18use syn::parse_macro_input;
19
20#[proc_macro]
21/// [`model_config!`] is a procedural macro used to define the configuration for a model in the
22/// `concision` framework. It allows users to specify various parameters and settings for the model
23/// in a concise and structured manner, declaring a name for their instance
24pub fn model_config(input: TokenStream) -> TokenStream {
25    let data = parse_macro_input! { input as ast::ConfigAst };
26    // use the handler to process the input data
27    let res = impls::impl_model_config(data);
28    // convert the tokens into a TokenStream
29    res.into()
30}
31
32#[proc_macro]
33/// the [`model!`]procedural macro is used to streamline the creation of custom models using the
34/// `concision` framework
35pub fn model(input: TokenStream) -> TokenStream {
36    let data = parse_macro_input! { input as ModelAst };
37    // use the handler to process the input data
38    let res = impls::impl_model(data);
39    // convert the tokens into a TokenStream
40    res.into()
41}
42
43#[proc_macro]
44/// [`nn!`] is a procedural macro designed to streamline the process of creating new neural
45/// networks;
46///
47/// ```ignore
48/// nn! {
49///     MyNeuralNetwork {
50///         layout: { input: 128, output: 10 },
51///         params: {
52///             learning_rate: 0.01,
53///             epochs: 100,
54///             ...
55///        },
56///         layers: [Linear, ReLU, ..., Linear],
57///     }     
58/// }
59/// ```
60pub fn nn(input: TokenStream) -> TokenStream {
61    let data = parse_macro_input!(input as ModelAst);
62    // use the handler to process the input data
63    let res = impls::impl_model(data);
64    // convert the tokens into a TokenStream
65    res.into()
66}