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

Fix objectmode is/is not #857

Merged
merged 2 commits into from Nov 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions numba/pythonapi.py
Expand Up @@ -562,12 +562,21 @@ def object_richcompare(self, lhs, rhs, opstr):
of the opid.
"""
ops = ['<', '<=', '==', '!=', '>', '>=']
opid = ops.index(opstr)
assert 0 <= opid < len(ops)
fnty = Type.function(self.pyobj, [self.pyobj, self.pyobj, Type.int()])
fn = self._get_function(fnty, name="PyObject_RichCompare")
lopid = self.context.get_constant(types.int32, opid)
return self.builder.call(fn, (lhs, rhs, lopid))
if opstr in ops:
opid = ops.index(opstr)
fnty = Type.function(self.pyobj, [self.pyobj, self.pyobj, Type.int()])
fn = self._get_function(fnty, name="PyObject_RichCompare")
lopid = self.context.get_constant(types.int32, opid)
return self.builder.call(fn, (lhs, rhs, lopid))
elif opstr == 'is':
bitflag = self.builder.icmp(lc.ICMP_EQ, lhs, rhs)
return self.from_native_value(bitflag, types.boolean)
elif opstr == 'is not':
bitflag = self.builder.icmp(lc.ICMP_NE, lhs, rhs)
return self.from_native_value(bitflag, types.boolean)
else:
raise NotImplementedError("Unknown operator {op!r}".format(
op=opstr))

def iter_next(self, iterobj):
fnty = Type.function(self.pyobj, [self.pyobj])
Expand Down
12 changes: 11 additions & 1 deletion numba/tests/test_optional.py
@@ -1,7 +1,7 @@
from __future__ import print_function, absolute_import
import numpy
import numba.unittest_support as unittest
from numba.compiler import compile_isolated
from numba.compiler import compile_isolated, Flags
from numba import types, typeof, njit
from numba.pythonapi import NativeError
from numba import lowering
Expand Down Expand Up @@ -75,6 +75,16 @@ def test_is_this_a_none(self):
for v in [-1, 0, 1, 2]:
self.assertEqual(pyfunc(v), cfunc(v))

def test_is_this_a_none_objmode(self):
pyfunc = is_this_a_none
flags = Flags()
flags.set('force_pyobject')
cres = compile_isolated(pyfunc, [types.intp], flags=flags)
cfunc = cres.entry_point
self.assertTrue(cres.objectmode)
for v in [-1, 0, 1, 2]:
self.assertEqual(pyfunc(v), cfunc(v))

def test_a_is_b_intp(self):
pyfunc = a_is_b
with self.assertRaises(lowering.LoweringError):
Expand Down