#[script]Expand description
Apply #[script] to a function fn(args...) -> Tensor<T> to compile
it into a ferrotorch_jit::TracedModule<T>-returning function.
The example below is marked ignore because this is a proc-macro
crate: it cannot itself import ferrotorch_jit::TracedModule or
ferrotorch_core::Tensor at doctest-compile time (proc-macro crates
can only export proc-macro items and pull procedural-macro deps; they
cannot depend on consumer crates). The example is exercised
end-to-end by the integration tests in
ferrotorch-jit-script/tests/script_macro.rs.
use ferrotorch_jit_script::script;
use ferrotorch_core::Tensor;
use ferrotorch_core::grad_fns::arithmetic::{mul, add};
use ferrotorch_core::grad_fns::reduction::sum;
#[script]
fn weighted_sum(a: Tensor<f32>, w: Tensor<f32>) -> Tensor<f32> {
let prod = mul(&a, &w)?;
sum(&prod)
}
// `weighted_sum(...)` now returns `FerrotorchResult<TracedModule<f32>>`
// built by tracing the body once with the supplied tensors.§Errors
Emits a compile_error! (via syn::Error) if the annotated function’s
return type isn’t one of the recognized shapes:
Tensor<T>FerrotorchResult<Tensor<T>>Result<Tensor<T>, _>
Previously, an unrecognized return type silently fell back to
TracedModule<f32>, producing a wrong-dtype wrapper for e.g.
Tensor<f64> callers. The macro now refuses the input instead.