Skip to content

Wrong result when call reshape() after Tensor::stack #1053

@wcshds

Description

@wcshds

Here is the code.

type Backend = NdArray;

let tensor = Tensor::<Backend, 1, Int>::arange(1..25).reshape([4, 6]);
let zeros: Tensor<Backend, 2, Int> = Tensor::zeros([4, 6]);
let intersperse =
    Tensor::stack::<3>([tensor.clone(), zeros.clone()].to_vec(), 2).reshape([4, 12]);

println!("{}", intersperse);

The result is:

Tensor {
  data:
[[1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0, 0],
 [7, 8, 9, 10, 11, 12, 0, 0, 0, 0, 0, 0],
 [13, 14, 15, 16, 17, 18, 0, 0, 0, 0, 0, 0],
 [19, 20, 21, 22, 23, 24, 0, 0, 0, 0, 0, 0]],
  shape:  [4, 12],
  device:  Cpu,
  backend:  "ndarray",
  kind:  "Int",
  dtype:  "i64",
}

But the expected result should be:

[[1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0],
 [7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0],
 [13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0],
 [19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0]],

I can get correct results on LibTorch Backend and Wgpu Backend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions