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

Wrong index with 3dim array when 1 dim size is 1 #319

Open
jdavid opened this issue Nov 7, 2024 · 1 comment
Open

Wrong index with 3dim array when 1 dim size is 1 #319

jdavid opened this issue Nov 7, 2024 · 1 comment

Comments

@jdavid
Copy link
Contributor

jdavid commented Nov 7, 2024

(Pdb) p arr
<blosc2.lazyexpr.LazyExpr object at 0x7fd224d12600>
(Pdb) p arr[:]
array([[[16., 16., 16., ..., 16., 16., 16.]],

       [[16., 16., 16., ..., 16., 16., 16.]],

       [[16., 16., 16., ..., 16., 16., 16.]],

       ...,

       [[16., 16., 16., ..., 16., 16., 16.]],

       [[16., 16., 16., ..., 16., 16., 16.]],

       [[16., 16., 16., ..., 16., 16., 16.]]])

# With numpy indexing
(Pdb) p arr[:][0]
array([[16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16.,
        16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16.,
        16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16.,
        16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16.,
        16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16.,
        16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16.,
        16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16.,
        16., 16., 16., 16., 16., 16., 16., 16., 16.]])

# With blosc2 indexing
(Pdb) p arr[0]
array([[[16., 16., 16., ..., 16., 16., 16.]],

       [[16., 16., 16., ..., 16., 16., 16.]],

       [[16., 16., 16., ..., 16., 16., 16.]],

       ...,

       [[16., 16., 16., ..., 16., 16., 16.]],

       [[16., 16., 16., ..., 16., 16., 16.]],

       [[16., 16., 16., ..., 16., 16., 16.]]])
@FrancescAlted
Copy link
Member

I have tried out different things, but I cannot reproduce this. With e.g.:

import blosc2
import numpy as np

shape = (50, 10, 60)
na = np.arange(np.prod(shape), dtype=np.int32).reshape(shape)
a = blosc2.asarray(na, chunks=(5, 1, 60), blocks=(1, 1, 60))

b = blosc2.sum(a, axis=1, keepdims=True)
nb = np.sum(na, axis=1, keepdims=True)
print(b.shape, nb.shape)
print("blosc2 idx:", b[0])
print("numpy idx:", nb[0])
print(b[0].shape, nb[0].shape)
assert np.allclose(b[:], nb)

I am getting this output:

(50, 1, 60) (50, 1, 60)
blosc2 idx: [[2700 2710 2720 2730 2740 2750 2760 2770 2780 2790 2800 2810 2820 2830
  2840 2850 2860 2870 2880 2890 2900 2910 2920 2930 2940 2950 2960 2970
  2980 2990 3000 3010 3020 3030 3040 3050 3060 3070 3080 3090 3100 3110
  3120 3130 3140 3150 3160 3170 3180 3190 3200 3210 3220 3230 3240 3250
  3260 3270 3280 3290]]
numpy idx: [[2700 2710 2720 2730 2740 2750 2760 2770 2780 2790 2800 2810 2820 2830
  2840 2850 2860 2870 2880 2890 2900 2910 2920 2930 2940 2950 2960 2970
  2980 2990 3000 3010 3020 3030 3040 3050 3060 3070 3080 3090 3100 3110
  3120 3130 3140 3150 3160 3170 3180 3190 3200 3210 3220 3230 3240 3250
  3260 3270 3280 3290]]
(1, 60) (1, 60)

By any chance, do you remember the shapes that are not working well?

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