コード例 #1
0
ファイル: typemapper.py プロジェクト: dwf/numba
    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, list, dict)):
            return infer_container_type(self, value)
        elif isinstance(value, types.ModuleType):
            return ModuleType(value)
        # elif isinstance(value, (self.ctypes_func_type, self.ctypes_func_type2)):
        elif is_ctypes(value):
            result = from_ctypes_value(value)
            if result.is_function:
                pointer = ctypes.cast(value, ctypes.c_void_p).value
                return PointerFunctionType(value, pointer, result)
            else:
                return result
        elif cffi_support.is_cffi_func(value):
            signature = cffi_support.get_signature(value)
            pointer = cffi_support.get_pointer(value)
            return PointerFunctionType(value, pointer, signature)
        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 numbawrapper.is_numba_wrapper(value):
            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
コード例 #2
0
ファイル: typemapper.py プロジェクト: KanzhiWu/numba
    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
コード例 #3
0
ファイル: infer_call.py プロジェクト: lizecillie/numba
def infer_typefunc(context, call_node, func_type, default_node):
    if (func_type.is_known_value and
            module_type_inference.is_registered(func_type.value)):
        # Try the module type inferers
        result_node = module_type_inference.resolve_call_or_none(
                                    context, call_node, func_type)
        if result_node:
            return result_node

    return default_node
コード例 #4
0
ファイル: infer_call.py プロジェクト: meteogrid/numba
def infer_typefunc(context, call_node, func_type, default_node):
    func_var = call_node.func.variable
    if func_var.is_constant:
        func_type = typesystem.KnownValueType(func_var.constant_value)

    if (func_type.is_known_value and
            module_type_inference.is_registered(func_type.value)):
        # Try the module type inferers
        result_node = module_type_inference.resolve_call_or_none(
                                    context, call_node, func_type)
        if result_node:
            return result_node

    return default_node
コード例 #5
0
def is_registered(value):
    from numba.type_inference import module_type_inference
    return module_type_inference.is_registered(value)
コード例 #6
0
ファイル: constants.py プロジェクト: FrancescAlted/numba
def is_registered(value):
    from numba.type_inference import module_type_inference
    return module_type_inference.is_registered(value)
コード例 #7
0
    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, list, dict)):
            return infer_container_type(self, value)
        elif isinstance(value, types.ModuleType):
            return ModuleType(value)
        # elif isinstance(value, (self.ctypes_func_type, self.ctypes_func_type2)):
        elif is_ctypes(value):
            result = from_ctypes_value(value)
            if result.is_function:
                pointer = ctypes.cast(value, ctypes.c_void_p).value
                return PointerFunctionType(value, pointer, result)
            else:
                return result
        elif cffi_support.is_cffi_func(value):
            signature = cffi_support.get_signature(value)
            pointer = cffi_support.get_pointer(value)
            return PointerFunctionType(value, pointer, signature)
        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 numbawrapper.is_numba_wrapper(value):
            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