def test_equality(self): self.assertEqual(types.int32, types.int32) self.assertEqual(types.uint32, types.uint32) self.assertEqual(types.complex64, types.complex64) self.assertEqual(types.float32, types.float32) # Different signedness self.assertNotEqual(types.int32, types.uint32) # Different width self.assertNotEqual(types.int64, types.int32) self.assertNotEqual(types.float64, types.float32) self.assertNotEqual(types.complex64, types.complex128) # Different domain self.assertNotEqual(types.int64, types.float64) self.assertNotEqual(types.uint64, types.float64) self.assertNotEqual(types.complex64, types.float64) # Same arguments but different return types get_pointer = None sig_a = typing.signature(types.intp, types.intp) sig_b = typing.signature(types.voidptr, types.intp) a = types.ExternalFunctionPointer(sig=sig_a, get_pointer=get_pointer) b = types.ExternalFunctionPointer(sig=sig_b, get_pointer=get_pointer) self.assertNotEqual(a, b) # Different call convention a = types.ExternalFunctionPointer(sig=sig_a, get_pointer=get_pointer) b = types.ExternalFunctionPointer(sig=sig_a, get_pointer=get_pointer, cconv='stdcall') self.assertNotEqual(a, b) # Different get_pointer a = types.ExternalFunctionPointer(sig=sig_a, get_pointer=get_pointer) b = types.ExternalFunctionPointer(sig=sig_a, get_pointer=object()) self.assertNotEqual(a, b) # Different template classes bearing the same name class DummyTemplate(object): key = "foo" a = types.BoundFunction(DummyTemplate, types.int32) class DummyTemplate(object): key = "bar" b = types.BoundFunction(DummyTemplate, types.int32) self.assertNotEqual(a, b) # Different dtypes self.assertNotEqual(types.DType(types.int32), types.DType(types.int64)) # CPointer with same addrspace self.assertEqual(types.CPointer(types.float32), types.CPointer(types.float32)) # CPointer with different addrspace self.assertNotEqual(types.CPointer(types.float32, 0), types.CPointer(types.float32, 1))
def generic_resolve(self, instance, attr): if attr in instance.struct: # It's a struct field => the type is well-known return instance.struct[attr] elif attr in instance.jitmethods: # It's a jitted method => typeinfer it meth = instance.jitmethods[attr] disp_type = types.Dispatcher(meth) class MethodTemplate(templates.AbstractTemplate): key = (self.key, attr) def generic(self, args, kws): args = (instance, ) + tuple(args) sig = disp_type.get_call_type(self.context, args, kws) return sig.as_method() return types.BoundFunction(MethodTemplate, instance) elif attr in instance.jitprops: # It's a jitted property => typeinfer its getter impdct = instance.jitprops[attr] getter = impdct['get'] disp_type = types.Dispatcher(getter) sig = disp_type.get_call_type(self.context, (instance, ), {}) return sig.return_type
def _resolve(self, typ, attr): if self._attr != attr: return None if isinstance(typ, types.TypeRef): assert typ == self.key else: assert isinstance(typ, self.key) class MethodTemplate(AbstractTemplate): key = (self.key, attr) _inline = self._inline _overload_func = staticmethod(self._overload_func) _inline_overloads = self._inline_overloads prefer_literal = self.prefer_literal def generic(_, args, kws): args = (typ,) + tuple(args) fnty = self._get_function_type(self.context, typ) sig = self._get_signature(self.context, fnty, args, kws) sig = sig.replace(pysig=utils.pysignature(self._overload_func)) for template in fnty.templates: self._inline_overloads.update(template._inline_overloads) if sig is not None: return sig.as_method() return types.BoundFunction(MethodTemplate, typ)
def generic_resolve(self, instance, attr): if attr in instance.struct: # It's a struct field => the type is well-known return instance.struct[attr] elif attr in instance.jit_methods: # It's a jitted method => typeinfer it meth = instance.jit_methods[attr] disp_type = types.Dispatcher(meth) class MethodTemplate(templates.AbstractTemplate): key = (self.key, attr) def generic(self, args, kws): args = (instance, ) + tuple(args) sig = disp_type.get_call_type(self.context, args, kws) return sig.as_method() return types.BoundFunction(MethodTemplate, instance) elif attr in instance.jit_static_methods: # It's a jitted method => typeinfer it meth = instance.jit_static_methods[attr] disp_type = types.Dispatcher(meth) class StaticMethodTemplate(templates.AbstractTemplate): key = (self.key, attr) def generic(self, args, kws): # Don't add instance as the first argument for a static # method. sig = disp_type.get_call_type(self.context, args, kws) # sig itself does not include ClassInstanceType as it's # first argument, so instead of calling sig.as_method() # we insert the recvr. This is equivalent to # sig.replace(args=(instance,) + sig.args).as_method(). return sig.replace(recvr=instance) return types.BoundFunction(StaticMethodTemplate, instance) elif attr in instance.jit_props: # It's a jitted property => typeinfer its getter impdct = instance.jit_props[attr] getter = impdct['get'] disp_type = types.Dispatcher(getter) sig = disp_type.get_call_type(self.context, (instance, ), {}) return sig.return_type
def attribute_resolver(self, ty): class MethodTemplate(AbstractTemplate): key = template_key def generic(_, args, kws): sig = method_resolver(self, ty, args, kws) if sig is not None and sig.recvr is None: sig = sig.replace(recvr=ty) return sig return types.BoundFunction(MethodTemplate, ty)
def _resolve(self, typ, attr): if self._attr != attr: return None assert isinstance(typ, self.key) class MethodTemplate(AbstractTemplate): key = self.key # this line is changed for __call__ _inline = self._inline _overload_func = staticmethod(self._overload_func) _inline_overloads = self._inline_overloads def generic(_, args, kws): args = (typ, ) + tuple(args) fnty = self._get_function_type(self.context, typ) sig = self._get_signature(self.context, fnty, args, kws) sig = sig.replace(pysig=numba.extending.utils.pysignature( self._overload_func)) for template in fnty.templates: self._inline_overloads.update(template._inline_overloads) if sig is not None: return sig.as_method() return types.BoundFunction(MethodTemplate, typ)
def resolve_sync(self, mod): return types.BoundFunction(Cuda_grid_group_sync, grid_group)
def resolve_from_buffer(self, ffi): return types.BoundFunction(FFI_from_buffer, types.ffi)
def array_attribute_attachment(self, ary): return types.BoundFunction(temp_class, ary)