def test_blitz_bug(): # Assignment to arr[i:] used to fail inside blitz expressions. with TempdirBlitz(): N = 4 expr_buggy = 'arr_blitz_buggy[{0}:] = arr[{0}:]' expr_not_buggy = 'arr_blitz_not_buggy[{0}:{1}] = arr[{0}:]' random.seed(7) arr = random.randn(N) sh = arr.shape[0] for lim in [0, 1, 2]: arr_blitz_buggy = zeros(N) arr_blitz_not_buggy = zeros(N) arr_np = zeros(N) blitz(expr_buggy.format(lim)) blitz(expr_not_buggy.format(lim, 'sh')) arr_np[lim:] = arr[lim:] assert_allclose(arr_blitz_buggy, arr_np) assert_allclose(arr_blitz_not_buggy, arr_np)
import numpy import weave a = numpy.zeros((10, 6)) expr = "a[1:3, 2:-1] = 1" weave.blitz(expr) print a