tracel-ai/burn · error

Unsupported type {:?}

Error message

Unsupported type {:?}

What it means

`rfft` only supports floating-point inputs (F32/F64) because the FFT kernel is written for real float element types. Any other dtype (integer, bool, F16/BF16 if unlisted) triggers this panic before launch.

Source

Thrown at crates/burn-cubecl/src/kernel/fft/base.rs:42

        return slice(tensor, &ranges);
    }
    let mut padded_shape = shape.clone();
    padded_shape[dim] = target;
    let padded = zeros(tensor.device.clone(), padded_shape, tensor.dtype);
    let slices: Vec<Slice> = shape.iter().map(|&s| Slice::from(0..s)).collect();
    crate::kernel::index::slice_assign(padded, &slices, tensor)
}

/// Launch the rfft kernel with optional padding for non-power-of-two sizes.
///
/// Signal is first truncated or zero-padded to `n` (when provided), then internally
/// padded to the next power of two so the kernel operates on a pow2 length.
/// Output bin count is `fft_size / 2 + 1` where `fft_size = next_pow2(n)`.
pub fn rfft(signal: CubeTensor, dim: usize, n: Option<usize>) -> (CubeTensor, CubeTensor) {
    let dtype = match signal.dtype {
        DType::F64 => f64::elem_type_native(),
        DType::F32 => f32::elem_type_native(),
        _ => panic!("Unsupported type {:?}", signal.dtype),
    };

    let input_device = signal.device.clone();
    let input_dtype = signal.dtype;
    let input_shape = signal.shape();
    let requested_n = n.unwrap_or(input_shape[dim]);
    let fft_size = requested_n.next_power_of_two();

    // Truncate/pad to requested_n, THEN pad to fft_size; otherwise for
    // requested_n < input_len < fft_size we would keep bogus samples in [n, fft_size).
    let signal = pad_to_length(signal, dim, requested_n);
    let signal = pad_to_length(signal, dim, fft_size);

    let signal_shape = signal.shape();
    let mut output_shape = signal_shape.clone();
    output_shape[dim] = fft_size / 2 + 1;

    let output_re = empty_device_dtype(

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Convert the input with `.float()` (or `.to_dtype(DType::F32)`) before calling rfft
  2. Cast to F64 only if double precision is genuinely needed
  3. Cast integer audio data to float and normalize before the transform

Example fix

// before
let (re, im) = samples_i32.rfft(0, None); // panics
// after
let (re, im) = samples_i32.float().rfft(0, None);
Defensive patterns

Strategy: validation

Validate before calling

assert!(matches!(signal.dtype(), DType::F32 | DType::F64), "rfft needs F32/F64");

Type guard

fn fft_supported(t: &TensorBase) -> bool { matches!(t.dtype(), DType::F32 | DType::F64) }

Prevention

When it happens

Trigger: Calling `tensor.rfft(dim, n)` on a tensor whose dtype is not F32 or F64.

Common situations: FFT on integer data (e.g. raw audio samples loaded as i16/i32); half-precision tensors from mixed-precision training; forgetting `.float()` conversion after decoding data.

Related errors


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