Create a Ufunc `Operator` from a given specification.
169973
def ufunc_class_factory(name, nargin, nargout, docstring):
    """"""

    assert 0 <= nargin <= 2

    def __init__(self, space):
        """Initialize an instance.

        Parameters
        ----------
        space : `TensorSpace`
            The domain of the operator.
        """
        if not isinstance(space, LinearSpace):
            raise TypeError('`space` {!r} not a `LinearSpace`'.format(space))

        if nargin == 1:
            domain = space0 = space
            dtypes = [space.dtype]
        elif nargin == len(space) == 2 and isinstance(space, ProductSpace):
            domain = space
            space0 = space[0]
            dtypes = [space[0].dtype, space[1].dtype]
        else:
            domain = ProductSpace(space, nargin)
            space0 = space
            dtypes = [space.dtype, space.dtype]

        dts_out = dtypes_out(name, dtypes)

        if nargout == 1:
            range = space0.astype(dts_out[0])
        else:
            range = ProductSpace(space0.astype(dts_out[0]),
                                 space0.astype(dts_out[1]))

        linear = name in LINEAR_UFUNCS
        Operator.__init__(self, domain=domain, range=range, linear=linear)

    def _call(self, x, out=None):
        """Return ``self(x)``."""
        # TODO: use `__array_ufunc__` when implemented on `ProductSpace`,
        # or try both
        if out is None:
            if nargin == 1:
                return getattr(x.ufuncs, name)()
            else:
                return getattr(x[0].ufuncs, name)(*x[1:])
        else:
            if nargin == 1:
                return getattr(x.ufuncs, name)(out=out)
            else:
                return getattr(x[0].ufuncs, name)(*x[1:], out=out)

    def __repr__(self):
        """Return ``repr(self)``."""
        return '{}({!r})'.format(name, self.domain)

    # Create example (also functions as doctest)
    if 'shift' in name or 'bitwise' in name or name == 'invert':
        dtype = int
    else:
        dtype = float

    space = tensor_space(3, dtype=dtype)
    if nargin == 1:
        vec = space.element([-1, 1, 2])
        arg = '{}'.format(vec)
        with np.errstate(all='ignore'):
            result = getattr(vec.ufuncs, name)()
    else:
        vec = space.element([-1, 1, 2])
        vec2 = space.element([3, 4, 5])
        arg = '[{}, {}]'.format(vec, vec2)
        with np.errstate(all='ignore'):
            result = getattr(vec.ufuncs, name)(vec2)

    if nargout == 2:
        result_space = ProductSpace(vec.space, 2)
        result = repr(result_space.element(result))

    examples_docstring = RAW_EXAMPLES_DOCSTRING.format(space=space, name=name,
                                                       arg=arg, result=result)
    full_docstring = docstring + examples_docstring

    attributes = {"__init__": __init__,
                  "_call": _call,
                  "derivative": derivative_factory(name),
                  "__repr__": __repr__,
                  "__doc__": full_docstring}

    full_name = name + '_op'

    return type(full_name, (Operator,), attributes)
385250
def binary_operator(op):
    
    # When combining a Filter with a NumericalExpression, we use this
    # attrgetter instance to defer to the commuted interpretation of the
    # NumericalExpression operator.
    commuted_method_getter = attrgetter(method_name_for_op(op, commute=True))

    def binary_operator(self, other):
        if isinstance(self, NumericalExpression):
            self_expr, other_expr, new_inputs = self.build_binary_op(
                op, other,
            )
            return NumExprFilter.create(
                "({left}) {op} ({right})".format(
                    left=self_expr,
                    op=op,
                    right=other_expr,
                ),
                new_inputs,
            )
        elif isinstance(other, NumericalExpression):
            # NumericalExpression overrides numerical ops to correctly handle
            # merging of inputs.  Look up and call the appropriate
            # right-binding operator with ourself as the input.
            return commuted_method_getter(other)(self)
        elif isinstance(other, Term):
            if other.dtype != bool_dtype:
                raise BadBinaryOperator(op, self, other)
            if self is other:
                return NumExprFilter.create(
                    "x_0 {op} x_0".format(op=op),
                    (self,),
                )
            return NumExprFilter.create(
                "x_0 {op} x_1".format(op=op),
                (self, other),
            )
        elif isinstance(other, int):  # Note that this is true for bool as well
            return NumExprFilter.create(
                "x_0 {op} {constant}".format(op=op, constant=int(other)),
                binds=(self,),
            )
        raise BadBinaryOperator(op, self, other)

    binary_operator.__doc__ = "Binary Operator: '%s'" % op
    return binary_operator
843654
def unary_operator(op):
    
    valid_ops = {'~'}
    if op not in valid_ops:
        raise ValueError("Invalid unary operator %s." % op)

    def unary_operator(self):
        # This can't be hoisted up a scope because the types returned by
        # unary_op_return_type aren't defined when the top-level function is
        # invoked.
        if isinstance(self, NumericalExpression):
            return NumExprFilter.create(
                "{op}({expr})".format(op=op, expr=self._expr),
                self.inputs,
            )
        else:
            return NumExprFilter.create("{op}x_0".format(op=op), (self,))

    unary_operator.__doc__ = "Unary Operator: '%s'" % op
    return unary_operator
564359
def _gt_from_lt(self, other):
    """"""
    op_result = self.__lt__(other)
    if op_result is NotImplemented:
        return NotImplemented
    return not op_result and self != other
