{"record":{"id":"86c05150ab14a3ce","repo":"tracel-ai/burn","slug":"other-reduction-is-not-supported-86c051","errorCode":null,"errorMessage":"{other:?} reduction is not supported","messagePattern":"(.+?) reduction is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-nn/src/loss/poisson.rs","lineNumber":139,"sourceCode":"    /// - `predictions`: `[...dims]`\n    /// - `targets`: `[...dims]`\n    /// - `output`: `[1]`\n    ///\n    /// # Panics\n    /// - Panics if the shapes of `predictions` and `targets` do not match.\n    /// - Panics if any target value is negative.\n    /// - Panics if `log_input` is `false` and any prediction value is negative.\n    pub fn forward<const D: usize>(\n        &self,\n        predictions: Tensor<D>,\n        targets: Tensor<D>,\n        reduction: Reduction,\n    ) -> Tensor<1> {\n        let loss = self.forward_no_reduction(predictions, targets);\n        match reduction {\n            Reduction::Mean | Reduction::Auto => loss.mean(),\n            Reduction::Sum => loss.sum(),\n            other => panic!(\"{other:?} reduction is not supported\"),\n        }\n    }\n\n    /// Computes the loss element-wise for the given predictions and targets without reduction.\n    ///\n    /// # Arguments\n    /// - `predictions`: The predicted values.\n    /// - `targets`: The target values.\n    ///\n    /// # Shapes\n    /// - `predictions`: `[...dims]`\n    /// - `targets`: `[...dims]`\n    /// - `output`: `[...dims]`\n    ///\n    /// # Panics\n    /// - Panics if the shapes of `predictions` and `targets` do not match.\n    /// - Panics if any target value is negative.\n    /// - Panics if `log_input` is `false` and any prediction value is negative.","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/loss/poisson.rs#L121-L157","documentation":"The Poisson loss `forward` only supports reduction modes Mean, Auto (treated as Mean), and Sum. Any other `Reduction` variant (e.g. Reduction::None or a future enum variant) reaches the catch-all match arm and panics. The library throws it because element-wise results are always reduced to a scalar `Tensor<1>` and unsupported modes have no defined behavior.","triggerScenarios":"Calling `PoissonLoss::forward(predictions, targets, reduction)` with a `Reduction` value other than Mean, Auto, or Sum — typically `Reduction::None` or `Reduction::Sum`-like custom variants.","commonSituations":"Copying reduction config from another framework where None is valid (PyTorch's 'none' reduction); deserializing a config from JSON that contains an unexpected reduction value; switching to a newer burn version that added a Reduction variant not yet handled.","solutions":["Pass Reduction::Mean, Reduction::Auto, or Reduction::Sum to forward().","If you need no reduction, call `forward_no_reduction(predictions, targets)` instead, which returns the element-wise loss.","Check the Reduction enum in your burn version and ensure the value you pass is one of the supported variants."],"exampleFix":"// before\nlet loss = poisson_loss.forward(predictions, targets, Reduction::None);\n// after\nlet loss = poisson_loss.forward_no_reduction(predictions, targets);\n// or\nlet loss = poisson_loss.forward(predictions, targets, Reduction::Mean);","handlingStrategy":"validation","validationCode":"fn is_supported_reduction(r: &Reduction) -> bool {\n    matches!(r, Reduction::Mean | Reduction::Auto | Reduction::Sum)\n}\nassert!(is_supported_reduction(&reduction), \"use forward_no_reduction for element-wise loss\");","typeGuard":"fn is_supported_reduction(r: &Reduction) -> bool {\n    matches!(r, Reduction::Mean | Reduction::Auto | Reduction::Sum)\n}","tryCatchPattern":"// Rust panics are not catchable normally; if you must, wrap in std::panic::catch_unwind:\nlet result = std::panic::catch_unwind(|| poisson_loss.forward(preds, targets, reduction));\nmatch result {\n    Ok(loss) => loss,\n    Err(_) => poisson_loss.forward_no_reduction(preds, targets).mean(),\n}","preventionTips":["Restrict user-facing Reduction to Mean/Sum/Auto in your own config enums and map to burn's Reduction at the boundary.","Use forward_no_reduction when you need element-wise losses.","Match exhaustively on Reduction in wrappers so new variants surface at compile time."],"tags":["rust","panic","loss-function","unsupported-argument"],"backgroundTag":"unsupported-reduction-mode","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}