def from_python(self, value): if isinstance(value, np.ndarray): dtype = map_dtype(value.dtype) return minitypes.ArrayType(dtype, value.ndim, is_c_contig=value.flags['C_CONTIGUOUS'], is_f_contig=value.flags['F_CONTIGUOUS']) elif isinstance(value, tuple): return tuple_ elif isinstance(value, types.ModuleType): return ModuleType(value) # elif isinstance(value, (self.ctypes_func_type, self.ctypes_func_type2)): elif hasattr(value, 'errcheck'): # ugh, ctypes if value.argtypes is None: return object_ restype = convert_from_ctypes(value.restype) argtypes = map(convert_from_ctypes, value.argtypes) return CTypesFunctionType(value, restype, argtypes) elif isinstance(value, minitypes.Type): return CastType(dst_type=value) elif hasattr(type(value), '__numba_ext_type'): return type(value).__numba_ext_type else: return super(NumbaTypeMapper, self).from_python(value)
def from_python(self, value): from numba.type_inference import module_type_inference if isinstance(value, np.ndarray): dtype = map_dtype(value.dtype) return minitypes.ArrayType(dtype, value.ndim) #, #is_c_contig=value.flags['C_CONTIGUOUS'], #is_f_contig=value.flags['F_CONTIGUOUS']) elif isinstance(value, np.dtype): return numba.typesystem.from_numpy_dtype(value) elif is_dtype_constructor(value): return numba.typesystem.from_numpy_dtype(np.dtype(value)) elif isinstance(value, tuple): return tuple_ elif isinstance(value, types.ModuleType): return ModuleType(value) # elif isinstance(value, (self.ctypes_func_type, self.ctypes_func_type2)): elif hasattr(value, 'errcheck'): # ugh, ctypes if value.argtypes is None: return object_ restype = convert_from_ctypes(value.restype) argtypes = map(convert_from_ctypes, value.argtypes) return CTypesFunctionType(value, restype, argtypes) elif isinstance(value, minitypes.Type): return CastType(dst_type=value) elif hasattr(type(value), '__numba_ext_type'): return getattr(type(value), '__numba_ext_type') elif value is numba.NULL: return null_type elif isinstance(value, numbawrapper.NumbaCompiledWrapper): return JitType(value) elif isinstance(value, numbawrapper.NumbaSpecializingWrapper): return AutojitType(value) elif hasattr(value, 'from_address') and hasattr(value, 'in_dll'): # Try to detect ctypes pointers, or default to minivect try: ctypes.cast(value, ctypes.c_void_p) except ctypes.ArgumentError: pass else: pass #type = convert_from_ctypes(value) #value = ctypes.cast(value, ctypes.c_void_p).value #return CTypesPointerType(type, valuee result_type = super(NumbaTypeMapper, self).from_python(value) if result_type == object_ and module_type_inference.is_registered(value): result = module_type_inference.module_attribute_type(value) if result is not None: result_type = result else: result_type = KnownValueType(value) return result_type
def from_python(self, value): if isinstance(value, np.ndarray): dtype = map_dtype(value.dtype) return minitypes.ArrayType(dtype, value.ndim, is_c_contig=value.flags['C_CONTIGUOUS'], is_f_contig=value.flags['F_CONTIGUOUS']) elif isinstance(value, tuple): return tuple_ elif isinstance(value, types.ModuleType): return ModuleType(value) # elif isinstance(value, (self.ctypes_func_type, self.ctypes_func_type2)): elif hasattr(value, 'errcheck'): # ugh, ctypes if value.argtypes is None: return object_ restype = convert_from_ctypes(value.restype) argtypes = map(convert_from_ctypes, value.argtypes) return CTypesFunctionType(value, restype, argtypes) elif isinstance(value, minitypes.Type): return CastType(dst_type=value) elif hasattr(type(value), '__numba_ext_type'): return type(value).__numba_ext_type elif value is numba.NULL: return null_type elif isinstance(value, numba.decorators.NumbaFunction): if value.signature is None: # autojit return AutojitType(value) else: return JitType(value) elif hasattr(value, 'from_address') and hasattr(value, 'in_dll'): # Try to detect ctypes pointers, or default to minivect try: ctypes.cast(value, ctypes.c_void_p) except ctypes.ArgumentError: pass else: pass #type = convert_from_ctypes(value) #value = ctypes.cast(value, ctypes.c_void_p).value #return CTypesPointerType(type, value) return super(NumbaTypeMapper, self).from_python(value)