Converts NeuroML arithmetic/logical operators to python equivalents.

        @param op: NeuroML operator
        @type op: string


        @return: Python operator
        @rtype: string
485182
def convert_op(self, op):
        

        if op == '.gt.':
            return '>'
        elif op == '.ge.' or op == '.geq.':
            return '>='
        elif op == '.lt.':
            return '<'
        elif op == '.le.':
            return '<='
        elif op == '.eq.':
            return '=='
        elif op == '.neq.':   
            return '!='
        elif op == '.ne.':   # .neq. is preferred!
            return '!='
        elif op == '^':
            return '**'
        elif op == '.and.':
            return 'and'
        elif op == '.or.':
            return 'or'
        else:
            return op
666728
def binary_operator(op):
    
    # When combining a Factor with a NumericalExpression, we use this
    # attrgetter instance to defer to the commuted implementation of the
    # NumericalExpression operator.
    commuted_method_getter = attrgetter(method_name_for_op(op, commute=True))

    @with_doc("Binary Operator: '%s'" % op)
    @with_name(method_name_for_op(op))
    @coerce_numbers_to_my_dtype
    def binary_operator(self, other):
        # This can't be hoisted up a scope because the types returned by
        # binop_return_type aren't defined when the top-level function is
        # invoked in the class body of Factor.
        return_type = binop_return_type(op)
        if isinstance(self, NumExprFactor):
            self_expr, other_expr, new_inputs = self.build_binary_op(
                op, other,
            )
            return return_type(
                "({left}) {op} ({right})".format(
                    left=self_expr,
                    op=op,
                    right=other_expr,
                ),
                new_inputs,
                dtype=binop_return_dtype(op, self.dtype, other.dtype),
            )
        elif isinstance(other, NumExprFactor):
            # NumericalExpression overrides ops to correctly handle merging of
            # inputs.  Look up and call the appropriate reflected operator with
            # ourself as the input.
            return commuted_method_getter(other)(self)
        elif isinstance(other, Term):
            if self is other:
                return return_type(
                    "x_0 {op} x_0".format(op=op),
                    (self,),
                    dtype=binop_return_dtype(op, self.dtype, other.dtype),
                )
            return return_type(
                "x_0 {op} x_1".format(op=op),
                (self, other),
                dtype=binop_return_dtype(op, self.dtype, other.dtype),
            )
        elif isinstance(other, Number):
            return return_type(
                "x_0 {op} ({constant})".format(op=op, constant=other),
                binds=(self,),
                # .dtype access is safe here because coerce_numbers_to_my_dtype
                # will convert any input numbers to numpy equivalents.
                dtype=binop_return_dtype(op, self.dtype, other.dtype)
            )
        raise BadBinaryOperator(op, self, other)

    return binary_operator
155903
function processOperators (ops) {
    if (!ops) return {};
    var operators = {};
    for (var i=0,k,prec;prec=ops[i]; i++) {
        for (k=1;k < prec.length;k++) {
            operators[prec[k]] = {precedence: i+1, assoc: prec[0]};
        }
    }
    return operators;
}
758112
def logical_binary_op(self):
        
        return (CaselessKeyword(self.syntax.and_op) |
                CaselessKeyword(self.syntax.or_op))
875960
def _bool_method_SERIES(cls, op, special):
    
    op_name = _get_op_name(op, special)

    def na_op(x, y):
        try:
            result = op(x, y)
        except TypeError:
            assert not isinstance(y, (list, ABCSeries, ABCIndexClass))
            if isinstance(y, np.ndarray):
                # bool-bool dtype operations should be OK, should not get here
                assert not (is_bool_dtype(x) and is_bool_dtype(y))
                x = ensure_object(x)
                y = ensure_object(y)
                result = libops.vec_binop(x, y, op)
            else:
                # let null fall thru
                assert lib.is_scalar(y)
                if not isna(y):
                    y = bool(y)
                try:
                    result = libops.scalar_binop(x, y, op)
                except (TypeError, ValueError, AttributeError,
                        OverflowError, NotImplementedError):
                    raise TypeError("cannot compare a dtyped [{dtype}] array "
                                    "with a scalar of type [{typ}]"
                                    .format(dtype=x.dtype,
                                            typ=type(y).__name__))

        return result

    fill_int = lambda x: x.fillna(0)
    fill_bool = lambda x: x.fillna(False).astype(bool)

    def wrapper(self, other):
        is_self_int_dtype = is_integer_dtype(self.dtype)

        self, other = _align_method_SERIES(self, other, align_asobject=True)
        res_name = get_op_result_name(self, other)

        if isinstance(other, ABCDataFrame):
            # Defer to DataFrame implementation; fail early
            return NotImplemented

        elif isinstance(other, (ABCSeries, ABCIndexClass)):
            is_other_int_dtype = is_integer_dtype(other.dtype)
            other = fill_int(other) if is_other_int_dtype else fill_bool(other)

            ovalues = other.values
            finalizer = lambda x: x

        else:
            # scalars, list, tuple, np.array
            is_other_int_dtype = is_integer_dtype(np.asarray(other))
            if is_list_like(other) and not isinstance(other, np.ndarray):
                # TODO: Can we do this before the is_integer_dtype check?
                # could the is_integer_dtype check be checking the wrong
                # thing?  e.g. other = [[0, 1], [2, 3], [4, 5]]?
                other = construct_1d_object_array_from_listlike(other)

            ovalues = other
            finalizer = lambda x: x.__finalize__(self)

        # For int vs int `^`, `|`, `&` are bitwise operators and return
        #   integer dtypes.  Otherwise these are boolean ops
        filler = (fill_int if is_self_int_dtype and is_other_int_dtype
                  else fill_bool)
        res_values = na_op(self.values, ovalues)
        unfilled = self._constructor(res_values,
                                     index=self.index, name=res_name)
        filled = filler(unfilled)
        return finalizer(filled)

    wrapper.__name__ = op_name
    return wrapper
