Module implementation for options. (#1728)

This commit is contained in:
Laurent Mazare
2024-02-18 14:12:55 +01:00
committed by GitHub
parent 678d44a7f6
commit 6284ad784c

View File

@ -129,6 +129,15 @@ impl<T: Fn(&Tensor) -> Result<Tensor>> Module for T {
} }
} }
impl<M: Module> Module for Option<&M> {
fn forward(&self, xs: &Tensor) -> Result<Tensor> {
match self {
None => Ok(xs.clone()),
Some(m) => m.forward(xs),
}
}
}
// A trait defining a module with forward method using a single tensor argument and a flag to // A trait defining a module with forward method using a single tensor argument and a flag to
// separate the training and evaluation behaviors. // separate the training and evaluation behaviors.
pub trait ModuleT { pub trait ModuleT {