Пример #1
0
    def __init__(self, typingctx, targetctx, library, args, return_type, flags,
                 locals):
        # Make sure the environment is reloaded
        config.reload_config()
        typingctx.refresh()
        targetctx.refresh()

        self.typingctx = typingctx
        self.targetctx = _make_subtarget(targetctx, flags)
        self.library = library
        self.args = args
        self.return_type = return_type
        self.flags = flags
        self.locals = locals

        # Results of various steps of the compilation pipeline
        self.bc = None
        self.func_id = None
        self.func_ir = None
        self.func_ir_original = None  # used for fallback
        self.lifted = None
        self.lifted_from = None
        self.typemap = None
        self.calltypes = None
        self.type_annotation = None

        self.status = _CompileStatus(
            can_fallback=self.flags.enable_pyobject,
            can_giveup=config.COMPATIBILITY_MODE
        )
Пример #2
0
    def __init__(self, typingctx, targetctx, library, args, return_type, flags,
                 locals):
        # Make sure the environment is reloaded
        config.reload_config()

        self.typingctx = typingctx

        subtargetoptions = {}
        if flags.boundcheck:
            subtargetoptions['enable_boundcheck'] = True
        if flags.nrt:
            subtargetoptions['enable_nrt'] = True

        self.targetctx = targetctx.subtarget(**subtargetoptions)
        self.library = library
        self.args = args
        self.return_type = return_type
        self.flags = flags
        self.locals = locals
        self.bc = None
        self.func_attr = None
        self.lifted = None

        self.status = _CompileStatus(can_fallback=self.flags.enable_pyobject,
                                     can_giveup=config.COMPATIBILITY_MODE)
Пример #3
0
    def __init__(self, typingctx, targetctx, library, args, return_type, flags,
                 locals):
        # Make sure the environment is reloaded
        config.reload_config()
        typingctx.refresh()
        targetctx.refresh()

        self.typingctx = typingctx
        self.targetctx = _make_subtarget(targetctx, flags)
        self.library = library
        self.args = args
        self.return_type = return_type
        self.flags = flags
        self.locals = locals

        # Results of various steps of the compilation pipeline
        self.bc = None
        self.func_id = None
        self.func_ir = None
        self.func_ir_original = None  # used for fallback
        self.lifted = None
        self.lifted_from = None
        self.typemap = None
        self.calltypes = None
        self.type_annotation = None

        self.status = _CompileStatus(
            can_fallback=self.flags.enable_pyobject,
            can_giveup=config.COMPATIBILITY_MODE
        )
Пример #4
0
    def __init__(self, typingctx, targetctx, library, args, return_type, flags,
                 locals):
        # Make sure the environment is reloaded
        config.reload_config()

        self.typingctx = typingctx

        subtargetoptions = {}
        if flags.boundcheck:
            subtargetoptions['enable_boundcheck'] = True
        if flags.nrt:
            subtargetoptions['enable_nrt'] = True
        error_model = callconv.error_models[flags.error_model](
            targetctx.call_conv)
        subtargetoptions['error_model'] = error_model

        self.targetctx = targetctx.subtarget(**subtargetoptions)
        self.library = library
        self.args = args
        self.return_type = return_type
        self.flags = flags
        self.locals = locals
        # Results of various steps of the compilation pipeline
        self.bc = None
        self.func_attr = None
        self.lifted = None
        self.typemap = None
        self.calltypes = None

        self.status = _CompileStatus(can_fallback=self.flags.enable_pyobject,
                                     can_giveup=config.COMPATIBILITY_MODE)
Пример #5
0
def numba_env_vars(**env_vars):
    """Context manager that updates the **numba** environment variables
    with the keyword dictionary ``env_vars``. Any keyword that starts
    with ``NUMBA_`` will override the corresponding key in the system
    environment dictionary. It resets the environment variables to its
    original values upon exit.

    :param env_vars: Keyword dictionary.
    :return:
    """
    os_environ = os.environ
    old_env_vars = {}
    new_env_vars = {}

    for key, value in env_vars.items():
        if key.startswith('NUMBA_'):
            new_env_vars[key] = str(value)
            env_var = os_environ.get(key, None)
            if env_var is not None:
                old_env_vars[key] = env_var

    os_environ.update(new_env_vars)
    reload_config()
    #
    yield
    #
    for key in new_env_vars.keys():
        del os_environ[key]
    os_environ.update(old_env_vars)
    reload_config()