1095098
def to_match(self):
        """"""
        self.validate()

        translation_table = {
            u'size': u'size()',
        }
        match_operator = translation_table.get(self.operator)
        if not match_operator:
            raise AssertionError(u'Unrecognized operator used: '
                                 u'{} {}'.format(self.operator, self))

        template = u'%(inner)s.%(operator)s'
        args = {
            'inner': self.inner_expression.to_match(),
            'operator': match_operator,
        }
        return template % args
257404
def _lt_from_ge(self, other):
    """"""
    op_result = self.__ge__(other)
    if op_result is NotImplemented:
        return NotImplemented
    return not op_result
1271213
def wrap_ufunc_base(name, n_in, n_out, doc):
    """"""
    ufunc = getattr(np, name)
    if n_in == 1:
        if n_out == 1:
            def wrapper(self, out=None, **kwargs):
                if out is None or isinstance(out, (type(self.elem),
                                                   type(self.elem.data))):
                    out = (out,)

                return self.elem.__array_ufunc__(
                    ufunc, '__call__', self.elem, out=out, **kwargs)

        elif n_out == 2:
            def wrapper(self, out=None, **kwargs):
                if out is None:
                    out = (None, None)

                return self.elem.__array_ufunc__(
                    ufunc, '__call__', self.elem, out=out, **kwargs)

        else:
            raise NotImplementedError

    elif n_in == 2:
        if n_out == 1:
            def wrapper(self, x2, out=None, **kwargs):
                return self.elem.__array_ufunc__(
                    ufunc, '__call__', self.elem, x2, out=(out,), **kwargs)

        else:
            raise NotImplementedError
    else:
        raise NotImplementedError

    wrapper.__name__ = wrapper.__qualname__ = name
    wrapper.__doc__ = doc
    return wrapper
1139284
def _call(self, x, out=None):
        """"""
        if out is None:
            return self.operator(self.scalar * x)
        else:
            if self.__tmp is not None:
                tmp = self.__tmp
            else:
                tmp = self.domain.element()
            tmp.lincomb(self.scalar, x)
            self.operator(tmp, out=out)
1069355
def constructSpec(indentation, begin_block, end_block, begin_line, end_line, 
                  begin_action, end_action, 
                  begin_condition, end_condition, 
                  logical_and, logical_or):
    """"""
    return {
        INDENTATION   : indentation, 
        BEG_BLOCK     : begin_block,
        END_BLOCK     : end_block,
        BEG_LINE      : begin_line, 
        END_LINE      : end_line, 
        BEG_ACTION    : begin_action, 
        END_ACTION    : end_action, 
        BEG_CONDITION : begin_condition, 
        END_CONDITION : end_condition, 
        LOGICAL_AND   : logical_and, 
        LOGICAL_OR    : logical_or
    }
876584
def validate(self):
        """"""
        _validate_operator_name(self.operator, BinaryComposition.SUPPORTED_OPERATORS)

        if not isinstance(self.left, Expression):
            raise TypeError(u'Expected Expression left, got: {} {} {}'.format(
                type(self.left).__name__, self.left, self))

        if not isinstance(self.right, Expression):
            raise TypeError(u'Expected Expression right, got: {} {}'.format(
                type(self.right).__name__, self.right))
688915
def _build_ufunc(func):
    """"""
    def larray_compatible_ufunc(x):
        if isinstance(x, larray):
            y = deepcopy(x)
            y.apply(func)
            return y
        else:
            return func(x)
    return larray_compatible_ufunc
1079748
def compile_query(query):
    """"""
    if isinstance(query, dict):
        expressions = []
        for key, value in query.items():
            if key.startswith('$'):
                if key not in query_funcs:
                    raise AttributeError('Invalid operator: {}'.format(key))
                expressions.append(query_funcs[key](value))
            else:
                expressions.append(filter_query(key, value))
        if len(expressions) > 1:
            return boolean_operator_query(operator.and_)(expressions)
        else:
            return (
                expressions[0]
                if len(expressions)
                else lambda query_function: query_function(None, None)
            )
    else:
        return query
1089107
function (operator) {
            var name = operator.operator,
                ret = {},
                field;
            if (name === "and" || name === "or" || name === "not") {
                ret["$" + name] = this.translateExpressions(operator.expressions);
            } else if (name === "eql") {
                field = operator.field;
                ret[field] = operator.value;
            } else if (QuerytoMongoMap.hasOwnProperty(name)) {
                field = operator.field;

                ret[field] = {};
                ret[field][QuerytoMongoMap[name]] = operator.value;
            } else if (name === "between") {
                field = operator.field;
                ret[field].$gt = operator.value[0];
                ret[field].$lt = operator.value[1];
            } else if (name === "like") {
                field = operator.field;
                ret[field] = {};
                ret[field].$regex = new RegExp(".*" + operator.value + ".*", "i");
            } else {
                throw new Error("Query Operator '" + name + "' is not supported!");
            }

            return ret;
        }
689529
def _call(self, x, out=None):
        """"""
        if out is None:
            return self.scalar * self.operator(x)
        else:
            self.operator(x, out=out)
            out *= self.scalar
698493
def _le_from_lt(self, other):
    """"""
    op_result = self.__lt__(other)
    return op_result or self == other
1131439
def _lt_from_le(self, other):
    """"""
    op_result = self.__le__(other)
    if op_result is NotImplemented:
        return NotImplemented
    return op_result and self != other
996181
public Operator createOperator(int op, Selector operand)
  {
	Operator operator = new OperatorImpl(op, operand);

	return operator; 
  }