### Initialize Muon Optimizer with Default Settings Source: https://burn.dev/docs/burn/optim/struct.MuonConfig.html Demonstrates how to initialize the Muon optimizer using its default configuration. This is the most basic way to get started with the optimizer. ```rust use burn_optim::{MuonConfig, AdjustLrFn}; // Using default (Original) method let optimizer = MuonConfig::new().init(); ``` -------------------------------- ### Example Searches Source: https://burn.dev/docs/burn/nn/struct.LocalResponseNorm.html?search= These are example searches that demonstrate how to query LocalResponseNorm. ```APIDOC ## Example Searches ### Description Demonstrates various ways to search within the LocalResponseNorm functionality. ### Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### BinFileRecorder Search Examples Source: https://burn.dev/docs/burn/record/struct.BinFileRecorder.html?search= Examples demonstrating how to search within BinFileRecorder. ```APIDOC ## BinFileRecorder Search This section provides examples of how to search within the BinFileRecorder. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### CPU Temperature Search Examples Source: https://burn.dev/docs/burn/train/metric/struct.CpuTemperature.html?search= This section provides examples of how to search for CPU temperature metrics. These examples demonstrate common search patterns and can be adapted for specific needs. ```APIDOC ## CPU Temperature Search ### Description Provides examples for searching CPU temperature metrics. ### Examples #### Basic Search ``` std::vec ``` #### Type Conversion Search ``` u32 -> bool ``` #### Generic Type Search ``` Option, (T -> U) -> Option ``` ``` -------------------------------- ### ActivationRecordItem Search Examples Source: https://burn.dev/docs/burn/nn/activation/enum.ActivationRecordItem.html?search= Provides examples of how to search for ActivationRecordItem. These examples demonstrate common search patterns and type conversions. ```APIDOC ## Search Examples This section provides examples of how to search for `ActivationRecordItem`. ### Example 1: Searching for a specific type ```rust // Example search for std::vec // search("std::vec") ``` ### Example 2: Searching for type conversions ```rust // Example search for u32 to bool conversion // search("u32 -> bool") ``` ### Example 3: Searching for generic type conversions ```rust // Example search for Option, (T -> U) -> Option // search("Option, (T -> U) -> Option") ``` ``` -------------------------------- ### CpuUse Search Examples Source: https://burn.dev/docs/burn/train/metric/struct.CpuUse.html?search= Examples of how to search for CPU usage metrics. ```APIDOC ## CpuUse Search ### Description Provides methods to search and filter CPU usage metrics. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### Slice Search Examples Source: https://burn.dev/docs/burn/tensor/struct.Slice.html?search= Examples demonstrating how to use slice search. ```APIDOC ## Slice Search ### Description Provides examples for slice searching. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### AsyncCheckpointer Search Examples Source: https://burn.dev/docs/burn/train/checkpoint/struct.AsyncCheckpointer.html?search= Examples demonstrating how to search for different types and conversions within the AsyncCheckpointer system. ```APIDOC ## AsyncCheckpointer Search This section provides examples of how to use the search functionality for AsyncCheckpointer. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### FullPrecisionSettings Search Examples Source: https://burn.dev/docs/burn/record/struct.FullPrecisionSettings.html?search= Examples of how to search for FullPrecisionSettings. ```APIDOC ## Search Examples ### Example 1: Searching for a specific type ```rust // Example: Searching for std::vec search("std::vec"); ``` ### Example 2: Searching for a type conversion ```rust // Example: Searching for u32 -> bool conversion search("u32 -> bool"); ``` ### Example 3: Searching for a generic type conversion ```rust // Example: Searching for Option, (T -> U) -> Option search("Option, (T -> U) -> Option"); ``` ``` -------------------------------- ### EventStoreClient Search Examples Source: https://burn.dev/docs/burn/train/metric/store/struct.EventStoreClient.html?search= Provides examples of how to construct search queries for the EventStoreClient. ```APIDOC ## EventStoreClient Search ### Description This section provides examples of search queries that can be used with the EventStoreClient. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### Slice Construction Examples Source: https://burn.dev/docs/burn/tensor/struct.Slice.html Provides examples of how to construct Slice objects directly. ```APIDOC ## Examples While you typically use the `s!` macro, you can also construct slices directly: ```rust use burn_tensor::Slice; // Equivalent to s![2..8] let slice1 = Slice::new(2, Some(8), 1); // Equivalent to s![0..10;2] let slice2 = Slice::new(0, Some(10), 2); // Equivalent to s![..;-1] (reverse) let slice3 = Slice::new(0, None, -1); ``` ``` -------------------------------- ### Search Examples Source: https://burn.dev/docs/burn/record/struct.NamedMpkFileRecorder.html?search= Provides examples of how to formulate search queries for NamedMpkFileRecorder. These examples demonstrate searching for specific types, type conversions, and generic type manipulations. ```APIDOC ## Search Examples ### Description This section provides examples of search queries that can be used with NamedMpkFileRecorder. These examples illustrate common search patterns and type manipulations. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### AgentEnvAsyncLoop Search Examples Source: https://burn.dev/docs/burn/train/struct.AgentEnvAsyncLoop.html?search= Examples demonstrating how to use the search functionality for AgentEnvAsyncLoop. ```APIDOC ## Search Examples ### Example 1: Searching for a standard type ``` std::vec ``` ### Example 2: Searching for a type conversion (integer to boolean) ``` u32 -> bool ``` ### Example 3: Searching for a generic type conversion with Option ``` Option, (T -> U) -> Option ``` ``` -------------------------------- ### AsyncProcessorEvaluation Search Examples Source: https://burn.dev/docs/burn/train/struct.AsyncProcessorEvaluation.html?search= Provides examples of search queries that can be performed. ```APIDOC ## Search Examples ### Example 1 ``` std::vec ``` ### Example 2 ``` u32 -> bool ``` ### Example 3 ``` Option, (T -> U) -> Option ``` ``` -------------------------------- ### Grid Options Search Examples Source: https://burn.dev/docs/burn/tensor/grid/struct.GridOptions.html?search= Examples demonstrating how to search for different types and conversions within the Grid Options. ```APIDOC ## Grid Options Search This section provides examples of search queries for the Grid Options module. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### Example Search Queries Source: https://burn.dev/docs/burn/grad_clipping/enum.GradientClippingConfig.html?search=std%3A%3Avec Demonstrates example search queries for finding Rust types and functionalities. These are useful for navigating documentation or codebases. ```text Example searches: * std::vec * u32 -> bool * Option, (T -> U) -> Option ``` -------------------------------- ### Metric Definition Search Examples Source: https://burn.dev/docs/burn/train/metric/struct.MetricDefinition.html?search= Examples of how to search for metric definitions. These examples demonstrate different query patterns. ```APIDOC ## Search Examples ### Example 1: Searching for a specific type ``` std::vec ``` ### Example 2: Searching for a type conversion ``` u32 -> bool ``` ### Example 3: Searching for a generic function signature ``` Option, (T -> U) -> Option ``` ``` -------------------------------- ### BinBytesRecorder Search Examples Source: https://burn.dev/docs/burn/record/struct.BinBytesRecorder.html?search= Provides examples of search queries that can be performed on BinBytesRecorder. ```APIDOC ## Search Examples ### Example Queries - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### EpochSummary Search Examples Source: https://burn.dev/docs/burn/train/metric/store/struct.EpochSummary.html?search= Examples of how to search for EpochSummary. ```APIDOC ## EpochSummary Search ### Description Provides examples of how to search for EpochSummary. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### RLTraining::new Source: https://burn.dev/docs/burn/train/struct.RLTraining.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new RLTraining instance with a specified directory for checkpoints and an environment initializer. ```APIDOC ## RLTraining::new ### Description Creates a new runner for reinforcement learning. ### Method `new(directory: impl AsRef, env_initializer: EI)` ### Parameters #### Arguments * `directory` - The directory to save the checkpoints. * `env_init` - Specifies how to initialize the environment. ``` -------------------------------- ### Split Off Slice Starting with Third Element Source: https://burn.dev/docs/burn/prelude/struct.Shape.html Use `split_off` to remove and return a subslice. This example shows splitting off the elements starting from the third element. ```rust let mut slice: &[_] = &['a', 'b', 'c', 'd']; let mut tail = slice.split_off(2..).unwrap(); assert_eq!(slice, &['a', 'b']); assert_eq!(tail, &['c', 'd']); ``` -------------------------------- ### LpLossConfig Examples Source: https://burn.dev/docs/burn/nn/loss/struct.LpLossConfig.html Demonstrates how to create L1, L2, and custom Lp loss configurations using LpLossConfig. ```rust use burn_nn::loss::{LpLossConfig, Reduction}; // Create L1 loss (MAE when using mean reduction) let l1_loss = LpLossConfig::l1(); // Create L2 loss (MSE when using mean reduction) let l2_loss = LpLossConfig::l2(); // Create custom Lp loss with p=3 let l3_loss = LpLossConfig::new(3.0).init(); ``` -------------------------------- ### Common Search Examples Source: https://burn.dev/docs/burn/nn/modules/norm/struct.GroupNormConfig.html?search= Illustrates typical search queries for various data types and generic structures. These examples can guide users on how to formulate their own searches. ```rust * std::vec ``` ```rust * u32 -> bool ``` ```rust * Option, (T -> U) -> Option ``` -------------------------------- ### LpLossConfig Initialization Source: https://burn.dev/docs/burn/nn/loss/struct.LpLossConfig.html?search= Demonstrates how to create LpLossConfig instances for L1, L2, and custom Lp losses. ```APIDOC ## LpLossConfig burn::nn::loss Configuration for the Lp Loss module. ### §Example ``` use burn_nn::loss::{LpLossConfig, Reduction}; // Create L1 loss (MAE when using mean reduction) let l1_loss = LpLossConfig::l1(); // Create L2 loss (MSE when using mean reduction) let l2_loss = LpLossConfig::l2(); // Create custom Lp loss with p=3 let l3_loss = LpLossConfig::new(3.0).init(); ``` ## Fields §`p: f64` The exponent `p` determining the type of error measurement. Common values: * `p = 1.0`: L1 loss (MAE with mean reduction) - robust to outliers * `p = 2.0`: L2 loss (MSE with mean reduction) - standard choice, differentiable everywhere * `p > 2.0`: Increasingly sensitive to large errors (outliers) * `0 < p < 1`: More robust to outliers than L1 (quasi-norm) ## Implementations ### impl LpLossConfig #### pub fn new(p: f64) -> LpLossConfig Create a new instance of the config. ##### §Arguments ###### §Required Arguments ###### §`p` The exponent `p` determining the type of error measurement. Common values: * `p = 1.0`: L1 loss (MAE with mean reduction) - robust to outliers * `p = 2.0`: L2 loss (MSE with mean reduction) - standard choice, differentiable everywhere * `p > 2.0`: Increasingly sensitive to large errors (outliers) * `0 < p < 1`: More robust to outliers than L1 (quasi-norm) #### pub fn init(&self) -> LpLoss Initializes a Lp Loss module. ##### §Panics Panics if `p <= 0`. #### pub fn l1() -> LpLoss Creates L1 loss (p=1). When used with `Reduction::Mean`, this computes Mean Absolute Error (MAE). When used with `Reduction::Sum`, this computes Sum of Absolute Errors (SAE). #### pub fn l2() -> LpLoss Creates L2 loss (p=2). When used with `Reduction::Mean`, this computes Mean Squared Error (MSE). When used with `Reduction::Sum`, this computes Sum of Squared Errors (SSE). ``` -------------------------------- ### Split Off Mutable Slice Starting with Third Element Source: https://burn.dev/docs/burn/prelude/struct.Shape.html Use `split_off_mut` to remove and return a mutable subslice. This example shows splitting off the elements starting from the third element. ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c', 'd']; let mut tail = slice.split_off_mut(2..).unwrap(); assert_eq!(slice, &mut ['a', 'b']); assert_eq!(tail, &mut ['c', 'd']); ``` -------------------------------- ### LearnerSummaryConfig Search Examples Source: https://burn.dev/docs/burn/train/struct.LearnerSummaryConfig.html?search= Examples of how to perform searches on LearnerSummaryConfig. ```APIDOC ## LearnerSummaryConfig Search ### Description Provides examples for searching within LearnerSummaryConfig. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### Example Initializer Searches Source: https://burn.dev/docs/burn/module/enum.Initializer.html?search= Demonstrates various ways to search for initializers, including searching by type, type transformations, and generic types. ```APIDOC ## Example Searches ### Description Provides examples of how to search for initializers. ### Code Examples #### Search by Type ```apidoc std::vec ``` #### Search by Type Transformation ```apidoc u32 -> bool ``` #### Search with Generic Types and Transformations ```apidoc Option, (T -> U) -> Option ``` ``` -------------------------------- ### ActivationConfig_search Source: https://burn.dev/docs/burn/nn/activation/enum.ActivationConfig.html?search= This section details how to search for activation configurations. It includes example searches to guide users. ```APIDOC ## ActivationConfig_search ### Description Provides functionality to search for activation configurations. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### PrecisionMetric Search Examples Source: https://burn.dev/docs/burn/train/metric/struct.PrecisionMetric.html?search= Examples of how to search for PrecisionMetric related items. ```APIDOC ## PrecisionMetric Search ### Description Provides examples for searching PrecisionMetric related functionalities. ### Example Searches * `std::vec` * `u32 -> bool` * `Option, (T -> U) -> Option` ``` -------------------------------- ### install Source: https://burn.dev/docs/burn/train/trait.ApplicationLoggerInstaller.html Installs the application logger. Returns a Result indicating success or failure with an error message. ```APIDOC ## fn install(&self) -> Result<(), String> ### Description Install the application logger. ### Returns - `Result<(), String>`: Ok(()) on success, or an Err(String) with an error message on failure. ``` -------------------------------- ### Get Window by Index Source: https://burn.dev/docs/burn/data/dataset/transform/struct.WindowsDataset.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves a specific window of data as a vector. The index corresponds to the starting position of the window in the dataset. ```rust fn get(&self, index: usize) -> Option> ``` -------------------------------- ### EluConfig Initialization and Configuration Source: https://burn.dev/docs/burn/nn/activation/struct.EluConfig.html?search= Demonstrates how to create and configure an EluConfig object. ```APIDOC ## Struct EluConfig Configuration to create an Elu layer using the init function. ### Fields * `alpha`: `f64` - The alpha value. Default is 1.0 ### Methods * `pub fn new() -> EluConfig` Create a new instance of the config with default alpha value. * `pub fn with_alpha(self, alpha: f64) -> EluConfig` Sets the value for the `alpha` field. * `pub fn init(&self) -> Elu` Initialize a new Elu Layer using the current configuration. ``` -------------------------------- ### LocalResponseNorm Search Examples Source: https://burn.dev/docs/burn/nn/modules/struct.LocalResponseNorm.html?search= Provides examples of how to perform searches within the LocalResponseNorm module. ```APIDOC ## Search Examples ### Description Examples of common search queries. ### Example Searches * `std::vec` * `u32 -> bool` * `Option, (T -> U) -> Option` ``` -------------------------------- ### InstanceNormRecordItem Search Examples Source: https://burn.dev/docs/burn/nn/struct.InstanceNormRecordItem.html?search= Examples of how to search for InstanceNormRecordItem, including common patterns and types. ```APIDOC ## InstanceNormRecordItem Search ### Description Provides examples of search queries for InstanceNormRecordItem. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### CTCLoss Initialization and Usage Example Source: https://burn.dev/docs/burn/nn/loss/struct.CTCLoss.html?search= Demonstrates how to initialize CTCLoss with default and custom configurations, and how to compute the loss using log-probabilities, targets, and lengths. ```rust use burn::tensor::{Tensor, Int}; use burn::tensor::activation::log_softmax; use burn::nn::loss::{CTCLossConfig, CTCLoss}; let device = Default::default(); // Initialize CTC Loss with default configuration let ctc_loss = CTCLossConfig::new().init(); // Initialize CTC Loss with custom configuration let ctc_loss = CTCLossConfig::new() .with_blank(1) .with_zero_infinity(true) .init(); // Prepare inputs (Logits shape: [Time, Batch, Class]) // In your actual code, the logits would be the output of your model let logits = Tensor::::ones([10, 2, 5], &device); let log_probs = log_softmax(logits, 2); // Targets shape: [Batch, Max_Target_Len] // Note: Targets should not contain the blank index (1). let targets = Tensor::::from_data([[0, 2], [3, 4]], &device); // Lengths shape: [Batch] let input_lengths = Tensor::::from_data([10, 8], &device); let target_lengths = Tensor::::from_data([2, 2], &device); // Compute loss let loss = ctc_loss.forward(log_probs, targets, input_lengths, target_lengths); ``` -------------------------------- ### SwiGluConfig::init Method Source: https://burn.dev/docs/burn/nn/activation/struct.SwiGluConfig.html?search= Initializes a SwiGlu activation layer using the current configuration and a given device. ```rust pub fn init(&self, device: &::Device) -> SwiGlu where B: Backend ``` -------------------------------- ### Reverse split subslices Source: https://burn.dev/docs/burn/prelude/struct.Shape.html Use `rsplit` to get an iterator over subslices separated by elements matching a predicate, starting from the end of the slice. The matched element is excluded. ```rust let slice = [11, 22, 33, 0, 44, 55]; let mut iter = slice.rsplit(|num| *num == 0); assert_eq!(iter.next().unwrap(), &[44, 55]); assert_eq!(iter.next().unwrap(), &[11, 22, 33]); assert_eq!(iter.next(), None); ``` ```rust let v = &[0, 1, 1, 2, 3, 5, 8]; let mut it = v.rsplit(|n| *n % 2 == 0); assert_eq!(it.next().unwrap(), &[]); assert_eq!(it.next().unwrap(), &[3, 5]); assert_eq!(it.next().unwrap(), &[1, 1]); assert_eq!(it.next().unwrap(), &[]); assert_eq!(it.next(), None); ``` -------------------------------- ### Dataset Windowing Example Source: https://burn.dev/docs/burn/data/dataset/audio/struct.SpeechCommandsDataset.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to create sliding windows over a dataset. Panics if the window size is 0. ```rust use crate::burn_dataset:: transform::{Windows, WindowsDataset}, Dataset, InMemDataset, }; let items = [1, 2, 3, 4].to_vec(); let dataset = InMemDataset::new(items.clone()); for window in dataset.windows(2) { // do sth with window } ``` -------------------------------- ### Extending Vec from a Range (Start) Source: https://burn.dev/docs/burn/module/type.Devices.html Given a range `src`, clones a slice of elements in that range and appends it to the end of the Vec. This example extends from the beginning up to (but not including) the second element. ```rust let mut numbers = vec![0, 1, 2, 3, 4]; numbers.extend_from_within(..2); assert_eq!(numbers, [0, 1, 2, 3, 4, 0, 1]); ``` -------------------------------- ### InstanceNormConfig::init Source: https://burn.dev/docs/burn/nn/modules/norm/struct.InstanceNormConfig.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes a new InstanceNorm module on the specified device. ```APIDOC ## InstanceNormConfig::init ### Description Initialize a new instance norm module. ### Signature ```rust pub fn init(&self, device: &::Device) -> InstanceNorm where B: Backend, ``` ### Arguments * **device** (&`::Device`) - The device on which to initialize the module. ``` -------------------------------- ### Reverse split mutable subslices Source: https://burn.dev/docs/burn/prelude/struct.Shape.html Use `rsplit_mut` to get an iterator over mutable subslices separated by elements matching a predicate, starting from the end of the slice. The matched element is excluded. ```rust let mut v = [100, 400, 300, 200, 600, 500]; let mut count = 0; for group in v.rsplit_mut(|num| *num % 3 == 0) { count += 1; group[0] = count; } assert_eq!(v, [3, 400, 300, 2, 600, 1]); ``` -------------------------------- ### InstanceNormConfig::init Source: https://burn.dev/docs/burn/nn/modules/norm/struct.InstanceNormConfig.html?search=u32+-%3E+bool Initializes a new InstanceNorm module using the provided configuration and device. ```APIDOC ## InstanceNormConfig::init ### Description Initialize a new instance norm module. ### Signature ```rust pub fn init(&self, device: &::Device) -> InstanceNorm ``` ### Arguments * `device` (&::Device) - The device on which to initialize the InstanceNorm module. ``` -------------------------------- ### Getting Metadata with `and_then` Source: https://burn.dev/docs/burn/data/dataset/type.Result.html?search=u32+-%3E+bool Demonstrates using `and_then` to chain metadata retrieval operations on file paths. This example shows how to handle potential errors during file system access. ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### Create and Use WindowsDataset Source: https://burn.dev/docs/burn/data/dataset/transform/struct.SamplerDataset.html?search= Demonstrates how to create a dataset and then use the `windows` method to create sliding windows of items. Panics if the window size is 0. ```rust use crate::burn_dataset:: transform::{Windows, WindowsDataset}, Dataset, InMemDataset, }; let items = [1, 2, 3, 4].to_vec(); let dataset = InMemDataset::new(items.clone()); let windows_dataset = WindowsDataset::new(dataset, 2); let mut iter = windows_dataset.iter(); assert_eq!(iter.next().unwrap(), vec![1, 2]); assert_eq!(iter.next().unwrap(), vec![2, 3]); assert_eq!(iter.next().unwrap(), vec![3, 4]); assert_eq!(iter.next(), None); ``` -------------------------------- ### Mutably Iterate Over Chunks From the End Source: https://burn.dev/docs/burn/prelude/struct.Shape.html Use `rchunks_mut` to get mutable references to overlapping chunks of a specified size, starting from the end. The last chunk may be smaller. Panics if `chunk_size` is zero. ```rust let v = &mut [0, 0, 0, 0, 0]; let mut count = 1; for chunk in v.rchunks_mut(2) { for elem in chunk.iter_mut() { *elem += count; } count += 1; } assert_eq!(v, &[3, 2, 2, 1, 1]); ``` -------------------------------- ### Search Examples Source: https://burn.dev/docs/burn/train/struct.AsyncProcessorTraining.html?search= Examples demonstrating how to use the search functionality to find specific types and patterns. ```APIDOC ## Search Examples ### Description Examples demonstrating how to use the search functionality to find specific types and patterns. ### Example 1: Searching for a specific type ``` std::vec ``` ### Example 2: Searching for a type conversion ``` u32 -> bool ``` ### Example 3: Searching for a generic type conversion ``` Option, (T -> U) -> Option ``` ``` -------------------------------- ### SmoothL1LossConfig::init() Method Source: https://burn.dev/docs/burn/nn/loss/struct.SmoothL1LossConfig.html?search=u32+-%3E+bool Initializes a Smooth L1 Loss module using the current configuration. Panics if beta is not positive. ```rust pub fn init(&self) -> SmoothL1Loss ``` -------------------------------- ### Get Pointer Range of Slice Source: https://burn.dev/docs/burn/prelude/struct.Shape.html Retrieve the start and end raw pointers of a slice, forming a half-open range. The end pointer is one past the last element and requires extra caution. ```rust let a = [1, 2, 3]; let x = &a[1] as *const _; let y = &5 as *const _; assert!(a.as_ptr_range().contains(&x)); assert!(!a.as_ptr_range().contains(&y)); ``` -------------------------------- ### LpLossConfig::init Method Source: https://burn.dev/docs/burn/nn/loss/struct.LpLossConfig.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes a Lp Loss module from its configuration. Panics if p <= 0. ```rust pub fn init(&self) -> LpLoss ``` -------------------------------- ### Get Mutable Pointer Range of Slice Source: https://burn.dev/docs/burn/prelude/struct.Shape.html Obtain the start and end mutable raw pointers of a slice, forming a half-open range. The end pointer is one past the last element and requires extra caution. ```rust let mut v = [1, 2, 3]; let ptr_range = v.as_mut_ptr_range(); // Example usage would go here, but is not provided in the source. ``` -------------------------------- ### LpLossConfig Initialization Source: https://burn.dev/docs/burn/nn/loss/struct.LpLossConfig.html Demonstrates how to create LpLossConfig instances for L1, L2, and custom p-values. ```APIDOC ## LpLossConfig Configuration for the Lp Loss module. ### §Example ```rust use burn_nn::loss::{LpLossConfig, Reduction}; // Create L1 loss (MAE when using mean reduction) let l1_loss = LpLossConfig::l1(); // Create L2 loss (MSE when using mean reduction) let l2_loss = LpLossConfig::l2(); // Create custom Lp loss with p=3 let l3_loss = LpLossConfig::new(3.0).init(); ``` ## Fields ### `p: f64` The exponent `p` determining the type of error measurement. Common values: * `p = 1.0`: L1 loss (MAE with mean reduction) - robust to outliers * `p = 2.0`: L2 loss (MSE with mean reduction) - standard choice, differentiable everywhere * `p > 2.0`: Increasingly sensitive to large errors (outliers) * `0 < p < 1`: More robust to outliers than L1 (quasi-norm) ## Implementations ### `impl LpLossConfig` #### `pub fn new(p: f64) -> LpLossConfig` Create a new instance of the config. ##### §Arguments ###### §Required Arguments ###### §`p` The exponent `p` determining the type of error measurement. Common values: * `p = 1.0`: L1 loss (MAE with mean reduction) - robust to outliers * `p = 2.0`: L2 loss (MSE with mean reduction) - standard choice, differentiable everywhere * `p > 2.0`: Increasingly sensitive to large errors (outliers) * `0 < p < 1`: More robust to outliers than L1 (quasi-norm) #### `pub fn init(&self) -> LpLoss` Initializes a Lp Loss module. ##### §Panics Panics if `p <= 0`. #### `pub fn l1() -> LpLoss` Creates L1 loss (p=1). When used with `Reduction::Mean`, this computes Mean Absolute Error (MAE). When used with `Reduction::Sum`, this computes Sum of Absolute Errors (SAE). #### `pub fn l2() -> LpLoss` Creates L2 loss (p=2). When used with `Reduction::Mean`, this computes Mean Squared Error (MSE). When used with `Reduction::Sum`, this computes Sum of Squared Errors (SSE). ``` -------------------------------- ### Get Element Offset by Pointer Source: https://burn.dev/docs/burn/prelude/struct.Shape.html Use `element_offset` to find the index of an element reference within a slice using pointer arithmetic. It returns `None` if the element reference does not point to the start of an element. This method panics if `T` is zero-sized. ```rust let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); ``` ```rust let arr: &[[u32; 2]] = &[[0, 1], [2, 3]]; let flat_arr: &[u32] = arr.as_flattened(); let ok_elm: &[u32; 2] = flat_arr[0..2].try_into().unwrap(); let weird_elm: &[u32; 2] = flat_arr[1..3].try_into().unwrap(); assert_eq!(ok_elm, &[0, 1]); assert_eq!(weird_elm, &[1, 2]); assert_eq!(arr.element_offset(ok_elm), Some(0)); // Points to element 0 assert_eq!(arr.element_offset(weird_elm), None); // Points between element 0 and 1 ``` -------------------------------- ### Get Element Offset by Pointer Source: https://burn.dev/docs/burn/prelude/struct.Shape.html?search=u32+-%3E+bool Find the index of an element within a slice using its memory address. This method relies on pointer arithmetic and does not compare element values. It returns `None` if the pointer is not aligned to an element's start. ```rust let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); ``` -------------------------------- ### Arc::into_raw_with_allocator and Arc::from_raw_in Example Source: https://burn.dev/docs/burn/tensor/backend/type.ServerUtilitiesHandle.html?search= Demonstrates consuming an Arc to get its raw pointer and allocator, and then reconstructing the Arc from these. This requires the `allocator_api` feature and involves unsafe operations for pointer manipulation. Ensure the pointer is converted back to an Arc to avoid memory leaks. ```rust #![feature(allocator_api)] use std::sync::Arc; use std::alloc::System; let x = Arc::new_in("hello".to_owned(), System); let (ptr, alloc) = Arc::into_raw_with_allocator(x); assert_eq!(unsafe { &*ptr }, "hello"); let x = unsafe { Arc::from_raw_in(ptr, alloc) }; assert_eq!(&*x, "hello"); ``` -------------------------------- ### ViewLayoutLaunchArg Implementations Source: https://burn.dev/docs/burn/tensor/struct.f16.html?search=u32+-%3E+bool Handles argument registration and expansion for kernel compilation. ```APIDOC ## type RuntimeArg = ::RuntimeArg ### Description The runtime argument for the kernel. ``` ```APIDOC ## type CompilationArg = ::CompilationArg ### Description Compilation argument. ``` ```APIDOC ## fn register( arg: ::RuntimeArg, _buffer: &B, _ty: Type, launcher: &mut KernelLauncher, ) -> ::CompilationArg ### Description Registers an input or output argument for a kernel launch. ### Parameters * `arg`: The runtime argument for the kernel. * `_buffer`: A reference to the buffer argument. * `_ty`: The type of the argument. * `launcher`: A mutable reference to the `KernelLauncher`. ### Returns The compilation argument for the registered argument. ``` ```APIDOC ## fn expand( arg: &::CompilationArg, _ty: Type, builder: &mut KernelBuilder, ) -> ::ExpandType ### Description Register an input variable during compilation that fills the [`KernelBuilder`]. ### Parameters * `arg`: A reference to the compilation argument. * `_ty`: The type of the argument. * `builder`: A mutable reference to the `KernelBuilder`. ### Returns The expanded type for the kernel builder. ``` ```APIDOC ## fn expand_output( arg: &::CompilationArg, _ty: Type, builder: &mut KernelBuilder, ) -> ::ExpandType ### Description Register an output variable during compilation that fills the [`KernelBuilder`]. ### Parameters * `arg`: A reference to the compilation argument. * `_ty`: The type of the argument. * `builder`: A mutable reference to the `KernelBuilder`. ### Returns The expanded type for the kernel builder. ``` -------------------------------- ### RmsPropStateItem Search Examples Source: https://burn.dev/docs/burn/optim/struct.RmsPropStateItem.html?search= Examples of how to search for RmsPropStateItem. These examples demonstrate common search patterns. ```APIDOC ## Search Examples ### Example 1: Searching for a specific type ```rust // Example: Search for std::vec ``` ### Example 2: Searching for type conversions ```rust // Example: Search for u32 -> bool ``` ### Example 3: Searching for generic type conversions ```rust // Example: Search for Option, (T -> U) -> Option ``` ``` -------------------------------- ### MultiDevicesTrainStep::new Source: https://burn.dev/docs/burn/train/train/struct.MultiDevicesTrainStep.html?search= Creates a new instance of MultiDevicesTrainStep, initializing it for multi-device training. ```APIDOC ## MultiDevicesTrainStep::new ### Description Create a new multi devices train step. ### Method `pub fn new(devices: &[<::Backend as BackendTypes>::Device]) -> MultiDevicesTrainStep` ### Arguments * `devices` - Devices to be used for training. ### Returns A new `MultiDevicesTrainStep` instance. ``` -------------------------------- ### MomentumStateItem Search Examples Source: https://burn.dev/docs/burn/optim/momentum/struct.MomentumStateItem.html?search= Examples of how to search for MomentumStateItem. These examples demonstrate common search patterns. ```APIDOC ## Search Examples ### Example 1: Searching for a specific type ``` std::vec ``` ### Example 2: Searching for a type conversion ``` u32 -> bool ``` ### Example 3: Searching for a generic type conversion ``` Option, (T -> U) -> Option ``` ``` -------------------------------- ### CrossEntropyLossRecordItem Search Examples Source: https://burn.dev/docs/burn/nn/loss/struct.CrossEntropyLossRecordItem.html?search= Examples of how to search for CrossEntropyLossRecordItem. These examples demonstrate different query patterns. ```APIDOC ## Search Examples ### Example 1: Searching for a specific type ``` std::vec ``` ### Example 2: Searching for type conversions ``` u32 -> bool ``` ### Example 3: Searching for generic type transformations ``` Option, (T -> U) -> Option ``` ``` -------------------------------- ### InstanceNormConfig::init Source: https://burn.dev/docs/burn/nn/modules/norm/struct.InstanceNormConfig.html Initializes a new InstanceNorm module using the configuration. ```APIDOC ## InstanceNormConfig::init ### Description Initialize a new instance norm module. ### Method `pub fn init(&self, device: &::Device) -> InstanceNorm` ### Type Parameters * `B` - Represents the backend type. ### Arguments * `device` (&`::Device`) - The device on which to initialize the InstanceNorm module. ``` -------------------------------- ### ComposedLrSchedulerRecordItem Search Examples Source: https://burn.dev/docs/burn/lr_scheduler/composed/struct.ComposedLrSchedulerRecordItem.html?search= Examples of how to search for ComposedLrSchedulerRecordItem. These examples demonstrate different search patterns. ```APIDOC ## Search Examples ### Example 1: Searching for a specific item ``` std::vec ``` ### Example 2: Searching for a type conversion ``` u32 -> bool ``` ### Example 3: Searching for a generic type conversion ``` Option, (T -> U) -> Option ``` ``` -------------------------------- ### SoftplusConfig init() Method Source: https://burn.dev/docs/burn/nn/activation/struct.SoftplusConfig.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes a new Softplus Layer using the current configuration. ```rust pub fn init(&self) -> Softplus ``` -------------------------------- ### MaxPool2dWithIndices Search Examples Source: https://burn.dev/docs/burn/tensor/backend/ops/struct.MaxPool2dWithIndices.html?search= Examples of how to search for MaxPool2dWithIndices operations. These examples demonstrate different query patterns. ```APIDOC ## MaxPool2dWithIndices Search ### Description Provides examples of search queries for `MaxPool2dWithIndices`. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### Dataset Windows Example Source: https://burn.dev/docs/burn/data/dataset/transform/struct.SamplerDataset.html Demonstrates how to create a sliding window over a dataset using the `windows` method. This is useful for processing sequences of data. Ensure the dataset is not empty and the window size is valid. ```rust use crate::burn_dataset:: transform::{Windows, WindowsDataset}, Dataset, InMemDataset, }; let items = [1, 2, 3, 4].to_vec(); let dataset = InMemDataset::new(items.clone()); let windows_dataset = WindowsDataset::new(dataset, 2); let windows = windows_dataset.windows(2); assert_eq!(windows.next().unwrap(), vec![1, 2]); assert_eq!(windows.next().unwrap(), vec![2, 3]); assert_eq!(windows.next().unwrap(), vec![3, 4]); assert!(windows.next().is_none()); ``` -------------------------------- ### ConvTranspose1dRecordItem Search Examples Source: https://burn.dev/docs/burn/nn/modules/conv/struct.ConvTranspose1dRecordItem.html?search= Examples of how to perform searches for ConvTranspose1dRecordItem. These examples demonstrate different query patterns. ```APIDOC ## Search Examples ### Example 1: Basic Type Search ```rust // Search for std::vec ``` ### Example 2: Type Conversion Search ```rust // Search for u32 -> bool ``` ### Example 3: Generic Type Conversion Search ```rust // Search for Option, (T -> U) -> Option ``` ``` -------------------------------- ### RngSource Initialization Examples Source: https://burn.dev/docs/burn/data/dataset/transform/enum.RngSource.html?search=u32+-%3E+bool Demonstrates various ways to create an RngSource instance, including default, seeded, and from an existing StdRng. Also shows how to fork an RNG. ```rust use rand::rngs::StdRng; use rand::SeedableRng; use burn_dataset::transform::RngSource; // Default via `StdRng::from_os_rng()` (`RngSource::Default`) let system: RngSource = RngSource::default(); // From a fixed seed (`RngSource::Seed`) let seeded: RngSource = 42.into(); // From an existing rng (`RngSource::Rng`) let rng = StdRng::seed_from_u64(123); let with_rng: RngSource = rng.into(); // Forks the parent RNG to derive an independent, deterministic child RNG. // The original `rng` is modified, and the resulting `RngSource` contains // a new RNG starting from a unique state. let mut rng = StdRng::seed_from_u64(123); let forked: RngSource = (&mut rng).into(); ``` -------------------------------- ### Install Application Logger Source: https://burn.dev/docs/burn/train/struct.FileApplicationLoggerInstaller.html Installs the configured file application logger. This method is part of the ApplicationLoggerInstaller trait implementation for FileApplicationLoggerInstaller. ```rust fn install(&self) -> Result<(), String> ``` -------------------------------- ### FileApplicationLoggerInstaller::install Source: https://burn.dev/docs/burn/train/struct.FileApplicationLoggerInstaller.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Installs the configured file application logger, making it active for log output. ```APIDOC ## FileApplicationLoggerInstaller::install ### Description Install the application logger. ### Method ```rust fn install(&self) -> Result<(), String> ``` ### Returns * `Result<(), String>` - Ok(()) if the logger was installed successfully, or an Err(String) with an error message if installation failed. ``` -------------------------------- ### EluConfig::init() Source: https://burn.dev/docs/burn/nn/activation/struct.EluConfig.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes a new Elu Layer using the current configuration. ```APIDOC ### `fn init(&self) -> Elu` Initialize a new Elu Layer. ``` -------------------------------- ### BiLstmRecord Search Examples Source: https://burn.dev/docs/burn/nn/struct.BiLstmRecord.html?search= Provides examples of how to perform searches within the BiLstmRecord system. These examples illustrate common search patterns and syntax. ```APIDOC ## Search Examples ### General Search Syntax - **std::vec**: Search for items related to the standard vector type. - **u32 -> bool**: Search for functions or types that convert a u32 to a boolean. - **Option, (T -> U) -> Option**: Search for operations involving Option types and transformations. ### Usage These examples can be used as a starting point for constructing your own search queries to find specific data or functionality within the BiLstmRecord system. ``` -------------------------------- ### FileApplicationLoggerInstaller::new Source: https://burn.dev/docs/burn/train/struct.FileApplicationLoggerInstaller.html Creates a new instance of FileApplicationLoggerInstaller, configured to log to the specified file path. ```APIDOC ## pub fn new(path: impl AsRef) -> FileApplicationLoggerInstaller ### Description Create a new file application logger. ### Parameters #### Path Parameters - **path** (impl AsRef) - Required - The path to the file where logs will be written. ``` -------------------------------- ### LstmRecordItem_search Examples Source: https://burn.dev/docs/burn/nn/modules/lstm/struct.LstmRecordItem.html?search= Examples of how to search for LstmRecordItem records. ```APIDOC ## Search Examples This section provides example search queries for `LstmRecordItem`. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### ComposedLrSchedulerRecord Search Examples Source: https://burn.dev/docs/burn/lr_scheduler/composed/struct.ComposedLrSchedulerRecord.html?search= Examples of how to search for ComposedLrSchedulerRecord. ```APIDOC ## Search Examples Example searches: * std::vec * u32 -> bool * Option, (T -> U) -> Option ``` -------------------------------- ### RLTraining::new Source: https://burn.dev/docs/burn/train/struct.RLTraining.html Creates a new runner for reinforcement learning with a specified directory for checkpoints and an environment initializer. ```APIDOC ## RLTraining::new ### Description Creates a new runner for reinforcement learning. ### Method `new` ### Parameters #### Arguments - `directory` (impl AsRef) - The directory to save the checkpoints. - `env_initializer` (EI) - Specifies how to initialize the environment. ``` -------------------------------- ### AdamWStateItem Search Examples Source: https://burn.dev/docs/burn/optim/struct.AdamWStateItem.html?search= Examples of search queries for AdamWStateItem. ```APIDOC ## AdamWStateItem Search ### Description Provides examples of how to search for `AdamWStateItem` within the Burn optimizer. ### Example Searches * `std::vec` * `u32 -> bool` * `Option, (T -> U) -> Option` ``` -------------------------------- ### FileApplicationLoggerInstaller::install Source: https://burn.dev/docs/burn/train/struct.FileApplicationLoggerInstaller.html Installs the configured file application logger. This method should be called after creating an instance of FileApplicationLoggerInstaller. ```APIDOC ## fn install(&self) -> Result<(), String> ### Description Install the application logger. ### Returns - `Ok(())` if the logger was installed successfully. - `Err(String)` if an error occurred during installation. ``` -------------------------------- ### KLDivLossConfig::init() Source: https://burn.dev/docs/burn/nn/loss/struct.KLDivLossConfig.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes the KLDiv Loss based on the current configuration. ```APIDOC ## pub fn init(&self) -> KLDivLoss Initialize KLDiv Loss. ``` -------------------------------- ### FileApplicationLoggerInstaller Implementation Source: https://burn.dev/docs/burn/train/trait.ApplicationLoggerInstaller.html?search=u32+-%3E+bool Example of an implementation for the ApplicationLoggerInstaller trait, specifically for FileApplicationLoggerInstaller. ```rust impl ApplicationLoggerInstaller for FileApplicationLoggerInstaller { // ... implementation details ... } ``` -------------------------------- ### NumericEntry Search Examples Source: https://burn.dev/docs/burn/train/metric/enum.NumericEntry.html?search= Examples of how to search for numeric entries. ```APIDOC ## NumericEntry Search Examples This section provides examples of common search queries for numeric entries. ### Example Searches * `std::vec` * `u32 -> bool` * `Option, (T -> U) -> Option` ```