How to use the numexpr.utils.CacheDict function in numexpr

To help you get started, weā€™ve selected a few numexpr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OSGeo / grass-addons / grass7 / raster / r.green / r.green.hydro / r.green.hydro.financial / r.green.hydro.financial.py View on Github external
def get_cnames(expr,
               _names_cache=ne.utils.CacheDict(256) if ne else ne,
               _numexpr_cache=ne.utils.CacheDict(256) if ne else ne, 
               **kwargs):
    if not isinstance(expr, (str, unicode)):
        raise ValueError("must specify expression as a string")
    # Get the names for this expression
    context = ne.necompiler.getContext(kwargs, frame_depth=1)
    expr_key = (expr, tuple(sorted(context.items())))
    if expr_key not in _names_cache:
        _names_cache[expr_key] = ne.necompiler.getExprNames(expr.strip(),
                                                            context)
    names, ex_uses_vml = _names_cache[expr_key]
    return names
github pydata / numexpr / numexpr / necompiler.py View on Github external
except KeyError:
                a = global_dict[name]
            arguments.append(numpy.asarray(a))
    finally:
        # If we generated local_dict via an explicit reference to f_locals,
        # clear the dict to prevent creating extra ref counts in the caller's scope
        # See https://github.com/pydata/numexpr/issues/310
        if clear_local_dict:
            local_dict.clear()

    return arguments


# Dictionaries for caching variable names and compiled expressions
_names_cache = CacheDict(256)
_numexpr_cache = CacheDict(256)
_numexpr_last = {}

evaluate_lock = threading.Lock()

def evaluate(ex, local_dict=None, global_dict=None,
             out=None, order='K', casting='safe', **kwargs):
    """Evaluate a simple array expression element-wise, using the new iterator.

    ex is a string forming an expression, like "2*a+3*b". The values for "a"
    and "b" will by default be taken from the calling function's frame
    (through use of sys._getframe()). Alternatively, they can be specifed
    using the 'local_dict' or 'global_dict' arguments.

    Parameters
    ----------
github pydata / numexpr / numexpr / necompiler.py View on Github external
a = local_dict[name]
            except KeyError:
                a = global_dict[name]
            arguments.append(numpy.asarray(a))
    finally:
        # If we generated local_dict via an explicit reference to f_locals,
        # clear the dict to prevent creating extra ref counts in the caller's scope
        # See https://github.com/pydata/numexpr/issues/310
        if clear_local_dict:
            local_dict.clear()

    return arguments


# Dictionaries for caching variable names and compiled expressions
_names_cache = CacheDict(256)
_numexpr_cache = CacheDict(256)
_numexpr_last = {}

evaluate_lock = threading.Lock()

def evaluate(ex, local_dict=None, global_dict=None,
             out=None, order='K', casting='safe', **kwargs):
    """Evaluate a simple array expression element-wise, using the new iterator.

    ex is a string forming an expression, like "2*a+3*b". The values for "a"
    and "b" will by default be taken from the calling function's frame
    (through use of sys._getframe()). Alternatively, they can be specifed
    using the 'local_dict' or 'global_dict' arguments.

    Parameters
    ----------
github OSGeo / grass-addons / grass7 / raster / r.green / r.green.hydro / r.green.hydro.financial / r.green.hydro.financial.py View on Github external
def get_cnames(expr,
               _names_cache=ne.utils.CacheDict(256) if ne else ne,
               _numexpr_cache=ne.utils.CacheDict(256) if ne else ne, 
               **kwargs):
    if not isinstance(expr, (str, unicode)):
        raise ValueError("must specify expression as a string")
    # Get the names for this expression
    context = ne.necompiler.getContext(kwargs, frame_depth=1)
    expr_key = (expr, tuple(sorted(context.items())))
    if expr_key not in _names_cache:
        _names_cache[expr_key] = ne.necompiler.getExprNames(expr.strip(),
                                                            context)
    names, ex_uses_vml = _names_cache[expr_key]
    return names
github pydata / numexpr / numexpr / utils.py View on Github external
def __init__(self, maxentries):
        self.maxentries = maxentries
        super(CacheDict, self).__init__(self)
github OSGeo / grass-addons / grass7 / raster / r.green / r.green.hydro / r.green.hydro.financial / r.green.hydro.financial.py View on Github external
def get_cnames(expr,
               _names_cache=ne.utils.CacheDict(256) if ne else ne,
               _numexpr_cache=ne.utils.CacheDict(256) if ne else ne,
               **kwargs):
    if not isinstance(expr, (str, unicode)):
        raise ValueError("must specify expression as a string")
    # Get the names for this expression
    context = ne.necompiler.getContext(kwargs, frame_depth=1)
    expr_key = (expr, tuple(sorted(context.items())))
    if expr_key not in _names_cache:
        _names_cache[expr_key] = ne.necompiler.getExprNames(expr.strip(),
                                                            context)
    names, ex_uses_vml = _names_cache[expr_key]
    return names
github OSGeo / grass-addons / grass7 / raster / r.green / r.green.hydro / r.green.hydro.financial / r.green.hydro.financial.py View on Github external
def get_cnames(expr,
               _names_cache=ne.utils.CacheDict(256) if ne else ne,
               _numexpr_cache=ne.utils.CacheDict(256) if ne else ne,
               **kwargs):
    if not isinstance(expr, (str, unicode)):
        raise ValueError("must specify expression as a string")
    # Get the names for this expression
    context = ne.necompiler.getContext(kwargs, frame_depth=1)
    expr_key = (expr, tuple(sorted(context.items())))
    if expr_key not in _names_cache:
        _names_cache[expr_key] = ne.necompiler.getExprNames(expr.strip(),
                                                            context)
    names, ex_uses_vml = _names_cache[expr_key]
    return names