Skip to content

reorder() before indexing produces incorrect results #2273

@0xjc

Description

@0xjc

For inp1, I create a 2x3x2 array, reorder it to 2x2x3, and index it along dimension 1.

For inp2, I prepare the reordering beforehand, and index it along dimension 1.

int idx_host[2] = {1, 1};
float inp1_host[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
float inp2_host[12] = {0, 1, 6, 7, 2, 3, 8, 9, 4, 5, 10, 11};
array idx(2, idx_host);
array inp1 = reorder(array(2, 3, 2, inp1_host), 0, 2, 1);
array inp2(2, 2, 3, inp2_host);
array res1 = inp1(span, idx, span);
array res2 = inp2(span, idx, span);
af::print("idx", idx);
af::print("inp1", inp1);
af::print("inp2", inp2);
af::print("res1", res1);
af::print("res2", res2);

Output:

idx
[2 1 1 1]
         1 
         1 

inp1
[2 2 3 1]
    0.0000     6.0000 
    1.0000     7.0000 

    2.0000     8.0000 
    3.0000     9.0000 

    4.0000    10.0000 
    5.0000    11.0000 


inp2
[2 2 3 1]
    0.0000     6.0000 
    1.0000     7.0000 

    2.0000     8.0000 
    3.0000     9.0000 

    4.0000    10.0000 
    5.0000    11.0000 


res1
[2 2 3 1]
    2.0000     2.0000 
    3.0000     3.0000 

    8.0000     8.0000 
    9.0000     9.0000 

    0.0000     0.0000 
    0.0000     0.0000 


res2
[2 2 3 1]
    6.0000     6.0000 
    7.0000     7.0000 

    8.0000     8.0000 
    9.0000     9.0000 

   10.0000    10.0000 
   11.0000    11.0000 

We get inp1 and inp2 the same, as expected, but res1 and res2 differ. res2 is what I would expect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions