Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected result of .into_shape for f-order array #643

Closed
raskr opened this issue Jun 18, 2019 · 1 comment
Closed

Unexpected result of .into_shape for f-order array #643

raskr opened this issue Jun 18, 2019 · 1 comment

Comments

@raskr
Copy link

raskr commented Jun 18, 2019

I applied reversed_axes to get f-order array and then called into_shape:

let a1 = ndarray::arr3(&[
    [
        [0., 1.],
        [2., 3.],
    ],
    [
        [4., 5.],
        [6., 7.],
    ]
]);
println!("a1:\n{:?}", a1);
let a2 = a1.view().reversed_axes();
println!("a2:\n{:?}", a2);
let a3 = a2.into_shape(8);
println!("a3:\n{:?}", a3);

I expected a3 to be [0.0, 4.0, 2.0, 6.0, 1.0, 5.0, 3.0, 7.0], but the result was:

a1:
[[[0.0, 1.0],
  [2.0, 3.0]],
 [[4.0, 5.0],
  [6.0, 7.0]]] shape=[2, 2, 2], strides=[4, 2, 1], layout=C (0x1), const ndim=3
a2:
[[[0.0, 4.0],
  [2.0, 6.0]],
 [[1.0, 5.0],
  [3.0, 7.0]]] shape=[2, 2, 2], strides=[1, 2, 4], layout=F (0x2), const ndim=3
a3:
Ok([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0] shape=[8], strides=[1], layout=C | F (0x3), const ndim=1)

Is this an expected behavior?

@jturner314
Copy link
Member

The reason why this is happening is that .into_shape() uses the memory order of the elements, which is not necessarily standard order. This behavior is quite bad because it's not always easy to determine what memory order an array will have. The behavior of .into_shape() needs to be changed. Please feel free to add comments to #390.

Closing as a duplicate of #390.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants