Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
----------
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
----------
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
def __init__(self, maxentries):
self.maxentries = maxentries
super(CacheDict, self).__init__(self)
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
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