# How to use the numexpr.expressions.FuncNode 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.

pydata / numexpr / numexpr / expressions.py View on Github
kind = 'double'
r = multiply(r, OpNode('sqrt', [a], kind))
if r is None:
r = OpNode('ones_like', [a])
if x &lt; 0:
r = OpNode('div', [ConstantNode(1), r])
return r
if get_optimization() in ('moderate', 'aggressive'):
if x == -1:
return OpNode('div', [ConstantNode(1), a])
if x == 0:
return OpNode('ones_like', [a])
if x == 0.5:
kind = a.astKind
if kind in ('int', 'long'): kind = 'double'
return FuncNode('sqrt', [a], kind=kind)
if x == 1:
return a
if x == 2:
return OpNode('mul', [a, a])
return OpNode('pow', [a, b])
pydata / numexpr / numexpr / expressions.py View on Github
def _func(a, axis=None):
axis = encode_axis(axis)
if isinstance(a, ConstantNode):
return a
if isinstance(a, (bool, int_, long_, float, double, complex)):
a = ConstantNode(a)
return FuncNode(name, [a, axis], kind=a.astKind)
return _func
pydata / numexpr / numexpr / expressions.py View on Github
def where_func(a, b, c):
if isinstance(a, ConstantNode):
return b if a.value else c
if allConstantNodes([a, b, c]):
return ConstantNode(numpy.where(a, b, c))
return FuncNode('where', [a, b, c])
pydata / numexpr / numexpr / expressions.py View on Github
def contains_func(a, b):
return FuncNode('contains', [a, b], kind='bool')
pydata / numexpr / numexpr / expressions.py View on Github
if allConstantNodes(args):
return ConstantNode(func(*[x.value for x in args]))
kind = commonKind(args)
if kind in ('int', 'long'):
# Exception for following NumPy casting rules
#FIXME: this is not always desirable. The following
# functions which return ints (for int inputs) on numpy
# but not on numexpr: copy, abs, fmod, ones_like
kind = 'double'
else:
# Apply regular casting rules
if minkind and kind_rank.index(minkind) &gt; kind_rank.index(kind):
kind = minkind
if maxkind and kind_rank.index(maxkind) &lt; kind_rank.index(kind):
kind = maxkind
return FuncNode(func.__name__, args, kind)

## numexpr

Fast numerical expression evaluator for NumPy

MIT