Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues using from within iPython #34

Closed
pbutler opened this issue Sep 3, 2012 · 2 comments
Closed

Issues using from within iPython #34

pbutler opened this issue Sep 3, 2012 · 2 comments

Comments

@pbutler
Copy link

pbutler commented Sep 3, 2012

I can run the tests, I can also run the same code from the command line but trying to copy and paste the code directly into iPython fails as follows:

Python 2.7.2 (default, Jun 20 2012, 16:23:33)
Type "copyright", "credits" or "license" for more information.

IPython 0.14.dev -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import numpy as np

In [2]: from numba import double

In [3]: from numba.decorators import jit

In [4]:

In [4]: @jit(arg_types=[double[:,:]], ret_type = double)
   ...: def sum2d(arr):
   ...:         M, N = arr.shape
   ...:         result = 0.0
   ...:         for i in range(M):
   ...:                 for j in range(N):
   ...:                         result += arr[i,j]
   ...:                 return result
   ...:
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-4-e1f9177b3ba9> in <module>()
----> 1 @jit(arg_types=[double[:,:]], ret_type = double)
      2 def sum2d(arr):
      3         M, N = arr.shape
      4         result = 0.0
      5         for i in range(M):

/Library/Python/2.7/site-packages/numba/decorators.pyc in _jit(func)
    108                            "garbage collected!" % (func,))
    109         t = bytecode_translate.Translate(func, *args, **kws)
--> 110         t.translate()
    111         __tr_map__[func] = t
    112         return t.get_ctypes_func(llvm)

/Library/Python/2.7/site-packages/numba/translate.pyc in translate(self)
    940                     self.build_phi_nodes(self.crnt_block)
    941             if not is_dead_code:
--> 942                 getattr(self, 'op_'+name)(i, op, arg)
    943
    944         # Perform code optimization

/Library/Python/2.7/site-packages/numba/translate.pyc in op_STORE_FAST(self, i, op, arg)
   1325         newval = self.stack.pop(-1)
   1326         if isinstance(newval.val, DelayedObj):
-> 1327             self._generate_for_loop(i, op, arg, newval)
   1328         else:
   1329             if self.has_pending_phi(i, arg):

/Library/Python/2.7/site-packages/numba/translate.pyc in _generate_for_loop(self, i, op, arg, delayer)
   1252         xrange, or arange).'''
   1253         arg_val = self._locals[arg]
-> 1254         false_jump_target = self.pending_blocks.pop(i - 3)
   1255         crnt_block_data = self._revisit_block(i - 3)
   1256         inc_variable = delayer.val.get_inc()

KeyError: 34

System is OSX 10.8, running the repo versions of llvmpy, numba, and Meta.

@jriehl
Copy link
Contributor

jriehl commented Sep 5, 2012

The example should work if you lower the indentation level of return result one level.

OTOH, the example as typed is an interesting bug because it illustrates a shortcoming in my fix for issue #25. The premature return statement is causing the nominal loop exit target to be (correctly) identified as dead code, and eliminated. The loop transformation code doesn't account for this possibility, and crashes.

jriehl pushed a commit that referenced this issue Sep 6, 2012
@jriehl
Copy link
Contributor

jriehl commented Sep 6, 2012

Fixed, per unit test added to numba.tests.test_sum.TestSum2d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants