#4688·burn

cpu: repeat_dim on an outer dim of size 1 leaves zeros

Author: mineichenCreated Mar 29, 2026Updated Sep 29, 2026
Labelsbugquestion

Describe the bug Instead of initializing the repeated ranges, they seem to stay 0 (or even uninitialized?)

To Reproduce

rust
use burn::tensor::backend::Backend;
use burn::tensor::Tensor;

fn main() {
    test_backend::<burn_ndarray::NdArray<f32, i32>>();
    test_backend::<burn_cpu::Cpu<f32, i32>>();
}

fn test_backend<T: Backend<IntElem = i32>>() {
    let device = Default::default();

    let size = 3;
    let d1 = Tensor::<T, _, _>::arange(0..size as _, &device);
    let repeat_d1 = d1.clone().repeat_dim(0, size);
    let repeat_d2 = d1.reshape([1, size]).repeat_dim(0, size);

    let [d1_result, d2_result] =
        [repeat_d1.to_data(), repeat_d2.to_data()].map(|x| x.as_slice::<i32>().unwrap().to_vec());
    let expected = (0..size).flat_map(|_| 0..size as i32).collect::<Vec<_>>();
    assert_eq!(d1_result, expected);
    let backend_typename = std::any::type_name::<T>();
    if expected != d2_result {
        println!("BUG: {d2_result:?} ({backend_typename:?})");
    } else {
        println!("OK: {d2_result:?} ({backend_typename:?})");
    }
}

outputs:

 OK: [0, 1, 2, 0, 1, 2, 0, 1, 2] ("burn_ndarray::backend::NdArray<f32, i32>")
BUG: [0, 1, 2, 0, 0, 0, 0, 0, 0] ("burn_fusion::backend::Fusion<burn_cubecl::backend::CubeBackend<cubecl_cpu::runtime::CpuRuntime, f32, i32, u8>>")

Expected behavior The pattern 0,1,2 should be repeated Tested with github:master and the latest burn:0.20.1

Desktop

  • OS: TuxedoOS (Using nix flakes for the env; a flake.nix could be provided if necessary)
  • Version 24.04.4 LTS