Пример #6
0
    def __init__(self, typingctx, targetctx, library, args, return_type, flags,
                 locals):
        # Make sure the environment is reloaded
        config.reload_config()

        self.typingctx = typingctx

        subtargetoptions = {}
        if flags.boundcheck:
            subtargetoptions['enable_boundcheck'] = True
        if flags.nrt:
            subtargetoptions['enable_nrt'] = True
        error_model = callconv.error_models[flags.error_model](targetctx.call_conv)
        subtargetoptions['error_model'] = error_model

        self.targetctx = targetctx.subtarget(**subtargetoptions)
        self.library = library
        self.args = args
        self.return_type = return_type
        self.flags = flags
        self.locals = locals
        self.bc = None
        self.func_attr = None
        self.lifted = None

        self.status = _CompileStatus(
            can_fallback=self.flags.enable_pyobject,
            can_giveup=config.COMPATIBILITY_MODE
        )
Пример #7
0
    def __init__(self, typingctx, targetctx, library, args, return_type, flags,
                 locals):
        # Make sure the environment is reloaded
        config.reload_config()
        typingctx.refresh()
        targetctx.refresh()

        self.typingctx = typingctx
        self.targetctx = _make_subtarget(targetctx, flags)
        self.library = library
        self.args = args
        self.return_type = return_type
        self.flags = flags
        self.locals = locals

        # Results of various steps of the compilation pipeline
        self.bc = None
        self.func_id = None
        self.func_ir = None
        self.lifted = None
        self.lifted_from = None
        self.typemap = None
        self.calltypes = None
        self.type_annotation = None
        self.metadata = {} # holds arbitrary inter-pipeline stage meta data

        # parfor diagnostics info, add to metadata
        self.parfor_diagnostics = ParforDiagnostics()
        self.metadata['parfor_diagnostics'] = self.parfor_diagnostics

        self.status = _CompileStatus(
            can_fallback=self.flags.enable_pyobject,
            can_giveup=config.COMPATIBILITY_MODE
        )
 def test_num_threads_variable(self):
     """
     Tests the NUMBA_NUM_THREADS env variable behaves as expected.
     """
     key = 'NUMBA_NUM_THREADS'
     current = str(getattr(env, key, config.NUMBA_DEFAULT_NUM_THREADS))
     threads = "3154"
     env[key] = threads
     config.reload_config()
     try:
         self.assertEqual(threads, str(get_thread_count()))
         self.assertEqual(threads, str(config.NUMBA_NUM_THREADS))
     finally:
         # reset the env variable/set to default
         env[key] = current
         config.reload_config()
Пример #9
0
 def test_num_threads_variable(self):
     """
     Tests the NUMBA_NUM_THREADS env variable behaves as expected.
     """
     key = 'NUMBA_NUM_THREADS'
     current = str(getattr(env, key, config.NUMBA_DEFAULT_NUM_THREADS))
     threads = "3154"
     env[key] = threads
     config.reload_config()
     try:
         self.assertEqual(threads, str(get_thread_count()))
         self.assertEqual(threads, str(config.NUMBA_NUM_THREADS))
     finally:
         # reset the env variable/set to default
         env[key] = current
         config.reload_config()
Пример #10
0
def override_env_config(name, value):
    """
    Return a context manager that temporarily sets an Numba config environment
    *name* to *value*.
    """
    old = os.environ.get(name)
    os.environ[name] = value
    config.reload_config()

    try:
        yield
    finally:
        if old is None:
            # If it wasn't set originally, delete the environ var
            del os.environ[name]
        else:
            # Otherwise, restore to the old value
            os.environ[name] = old
        # Always reload config
        config.reload_config()
Пример #11
0
def override_env_config(name, value):
    """
    Return a context manager that temporarily sets an Numba config environment
    *name* to *value*.
    """
    old = os.environ.get(name)
    os.environ[name] = value
    config.reload_config()

    try:
        yield
    finally:
        if old is None:
            # If it wasn't set originally, delete the environ var
            del os.environ[name]
        else:
            # Otherwise, restore to the old value
            os.environ[name] = old
        # Always reload config
        config.reload_config()