pub struct ModuleList { /* private fields */ }Expand description
List of modules with index-based access.
Unlike Sequential, ModuleList doesn’t define a forward pass.
It’s useful for holding submodules that need custom control flow.
§Example
ⓘ
use aprender::nn::{ModuleList, Linear, Module};
let layers = ModuleList::new()
.add(Linear::new(10, 10))
.add(Linear::new(10, 10))
.add(Linear::new(10, 10));
// Custom forward with residual connections
fn forward(layers: &ModuleList, x: &Tensor) -> Tensor {
let mut out = x.clone();
for i in 0..layers.len() {
let residual = out.clone();
out = layers.get(i).expect("layer index in bounds").forward(&out);
out = out.add(&residual); // residual connection
}
out
}Implementations§
Source§impl ModuleList
impl ModuleList
Source§impl ModuleList
impl ModuleList
Trait Implementations§
Source§impl Debug for ModuleList
impl Debug for ModuleList
Auto Trait Implementations§
impl Freeze for ModuleList
impl !RefUnwindSafe for ModuleList
impl Send for ModuleList
impl Sync for ModuleList
impl Unpin for ModuleList
impl UnsafeUnpin for ModuleList
impl !UnwindSafe for ModuleList
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more