{"record":{"id":"de7612446a3366bc","repo":"tracel-ai/burn","slug":"either-output-size-or-scale-factor-must-be-provide","errorCode":null,"errorMessage":"Either output_size or scale_factor must be provided","messagePattern":"Either output_size or scale_factor must be provided","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-nn/src/modules/interpolate/interpolate1d.rs","lineNumber":160,"sourceCode":") -> usize {\n    match (output_size, scale_factor) {\n        (Some(output_size), None) => {\n            // Use provided\n            output_size\n        }\n        (None, Some(scale_factor)) => {\n            // Calculate output size based on scale factor\n            let [_, _, l] = input_dims;\n\n            let new_dim = (l as f64) * (scale_factor as f64);\n\n            if new_dim > usize::MAX as f64 {\n                panic!(\"Scale factor is too large\");\n            }\n\n            new_dim as usize\n        }\n        _ => panic!(\"Either output_size or scale_factor must be provided\"),\n    }\n}\n\nimpl ModuleDisplay for Interpolate1d {\n    fn custom_settings(&self) -> Option<DisplaySettings> {\n        DisplaySettings::new()\n            .with_new_line_after_attribute(false)\n            .optional()\n    }\n\n    fn custom_content(&self, content: Content) -> Option<Content> {\n        content\n            .add_debug_attribute(\"mode\", &self.mode)\n            .add(\"output_size\", &format!(\"{:?}\", self.output_size))\n            .add(\"scale_factor\", &self.scale_factor)\n            .optional()\n    }\n}","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/modules/interpolate/interpolate1d.rs#L142-L178","documentation":"Interpolate1d's `calculate_output_size` requires the config to specify either an explicit output size or a scale factor; the match on the size enum has no other arms, so any other/none configuration panics. It fires when neither `Interpolate1dConfig::Output` nor `::Scale` was provided.","triggerScenarios":"Constructing Interpolate1d with a default/empty config (neither Output nor Scale set) and calling forward, causing calculate_output_size to fall through to the catch-all panic.","commonSituations":"Using `Interpolate1d::default()` or `..Default::default()` in struct update syntax that wipes out the size setting; deserializing an incomplete config where the size field is missing; copying a builder pattern and forgetting the final size setter.","solutions":["Construct with an explicit size: `Interpolate1d::new(Interpolate1dConfig::Output(len))` or `Interpolate1dConfig::Scale(factor)`.","Check that deserialized configs include exactly one of output_size/scale_factor before use.","Avoid `..Default::default()` overriding the size field when building the config."],"exampleFix":"// before\nlet interp = Interpolate1d::new(Interpolate1dConfig::default()); // neither set\n// after\nlet interp = Interpolate1d::new(Interpolate1dConfig::Output(256));\n// or\nlet interp = Interpolate1d::new(Interpolate1dConfig::Scale(2.0));","handlingStrategy":"validation","validationCode":"fn interpolate_config_is_set(config: &Interpolate1dConfig) -> bool {\n    matches!(config, Interpolate1dConfig::Output(_) | Interpolate1dConfig::Scale(_))\n}\nassert!(interpolate_config_is_set(&config), \"Interpolate1dConfig must set Output or Scale\");","typeGuard":"fn has_size_spec(config: &Interpolate1dConfig) -> bool {\n    matches!(config, Interpolate1dConfig::Output(_) | Interpolate1dConfig::Scale(_))\n}","tryCatchPattern":"let result = std::panic::catch_unwind(|| interpolate.forward(input));\nmatch result {\n    Ok(out) => out,\n    Err(_) => Interpolate1d::new(Interpolate1dConfig::Scale(1.0)).forward(input), // identity fallback\n}","preventionTips":["Never construct Interpolate1d from a bare default config; always set Output or Scale.","Watch for `..Default::default()` wiping the size field in struct-update syntax.","Validate deserialized interpolate configs contain a size spec before building the module."],"tags":["rust","panic","interpolation","missing-argument","config-validation"],"backgroundTag":"missing-required-config","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"}