How to use the numexpr.necompiler.getContext 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 FAST-HEP / fast-carpenter / fast_carpenter / expressions.py View on Github external
def evaluate(tree, expression):
    cleaned_expression, alias_dict = preprocess_expression(expression)
    context = numexpr.necompiler.getContext({}, frame_depth=1)
    variables = numexpr.necompiler.getExprNames(cleaned_expression, context)[0]
    try:
        adaptor = TreeToDictAdaptor(tree, alias_dict, variables)
    except ValueError:
        msg = "Cannot broadcast all variables in expression: %s" % expression
        logger.error(msg)
        raise ValueError(msg)
    result = numexpr.evaluate(cleaned_expression, local_dict=adaptor)
    result = adaptor.apply_jaggedness(result)
    return result
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 PyTables / PyTables / tables / expression.py View on Github external
"""The start range selection for the input."""
        self.stop = None
        """The stop range selection for the input."""
        self.step = None
        """The step range selection for the input."""
        self.values = []
        """The values of variables in expression (list)."""

        self._compiled_expr = None
        """The compiled expression."""
        self._single_row_out = None
        """A sample of the output with just a single row."""

        # First, get the signature for the arrays in expression
        vars_ = self._required_expr_vars(expr, uservars)
        context = getContext(kwargs)
        self.names, _ = getExprNames(expr, context)

        # Raise a ValueError in case we have unsupported objects
        for name, var in vars_.items():
            if type(var) in (int, float, str):
                continue
            if not isinstance(var, (tb.Leaf, tb.Column)):
                if hasattr(var, "dtype"):
                    # Quacks like a NumPy object
                    continue
                raise TypeError("Unsupported variable type: %r" % var)
            objname = var.__class__.__name__
            if objname not in ("Array", "CArray", "EArray", "Column"):
                raise TypeError("Unsupported variable type: %r" % var)

        # NumPy arrays to be copied? (we don't need to worry about