python-blosc2
python-blosc2 copied to clipboard
Wrong index with 3dim array when 1 dim size is 1
(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.]]])
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?