SciTools / biggus

:no_entry: [DEPRECATED] Virtual large arrays and lazy evaluation.
http://biggus.readthedocs.io/
GNU Lesser General Public License v3.0
54 stars 27 forks source link

IndexError when computing with 0-dim NumpyArrayAdapter #154

Closed ocefpaf closed 9 years ago

ocefpaf commented 9 years ago

I have the following scenario:

import biggus
import numpy as np

depth_c = np.array(5.)

c = np.empty((1, 36, 1, 1))
s = np.empty((1, 36, 1, 1))
eta = np.empty((855, 1, 82, 130))
depth = np.empty((1, 1, 82, 130))

I convert all those arrays to NumpyArrayAdapter and then perform some computations with them:

c, s, eta, depth, depth_c = map(biggus.NumpyArrayAdapter, (c, s, eta, depth, depth_c))
S = (depth_c * s) + ((depth - depth_c) * c)
z = eta * (S / depth + 1) + S

z.shape
(855, 36, 82, 130)

z[0, :, 30, 40]
IndexError

That should be a valid slice. If I do not make the 0-dim array a NumpyArrayAdapter things work as expected:

c, s, eta, depth = map(biggus.NumpyArrayAdapter, (c, s, eta, depth))
S = (depth_c * s) + ((depth - depth_c) * c)
z = eta * (S / depth + 1) + S

z.shape
(855, 36, 82, 130)

z[0, :, 30, 40]
<_Elementwise shape=(36) dtype=dtype('float64')>

PS: Sorry I could not make this simpler. I tried but simple versions of this actually work just fine!

ocefpaf commented 9 years ago

@pelson Also, if I do not make that 0-dim array a NumpyArrayAdapter, this problem goes away too.

pelson commented 9 years ago

Ouch. This one is a bit more serious than #152 - it is a genuine bug. Simplest code to reproduce so far:

import biggus
import numpy as np

s = biggus.NumpyArrayAdapter(np.empty((1, 36, 1, 1)))
eta = biggus.NumpyArrayAdapter(np.empty((855, 1, 82, 130)))

z = eta * s

print z.shape
print eta.shape, s.shape

print z[:, :, 30]
pelson commented 9 years ago

Or just:

import biggus
import numpy as np

s = biggus.NumpyArrayAdapter(np.empty((1, 36, 1, 1)))
a = biggus.BroadcastArray(s, {0: 855, 2: 82, 3: 130})

print a[:, :, 30]

I have a nice little test now. Time to figure out a fix :wink: