tracel-ai/burn · error

Unsupported dtype for `int_from_data`: {:?}

Error message

Unsupported dtype for `int_from_data`: {:?}

What it means

burn-ndarray's `int_from_data` accepts only int or uint dtype TensorData; float or bool data reaches the `else` arm and panics with `unimplemented!("Unsupported dtype for `int_from_data`: {:?}", data.dtype)`. There is no implicit dtype conversion in the ndarray backend's tensor constructors.

Source

Thrown at crates/burn-ndarray/src/ops/int_tensor.rs:29

// Current crate
use crate::SharedArray;
use crate::execute_with_int_dtype;
use crate::ops::matmul::matmul;
use crate::{ExpElement, NdArrayDevice, SEED, execute_with_int_out_dtype, slice};
use crate::{NdArray, cast_to_dtype, execute_with_dtype, tensor::NdArrayTensor};
use crate::{cat_with_dtype, execute_with_float_out_dtype};

// Workspace crates
use super::{NdArrayBitOps, NdArrayMathOps, NdArrayOps};
use burn_backend::{DType, Shape, TensorData};

impl IntTensorOps<Self> for NdArray {
    fn int_from_data(data: TensorData, _device: &NdArrayDevice) -> NdArrayTensor {
        if data.dtype.is_int() || data.dtype.is_uint() {
            NdArrayTensor::from_data(data)
        } else {
            unimplemented!("Unsupported dtype for `int_from_data`: {:?}", data.dtype)
        }
    }

    async fn int_into_data(tensor: NdArrayTensor) -> Result<TensorData, ExecutionError> {
        Ok(tensor.into_data())
    }

    fn int_to_device(tensor: NdArrayTensor, _device: &NdArrayDevice) -> NdArrayTensor {
        tensor
    }

    fn int_reshape(tensor: NdArrayTensor, shape: Shape) -> NdArrayTensor {
        execute_with_int_dtype!(tensor, |array| NdArrayOps::reshape(array, shape))
    }

    fn int_slice(tensor: NdArrayTensor, slices: &[burn_backend::Slice]) -> NdArrayTensor {
        slice!(tensor, slices)
    }

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Convert the data first: `data.convert::<i64>()` (or the target int type)
  2. On the Tensor API, create as float then `.int()` to cast
  3. Fix the data source to emit int/uint buffers
  4. Check `data.dtype.is_int() || data.dtype.is_uint()` before calling

Example fix

// before
let t = Tensor::<NdArray, 1, Int>::from_data(data_f32, &device);
// after
let t = Tensor::<NdArray, 1, Int>::from_data(data_f32.convert::<i64>(), &device);
Defensive patterns

Strategy: validation

Validate before calling

if !(data.dtype.is_int() || data.dtype.is_uint()) {
    data = data.convert::<i64>();
}
let t = Tensor::<NdArray, 1, Int>::from_data(data, &device);

Type guard

fn is_int_data(data: &TensorData) -> bool {
    data.dtype.is_int() || data.dtype.is_uint()
}

Try / catch

// pre-convert; from_data panics instead of returning Err
let safe_data = if is_int_data(&data) { data } else { data.convert::<i64>() };
let t = Tensor::<NdArray, 1, Int>::from_data(safe_data, &device);

Prevention

When it happens

Trigger: Creating an int tensor from float TensorData via `int_from_data` / `Tensor::<NdArray,_,Int>::from_data(...)`, e.g. passing F32 buffers, image data decoded as float, or imported ONNX weights stored as float into int tensors.

Common situations: Feeding image pixel buffers (F32-normalized) into int tensors; loading indices from float-preprocessed arrays; assuming cross-backend from_data behavior (some backends coerce, ndarray does not).

Related errors


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