Created
April 27, 2013 13:41
-
-
Save Jorge-C/5473175 to your computer and use it in GitHub Desktop.
weave.blitz assignment bug.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.weave import blitz | |
import numpy.testing as npt | |
def test_blitz_bug(): | |
"""Assignment to arr[i:] fails inside blitz expression.""" | |
N = 4 | |
expr_buggy = 'arr_blitz_buggy[{0}:] = arr[{0}:]' | |
expr_not_buggy = 'arr_blitz_not_buggy[{0}:{1}] = arr[{0}:]' | |
np.random.seed(7) | |
arr = np.random.randn(N) | |
sh = arr.shape[0] | |
for lim in [0, 1, 2]: | |
arr_blitz_buggy, arr_blitz_not_buggy, arr_np = np.zeros(N), np.zeros(N), np.zeros(N) | |
blitz(expr_buggy.format(lim)) | |
blitz(expr_not_buggy.format(lim, 'sh')) | |
arr_np[lim:] = arr[lim:] | |
npt.assert_allclose(arr_blitz_buggy, arr_np) | |
npt.assert_allclose(arr_blitz_not_buggy, arr_np) | |
if __name__ == '__main__': | |
test_blitz_bug() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment