tracel-ai/burn · error

HammingWindow size doesn't fit in i64 range.

Error message

HammingWindow size doesn't fit in i64 range.

What it means

Same overflow guard as blackman_window but for hamming_window: the function converts the usize window size to i64 to build the arange tensor, panicking with this message if the value exceeds the i64 range.

Solutions

  1. Validate the size fits in i64 before calling hamming_window
  2. Cap the window length to a practical maximum in configuration parsing
  3. Fix the upstream size computation to avoid overflow
  4. Reuse the sanity check that sizes >= 2 within i64 range are handled normally

Example fix

// before
let w = hamming_window(size, periodic, device);
// after
let size_i64 = i64::try_from(size).context("invalid window size")?;
let w = hamming_window(size_i64 as usize, periodic, device);
Defensive patterns

Strategy: validation

Validate before calling

if size > (i64::MAX as usize) {
    return Err("Hamming window size too large".into());
}
let w = hamming_window(size, periodic, device);

Prevention

When it happens

Trigger: Calling `hamming_window(size)` with size > i64::MAX; a size computed from overflowing arithmetic (bad hop/length math in an audio pipeline); fuzz or adversarial config inputs.

Common situations: Audio DSP configs with corrupted window-length parameters; derived sizes from sample-rate arithmetic that wrap; generic parameter sweeps constructing windows from counters.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/b0d13d7584abbd2f. Report an issue: GitHub.

Appendix: source

Thrown at crates/burn-tensor/src/tensor/signal/hamming_window.rs:51

pub fn hamming_window(
    size: usize,
    periodic: bool,
    options: impl Into<TensorCreationOptions>,
) -> Tensor<1> {
    let opt = options.into();
    let dtype = opt.resolve_dtype::<Float>();
    let shape = [size];
    check!(TensorCheck::creation_ops::<1>("HammingWindow", &shape));

    if size == 0 {
        return Tensor::<1>::empty(shape, opt).cast(dtype);
    }

    if size == 1 {
        return Tensor::<1>::ones(shape, opt).cast(dtype);
    }

    let size_i64 = i64::try_from(size).expect("HammingWindow size doesn't fit in i64 range.");
    let denominator = if periodic { size } else { size - 1 };
    let angular_increment = (2.0 * core::f64::consts::PI) / denominator as f64;

    let alpha = 25.0_f64 / 46.0_f64;
    let beta = 1.0 - alpha;

    Tensor::<1, Int>::arange(0..size_i64, &opt.device)
        .float()
        .mul_scalar(angular_increment)
        .cos()
        .mul_scalar(-beta)
        .add_scalar(alpha)
        .cast(dtype)
}

View on GitHub (pinned to d16f7ba2ed)