pub trait ModuleExt: Module {
Show 20 methods
// Provided methods
fn and_then<F>(&self, input: &Tensor, f: F) -> Result<Tensor>
where F: FnOnce(Tensor) -> Result<Tensor> { ... }
fn map<F>(&self, input: &Tensor, f: F) -> Result<Tensor>
where F: FnOnce(Tensor) -> Tensor { ... }
fn with_input<F>(&self, input: &Tensor, f: F) -> Result<Tensor>
where F: FnOnce(&Tensor) -> Result<Tensor> { ... }
fn summary(&self) -> String { ... }
fn print_summary(&self) { ... }
fn parameter_stats(&self) -> ParameterStats { ... }
fn has_finite_parameters(&self) -> bool { ... }
fn parameter_names(&self) -> Vec<String> { ... }
fn get_parameter(&self, name: &str) -> Option<Parameter> { ... }
fn freeze_matching(&mut self, pattern: &str) -> usize { ... }
fn unfreeze_matching(&mut self, pattern: &str) -> usize { ... }
fn frozen_parameters(&self) -> Vec<String> { ... }
fn trainable_parameters(&self) -> Vec<String> { ... }
fn clone_state_dict(&self) -> HashMap<String, Tensor> { ... }
fn apply_to_parameters<F>(&self, f: F)
where F: FnMut(&str, &Parameter) { ... }
fn parameters_by_type(&self) -> HashMap<String, usize> { ... }
fn validate(&self) -> Result<ValidationReport> { ... }
fn device(&self) -> Option<DeviceType> { ... }
fn is_cpu(&self) -> bool { ... }
fn is_cuda(&self) -> bool { ... }
}Expand description
Extension trait providing additional ergonomic methods for Module
This trait is automatically implemented for all types that implement Module, providing additional convenience methods without requiring changes to existing code.
§Design Philosophy
This extension follows Rust’s extension trait pattern to:
- Add functionality without breaking backward compatibility
- Keep the core Module trait focused on essential methods
- Provide advanced features for users who need them
- Enable fluent/builder-style APIs
Provided Methods§
Sourcefn with_input<F>(&self, input: &Tensor, f: F) -> Result<Tensor>
fn with_input<F>(&self, input: &Tensor, f: F) -> Result<Tensor>
Sourcefn print_summary(&self)
fn print_summary(&self)
Print module summary to stdout
Sourcefn parameter_stats(&self) -> ParameterStats
fn parameter_stats(&self) -> ParameterStats
Sourcefn has_finite_parameters(&self) -> bool
fn has_finite_parameters(&self) -> bool
Sourcefn parameter_names(&self) -> Vec<String>
fn parameter_names(&self) -> Vec<String>
Sourcefn get_parameter(&self, name: &str) -> Option<Parameter>
fn get_parameter(&self, name: &str) -> Option<Parameter>
Sourcefn freeze_matching(&mut self, pattern: &str) -> usize
fn freeze_matching(&mut self, pattern: &str) -> usize
Freeze specific parameters by name pattern
§Arguments
pattern- String pattern to match parameter names
§Returns
usize- Number of parameters frozen
§Note
This method currently returns a count but doesn’t actually freeze parameters because Parameter’s requires_grad is immutable. This is a placeholder for future implementation when mutable parameter access is available.
Sourcefn unfreeze_matching(&mut self, pattern: &str) -> usize
fn unfreeze_matching(&mut self, pattern: &str) -> usize
Unfreeze specific parameters by name pattern
§Arguments
pattern- String pattern to match parameter names
§Returns
usize- Number of parameters unfrozen
§Note
This method currently returns a count but doesn’t actually unfreeze parameters because Parameter’s requires_grad is immutable. This is a placeholder for future implementation when mutable parameter access is available.
Sourcefn frozen_parameters(&self) -> Vec<String>
fn frozen_parameters(&self) -> Vec<String>
Sourcefn trainable_parameters(&self) -> Vec<String>
fn trainable_parameters(&self) -> Vec<String>
Sourcefn clone_state_dict(&self) -> HashMap<String, Tensor>
fn clone_state_dict(&self) -> HashMap<String, Tensor>
Clone module parameters into a new state dict
§Returns
HashMap<String, Tensor>- Cloned state dictionary
Sourcefn apply_to_parameters<F>(&self, f: F)
fn apply_to_parameters<F>(&self, f: F)
Sourcefn parameters_by_type(&self) -> HashMap<String, usize>
fn parameters_by_type(&self) -> HashMap<String, usize>
Sourcefn validate(&self) -> Result<ValidationReport>
fn validate(&self) -> Result<ValidationReport>
Validate module configuration
Performs comprehensive validation of module state.
§Returns
Result<ValidationReport>- Validation results
Sourcefn device(&self) -> Option<DeviceType>
fn device(&self) -> Option<DeviceType>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.