596950
def operate(operator, other)
      if other.is_a?(Numeric)
        new(value.send(operator, other), unit)
      elsif other.respond_to?(:composition)
        if compatible_with?(other)
          converted = other.convert_to(unit)
          new(value.send(operator, converted.value),
              unit.send(operator, converted.unit))
        else
          new(value.send(operator, other.value),
              unit.send(operator, other.unit))
        end
      end
    end
242220
public static PointExpression<Point> pointOperation(Operator op, Expression<?>... args) {
        return new PointOperation<Point>(Point.class, op, args);
    }
1085929
def _reverse_op(name, doc="binary operator"):
    
    def _(self, other):
        jother = _create_column_from_literal(other)
        jc = getattr(jother, name)(self._jc)
        return Column(jc)
    _.__doc__ = doc
    return _
749034
def convert_one(self, op: ops.Operation) -> ops.OP_TREE:
        

        # Known gate name
        if not isinstance(op, ops.GateOperation):
            raise TypeError("{!r} is not a gate operation.".format(op))

        if is_native_ion_gate(op.gate):
            return [op]
        # one choice of known Hadamard gate decomposition
        if isinstance(op.gate, ops.HPowGate) and op.gate.exponent == 1:
            return [ops.Rx(np.pi).on(op.qubits[0]),
                    ops.Ry(-1 * np.pi/2).on(op.qubits[0])]
        # one choice of known CNOT gate decomposition
        if isinstance(op.gate, ops.CNotPowGate) and op.gate.exponent == 1:
            return [ops.Ry(np.pi/2).on(op.qubits[0]),
                    MS(np.pi/4).on(op.qubits[0], op.qubits[1]),
                    ops.Rx(-1*np.pi/2).on(op.qubits[0]),
                    ops.Rx(-1*np.pi/2).on(op.qubits[1]),
                    ops.Ry(-1*np.pi/2).on(op.qubits[0])]
        # Known matrix
        mat = protocols.unitary(op, None) if len(
            op.qubits) <= 2 else None
        if mat is not None and len(op.qubits) == 1:
            gates = optimizers.single_qubit_matrix_to_phased_x_z(mat)
            return [g.on(op.qubits[0]) for g in gates]
        elif mat is not None and len(op.qubits) == 2:
            return two_qubit_matrix_to_ion_operations(
                op.qubits[0], op.qubits[1], mat)
        else:
            if self.ignore_failures:
                return [op]
            else:
                raise TypeError(
                    "Don't know how to work with {!r}. "
                    "It isn't a native Ion Trap operation, "
                    "a 1 or 2 qubit gate with a known unitary, "
                    "or composite.".format(op.gate))
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
598208
def get_operations(self,
                       indices: Sequence[LogicalIndex],
                       qubits: Sequence[ops.Qid]
                       ) -> ops.OP_TREE:
        """"""
498228
def expr_to_str(n, l=None):
    
    op = n[0]
    if op.startswith('_') and op.endswith('_'):
        op = op.strip('_')
        if op == 'var':
            return n[1]
        elif op == 'literal':
            if isinstance(n[1], basestring):
                return "'%s'" % n[1]
            return str(n[1])
        elif op == 'cast':
            return "(%s)::%s" % (expr_to_str(n[1]), n[2])
    elif op in '+-*/':
        return "(%s) %s (%s)" % (expr_to_str(n[1]), op, expr_to_str(n[2]))
    elif op == "extract":
        return "extract( %s from %s )" % (n[1], expr_to_str(n[2]))
    else:
        arg = ','.join(map(expr_to_str, n[1:]))
        return "%s(%s)" % (op, arg)
244273
def arithmetic_mnemonic(self, op_name, op_type):
        """"""
        return self.OPERATIONS[op_name] + self.OPSIGNS[op_type]
1187827
def operator(self, operatorType, value):
        
        if value is None:
            if 'is none' in self._operatorMap and operatorType == Query.Op.Is:
                return 'is none'
            elif 'is not none' in self._operatorMap:
                return 'is not none'
            
        for op, data in self._operatorMap.items():
            if data.op == operatorType:
                return op
        return ''
755955
def _variable_inputs(self, op):
        
        if op.name not in self._vinputs:
            self._vinputs[op.name] = np.array([t.op in self.between_ops or t in self.model_inputs for t in op.inputs])
        return self._vinputs[op.name]
1022111
def relation_operation(self):
        
        if len(self.nodes) > 0:
            rel_op = self.nodes[-1].relation_operation
        else:
            rel_op = None
        return rel_op
1282775
def binary_op(data, op, other, blen=None, storage=None, create='array',
              **kwargs):
    """"""

    # normalise scalars
    if hasattr(other, 'shape') and len(other.shape) == 0:
        other = other[()]

    if np.isscalar(other):
        def f(block):
            return op(block, other)
        return map_blocks(data, f, blen=blen, storage=storage, create=create, **kwargs)

    elif len(data) == len(other):
        def f(a, b):
            return op(a, b)
        return map_blocks((data, other), f, blen=blen, storage=storage, create=create,
                          **kwargs)

    else:
        raise NotImplementedError('argument type not supported')