tracel-ai/burn · error

reduce_bool_dim_int: unsupported dtype {:?}

Error message

reduce_bool_dim_int: unsupported dtype {:?}

What it means

Dtype-dispatch exhaustiveness panic in `reduce_bool_dim_int`, the integer any/all-dim reduction: the match covers I64..U8; any other dtype (float/bool) reaching it panics, indicating an integer reduction was invoked on a non-integer tensor.

Source

Thrown at crates/burn-flex/src/ops/comparison.rs:1068

    out_dtype: BoolDType,
) -> FlexTensor {
    let tensor = tensor.to_contiguous();
    macro_rules! dispatch {
        ($ty:ty) => {{
            let data: &[$ty] = tensor.storage();
            reduce_bool_dim_with(&tensor, dim, init, combine, out_dtype, |idx| data[idx] != 0)
        }};
    }
    match tensor.dtype() {
        DType::I64 => dispatch!(i64),
        DType::I32 => dispatch!(i32),
        DType::I16 => dispatch!(i16),
        DType::I8 => dispatch!(i8),
        DType::U64 => dispatch!(u64),
        DType::U32 => dispatch!(u32),
        DType::U16 => dispatch!(u16),
        DType::U8 => dispatch!(u8),
        other => panic!("reduce_bool_dim_int: unsupported dtype {:?}", other),
    }
}

/// Reduce along a dimension producing a bool tensor (for bool any/all_dim).
fn reduce_bool_dim_raw(
    tensor: &FlexTensor,
    dim: usize,
    init: bool,
    combine: fn(bool, bool) -> bool,
    out_dtype: BoolDType,
) -> FlexTensor {
    let tensor = tensor.to_contiguous();
    let data: &[u8] = tensor.bytes();
    reduce_bool_dim_with(&tensor, dim, init, combine, out_dtype, |idx| data[idx] != 0)
}

// Tests kept here probe flex-internal `reduce_bool_dim_with` dispatch on
// non-contiguous inputs (stale-pointer-read regression, see prior incident

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Use any_float_dim/all_float_dim for float tensors
  2. Cast the tensor to an integer dtype before the reduction
  3. Check tensor.dtype() and branch to the correct reduce family

Example fix

// before
let col_all = all_int_dim(f32_tensor, 0, BoolDType::Native);
// after
let col_all = all_float_dim(f32_tensor, 0, BoolDType::Native);
Defensive patterns

Strategy: type-guard

Validate before calling

if !matches!(t.dtype(), DType::I64|DType::I32|DType::I16|DType::I8|DType::U64|DType::U32|DType::U16|DType::U8) { /* use any_float_dim/all_float_dim or cast */ }

Type guard

fn is_int_dtype(d: &DType) -> bool {
    matches!(d, DType::I64|DType::I32|DType::I16|DType::I8|DType::U64|DType::U32|DType::U16|DType::U8)
}

Prevention

When it happens

Trigger: Calling any_int_dim or all_int_dim with a float or bool tensor instead of one of the supported integer dtypes.

Common situations: Dim-wise any/all on float tensors misrouted to the int path; tensors converted to float upstream (normalization) before the reduction.

Related errors


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