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

ak.array gives unexpected results on a transposed numpy multi-dimensional array. #3757

Closed
ajpotts opened this issue Sep 9, 2024 · 2 comments · Fixed by #3761 or #3814
Closed

ak.array gives unexpected results on a transposed numpy multi-dimensional array. #3757

ajpotts opened this issue Sep 9, 2024 · 2 comments · Fixed by #3761 or #3814
Assignees
Labels
bug Something isn't working

Comments

@ajpotts
Copy link
Contributor

ajpotts commented Sep 9, 2024

Describe the bug
ak.array gives unexpected results on a transposed numpy multi-dimensional array.

To Reproduce

In [81]: 
    ...: import numpy as np
    ...: rows = 5
    ...: cols = 5
    ...: nda = np.random.randint(1, 10, (rows, cols))
    ...: nda
Out[81]: 
array([[7, 7, 7, 8, 6],
       [9, 4, 9, 6, 2],
       [2, 2, 3, 1, 9],
       [2, 7, 1, 3, 7],
       [4, 2, 7, 5, 1]])

In [82]: 
    ...: nda_to_ak = ak.array(nda)
    ...: nda_to_ak
    ...: 
Out[82]: array([array([7 7 7 8 6]) array([9 4 9 6 2]) array([2 2 3 1 9]) array([2 7 1 3 7]) array([4 2 7 5 1])])

In [83]: 
    ...: npa = np.transpose(nda)
    ...: npa
Out[83]: 
array([[7, 9, 2, 2, 4],
       [7, 4, 2, 7, 2],
       [7, 9, 3, 1, 7],
       [8, 6, 1, 3, 5],
       [6, 2, 9, 7, 1]])

In [84]: 
    ...: npa_to_ak = ak.array(npa)
    ...: npa_to_ak
    ...: 
    ...: 
Out[84]: array([array([7 7 7 8 6]) array([9 4 9 6 2]) array([2 2 3 1 9]) array([2 7 1 3 7]) array([4 2 7 5 1])])


@ajpotts ajpotts added the bug Something isn't working label Sep 9, 2024
@ajpotts ajpotts self-assigned this Sep 9, 2024
@ajpotts
Copy link
Contributor Author

ajpotts commented Sep 10, 2024

This is interesting:

In [32]: ak.array(nda_transpose)
Out[32]: array([array([1 1 3 6 7]) array([4 6 6 8 1]) array([3 7 2 4 8]) array([5 6 5 9 1]) array([3 2 7 9 6])])

In [33]: ak.array(nda_transpose.copy())
Out[33]: array([array([1 4 3 5 3]) array([1 6 7 6 2]) array([3 6 2 5 7]) array([6 8 4 9 9]) array([7 1 8 1 6])])

In [34]: nda_transpose
Out[34]: 
array([[1, 4, 3, 5, 3],
       [1, 6, 7, 6, 2],
       [3, 6, 2, 5, 7],
       [6, 8, 4, 9, 9],
       [7, 1, 8, 1, 6]])


ajpotts added a commit to ajpotts/arkouda that referenced this issue Sep 10, 2024
ajpotts added a commit to ajpotts/arkouda that referenced this issue Sep 11, 2024
ajpotts added a commit to ajpotts/arkouda that referenced this issue Sep 11, 2024
ajpotts added a commit to ajpotts/arkouda that referenced this issue Sep 18, 2024
ajpotts added a commit to ajpotts/arkouda that referenced this issue Sep 18, 2024
@stress-tess
Copy link
Member

stress-tess commented Sep 18, 2024

Dropped a comment on the PR. The reason for this is that for numpy the transpose is being treated as a different view of the same data (switches between column and row major), but the underlying data hasn't changed. We send the underlying data over as a buffer and ignore the order. When we do a copy, it actually moves the data elsewhere

This comment of the PR explains better and looks at the flags of the array and transpose:
#3761 (comment)

ajpotts added a commit to ajpotts/arkouda that referenced this issue Sep 18, 2024
ajpotts added a commit to ajpotts/arkouda that referenced this issue Sep 19, 2024
ajpotts added a commit to ajpotts/arkouda that referenced this issue Sep 20, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 26, 2024
… multi-dimensional array. (#3761)

Co-authored-by: Amanda Potts <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants