Skip to content

Instantly share code, notes, and snippets.

@timo
Created May 5, 2012 14:00
Show Gist options
  • Save timo/2602685 to your computer and use it in GitHub Desktop.
Save timo/2602685 to your computer and use it in GitHub Desktop.
not sure what's wrong
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
self = <pypy.module.micronumpy.test.test_compile.TestRunner object at 0x50c04d0>
def test_slice(self):
interp = self.run("""
a = [1,2,3,4]
b = a -> :
b -> 3
> """)
assert interp.results[0].value == 4
def test_slice_step(self):
pypy/module/micronumpy/test/test_compile.py:182:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.micronumpy.test.test_compile.TestRunner object at 0x50c04d0>
code = '\n a = [1,2,3,4]\n b = a -> :\n b -> 3\n '
def run(self, code):
interp = numpy_compile(code)
space = FakeSpace()
> interp.run(space)
pypy/module/micronumpy/test/test_compile.py:91:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.micronumpy.compile.InterpreterState object at 0x511dd50>
space = <pypy.module.micronumpy.compile.FakeSpace object at 0x50c0450>
def run(self, space):
self.space = space
for stmt in self.code.statements:
> stmt.execute(self)
pypy/module/micronumpy/compile.py:237:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = 'b' = (v(a) -> slice(0,-1,1))
interp = <pypy.module.micronumpy.compile.InterpreterState object at 0x511dd50>
def execute(self, interp):
> interp.variables[self.name] = self.expr.execute(interp)
pypy/module/micronumpy/compile.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = (v(a) -> slice(0,-1,1))
interp = <pypy.module.micronumpy.compile.InterpreterState object at 0x511dd50>
def execute(self, interp):
w_lhs = self.lhs.execute(interp)
if isinstance(self.rhs, SliceConstant):
w_rhs = self.rhs.wrap(interp.space)
else:
w_rhs = self.rhs.execute(interp)
if not isinstance(w_lhs, BaseArray):
# scalar
dtype = get_dtype_cache(interp.space).w_float64dtype
w_lhs = scalar_w(interp.space, dtype, w_lhs)
assert isinstance(w_lhs, BaseArray)
if self.name == '+':
w_res = w_lhs.descr_add(interp.space, w_rhs)
elif self.name == '*':
w_res = w_lhs.descr_mul(interp.space, w_rhs)
elif self.name == '-':
w_res = w_lhs.descr_sub(interp.space, w_rhs)
elif self.name == '->':
assert not isinstance(w_rhs, Scalar)
if isinstance(w_rhs, FloatObject):
w_rhs = IntObject(int(w_rhs.floatval))
assert isinstance(w_lhs, BaseArray)
> w_res = w_lhs.descr_getitem(interp.space, w_rhs)
pypy/module/micronumpy/compile.py:321:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.micronumpy.interp_numarray.W_NDimArray object at 0x5a37d90>
space = <pypy.module.micronumpy.compile.FakeSpace object at 0x50c0450>
w_idx = <pypy.module.micronumpy.compile.SliceObject object at 0x4be6810>
def descr_getitem(self, space, w_idx):
if (isinstance(w_idx, BaseArray) and w_idx.shape == self.shape and
w_idx.find_dtype().is_bool_type()):
return self.getitem_filter(space, w_idx)
> if self._single_item_result(space, w_idx):
pypy/module/micronumpy/interp_numarray.py:453:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.micronumpy.interp_numarray.W_NDimArray object at 0x5a37d90>
space = <pypy.module.micronumpy.compile.FakeSpace object at 0x50c0450>
w_idx = <pypy.module.micronumpy.compile.SliceObject object at 0x4be6810>
@jit.unroll_safe
def _single_item_result(self, space, w_idx):
""" The result of getitem/setitem is a single item if w_idx
is a list of scalars that match the size of shape
"""
if space.isinstance_w(w_idx, space.w_str):
return False
shape_len = len(self.shape)
if space.isinstance_w(w_idx, space.w_tuple):
for w_item in space.fixedview(w_idx):
if (space.isinstance_w(w_item, space.w_slice) or
space.is_w(w_item, space.w_None)):
return False
elif space.is_w(w_idx, space.w_None):
return False
if shape_len == 0:
raise OperationError(space.w_IndexError, space.wrap(
"0-d arrays can't be indexed"))
if shape_len == 1:
if space.isinstance_w(w_idx, space.w_int):
return True
try:
> value = space.int_w(space.index(w_idx))
pypy/module/micronumpy/interp_numarray.py:355:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.micronumpy.compile.FakeSpace object at 0x50c0450>
w_obj = <pypy.module.micronumpy.compile.SliceObject object at 0x4be6810>
def index(self, w_obj):
> return self.wrap(self.int_w(w_obj))
pypy/module/micronumpy/compile.py:135:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.micronumpy.compile.FakeSpace object at 0x50c0450>
w_obj = <pypy.module.micronumpy.compile.SliceObject object at 0x4be6810>
def int_w(self, w_obj):
if isinstance(w_obj, IntObject):
return w_obj.intval
elif isinstance(w_obj, FloatObject):
return int(w_obj.floatval)
elif isinstance(w_obj, SliceObject):
> raise OperationError(self.w_TypeError, self.wrap("slice."))
pypy/module/micronumpy/compile.py:131:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = OperationError(), w_type = None
w_value = <pypy.module.micronumpy.compile.StringObject object at 0x4be6910>, tb = None
def __init__(self, w_type, w_value, tb=None):
if not we_are_translated() and w_type is None:
from pypy.tool.error import FlowingError
> raise FlowingError(w_value)
E FlowingError: <pypy.module.micronumpy.compile.StringObject object at 0x4be6910>
pypy/interpreter/error.py:26: FlowingError
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /home/timo/coding/pypy/pypy/interpreter/error.py(26)__init__()
-> raise FlowingError(w_value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment