Python operator 模块,div() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用operator.div()

项目:Scalable-PaQL-Queries    作者:mattfeel    | 项目源码 | 文件源码
def op_to_opstr(op):
    if op is operator.le:
        return "<="
    elif op is operator.ge:
        return ">="
    elif op is operator.eq:
        return "="
    elif op is operator.add:
        return "+"
    elif op is operator.sub:
        return "-"
    elif op is operator.mul:
        return "*"
    elif op is operator.div:
        return "/"
    else:
        raise Exception("Operator '{}' not supported yet.", op)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __floordiv__(a, b):
        """a // b"""
        # Will be math.floor(a / b) in 3.0.
        div = a / b
        if isinstance(div, Rational):
            # trunc(math.floor(div)) doesn't work if the rational is
            # more precise than a float because the intermediate
            # rounding may cross an integer boundary.
            return div.numerator // div.denominator
        else:
            return math.floor(div)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __rfloordiv__(b, a):
        """a // b"""
        # Will be math.floor(a / b) in 3.0.
        div = a / b
        if isinstance(div, Rational):
            # trunc(math.floor(div)) doesn't work if the rational is
            # more precise than a float because the intermediate
            # rounding may cross an integer boundary.
            return div.numerator // div.denominator
        else:
            return math.floor(div)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __mod__(a, b):
        """a % b"""
        div = a // b
        return a - b * div
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __rmod__(b, a):
        """a % b"""
        div = a // b
        return a - b * div
项目:otRebuilder    作者:Pal3love    | 项目源码 | 文件源码
def __truediv__(self, other):
        return Vector(self._scalarOp(other, operator.div), keep=True)
项目:otRebuilder    作者:Pal3love    | 项目源码 | 文件源码
def __itruediv__(self, other):
        self.values = self._scalarOp(other, operator.div)
        return self
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def __rdiv__(self, other):
        """Implement the ``/`` operator in reverse.

        See :meth:`.ColumnOperators.__div__`.

        """
        return self.reverse_operate(div, other)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def __div__(self, other):
        """Implement the ``/`` operator.

        In a column context, produces the clause ``a / b``.

        """
        return self.operate(div, other)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def __floordiv__(a, b):
        """a // b"""
        # Will be math.floor(a / b) in 3.0.
        div = a / b
        if isinstance(div, Rational):
            # trunc(math.floor(div)) doesn't work if the rational is
            # more precise than a float because the intermediate
            # rounding may cross an integer boundary.
            return div.numerator // div.denominator
        else:
            return math.floor(div)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def __rfloordiv__(b, a):
        """a // b"""
        # Will be math.floor(a / b) in 3.0.
        div = a / b
        if isinstance(div, Rational):
            # trunc(math.floor(div)) doesn't work if the rational is
            # more precise than a float because the intermediate
            # rounding may cross an integer boundary.
            return div.numerator // div.denominator
        else:
            return math.floor(div)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def __mod__(a, b):
        """a % b"""
        div = a // b
        return a - b * div
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def __rmod__(b, a):
        """a % b"""
        div = a // b
        return a - b * div
项目:turtle    作者:icse-turtle    | 项目源码 | 文件源码
def division(self, *args):
        if not len(args) > 1:
            raise EvaluateException('\ requires at least 2 parameters!' + ' (' + str(len(args)) + ' given).')

        elif False in [isinstance(x, NumberType) for x in args]:
            raise EvaluateException('\ requires all parameters to be numbers!')

        elif 0 in [x.content for x in args[1:]]:
            raise EvaluateException('division by zero!')

        return reduce(op.div, args[1:], args[0])
项目:QXSConsolas    作者:qxsch    | 项目源码 | 文件源码
def __rdiv__(self, other):
        """Implement the ``/`` operator in reverse.

        See :meth:`.ColumnOperators.__div__`.

        """
        return self.reverse_operate(div, other)
项目:QXSConsolas    作者:qxsch    | 项目源码 | 文件源码
def __div__(self, other):
        """Implement the ``/`` operator.

        In a column context, produces the clause ``a / b``.

        """
        return self.operate(div, other)
项目:required    作者:shezadkhan137    | 项目源码 | 文件源码
def __div__(self, other):
        fieldop = FieldOp(operator.div, self, other)
        return R(fieldop)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_div_scalar(self):
        if six.PY3:
            return
        with testing.NumpyError(divide='ignore'):
            self.check_array_scalar_op(operator.div)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_rdiv_scalar(self):
        if six.PY3:
            return
        with testing.NumpyError(divide='ignore'):
            self.check_array_scalar_op(operator.div, swap=True)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_div_array(self):
        if six.PY3:
            return
        with testing.NumpyError(divide='ignore'):
            self.check_array_array_op(operator.div)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_broadcasted_div(self):
        if six.PY3:
            return
        with testing.NumpyError(divide='ignore'):
            self.check_array_broadcasted_op(operator.div)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_doubly_broadcasted_div(self):
        if six.PY3:
            return
        with testing.NumpyError(divide='ignore'):
            self.check_array_doubly_broadcasted_op(operator.div)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def __rdiv__(self, other):
        """Implement the ``/`` operator in reverse.

        See :meth:`.ColumnOperators.__div__`.

        """
        return self.reverse_operate(div, other)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def __div__(self, other):
        """Implement the ``/`` operator.

        In a column context, produces the clause ``a / b``.

        """
        return self.operate(div, other)
项目:Orator-Google-App-Engine    作者:MakarenaLabs    | 项目源码 | 文件源码
def __div__(self, other):
        return operator.div(self.__wrapped__, other)
项目:Orator-Google-App-Engine    作者:MakarenaLabs    | 项目源码 | 文件源码
def __rdiv__(self, other):
        return operator.div(other, self.__wrapped__)
项目:Orator-Google-App-Engine    作者:MakarenaLabs    | 项目源码 | 文件源码
def __rdiv__(self, other):
        return operator.div(other, self.__wrapped__)
项目:apm-agent-python    作者:elastic    | 项目源码 | 文件源码
def __div__(self, other):
        return operator.div(self.__wrapped__, other)
项目:apm-agent-python    作者:elastic    | 项目源码 | 文件源码
def __rdiv__(self, other):
        return operator.div(other, self.__wrapped__)
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def __rdiv__(self, other):
        """Implement the ``/`` operator in reverse.

        See :meth:`.ColumnOperators.__div__`.

        """
        return self.reverse_operate(div, other)
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def __div__(self, other):
        """Implement the ``/`` operator.

        In a column context, produces the clause ``a / b``.

        """
        return self.operate(div, other)
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def __rdiv__(self, other):
        """Implement the ``/`` operator in reverse.

        See :meth:`.ColumnOperators.__div__`.

        """
        return self.reverse_operate(div, other)
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def __div__(self, other):
        """Implement the ``/`` operator.

        In a column context, produces the clause ``a / b``.

        """
        return self.operate(div, other)
项目:ShelbySearch    作者:Agentscreech    | 项目源码 | 文件源码
def __rdiv__(self, other):
        """Implement the ``/`` operator in reverse.

        See :meth:`.ColumnOperators.__div__`.

        """
        return self.reverse_operate(div, other)
项目:ShelbySearch    作者:Agentscreech    | 项目源码 | 文件源码
def __div__(self, other):
        """Implement the ``/`` operator.

        In a column context, produces the clause ``a / b``.

        """
        return self.operate(div, other)
项目:Vector-Tiles-Reader-QGIS-Plugin    作者:geometalab    | 项目源码 | 文件源码
def __div__(self, y):
    return NonStandardInteger(operator.div(self.val, y))
项目:Vector-Tiles-Reader-QGIS-Plugin    作者:geometalab    | 项目源码 | 文件源码
def __rdiv__(self, y):
    return NonStandardInteger(operator.div(y, self.val))
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def test_registry_association():
    ds = fake_random_ds(64, nprocs=1, length_unit=10)
    a = ds.quan(3, 'cm')
    b = YTQuantity(4, 'm')
    c = ds.quan(6, '')
    d = 5

    assert_equal(id(a.units.registry), id(ds.unit_registry))

    def binary_op_registry_comparison(op):
        e = op(a, b)
        f = op(b, a)
        g = op(c, d)
        h = op(d, c)

        assert_equal(id(e.units.registry), id(ds.unit_registry))
        assert_equal(id(f.units.registry), id(b.units.registry))
        assert_equal(id(g.units.registry), id(h.units.registry))
        assert_equal(id(g.units.registry), id(ds.unit_registry))

    def unary_op_registry_comparison(op):
        c = op(a)
        d = op(b)

        assert_equal(id(c.units.registry), id(ds.unit_registry))
        assert_equal(id(d.units.registry), id(b.units.registry))

    binary_ops = [operator.add, operator.sub, operator.mul, 
                  operator.truediv]
    if hasattr(operator, "div"):
        binary_ops.append(operator.div)
    for op in binary_ops:
        binary_op_registry_comparison(op)

    for op in [operator.abs, operator.neg, operator.pos]:
        unary_op_registry_comparison(op)
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def test_subclass():

    class YTASubclass(YTArray):
        pass

    a = YTASubclass([4, 5, 6], 'g')
    b = YTASubclass([7, 8, 9], 'kg')
    nu = YTASubclass([10, 11, 12], '')
    nda = np.array([3, 4, 5])
    yta = YTArray([6, 7, 8], 'mg')
    loq = [YTQuantity(6, 'mg'), YTQuantity(7, 'mg'), YTQuantity(8, 'mg')]
    ytq = YTQuantity(4, 'cm')
    ndf = np.float64(3)

    def op_comparison(op, inst1, inst2, compare_class):
        assert_isinstance(op(inst1, inst2), compare_class)
        assert_isinstance(op(inst2, inst1), compare_class)

    ops = [operator.mul, operator.truediv]
    if hasattr(operator, "div"):
        ops.append(operator.div)
    for op in ops:
        for inst in (b, ytq, ndf, yta, nda, loq):
            op_comparison(op, a, inst, YTASubclass)

        op_comparison(op, ytq, nda, YTArray)
        op_comparison(op, ytq, yta, YTArray)

    for op in (operator.add, operator.sub):
        op_comparison(op, nu, nda, YTASubclass)
        op_comparison(op, a, b, YTASubclass)
        op_comparison(op, a, yta, YTASubclass)
        op_comparison(op, a, loq, YTASubclass)

    assert_isinstance(a[0], YTQuantity)
    assert_isinstance(a[:], YTASubclass)
    assert_isinstance(a[:2], YTASubclass)
    assert_isinstance(YTASubclass(yta), YTASubclass)
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __div__(self, other):
        assert type(other) in scalar_types
        return Vector2(operator.div(self.x, other),
                       operator.div(self.y, other))
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __rdiv__(self, other):
        assert type(other) in scalar_types
        return Vector2(operator.div(other, self.x),
                       operator.div(other, self.y))
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __mul__(self, other):
        if isinstance(other, Vector3):
            # TODO component-wise mul/div in-place and on Vector2; docs.
            if self.__class__ is Point3 or other.__class__ is Point3:
                _class = Point3
            else:
                _class = Vector3
            return _class(self.x * other.x,
                          self.y * other.y,
                          self.z * other.z)
        else: 
            assert type(other) in scalar_types
            return Vector3(self.x * other,
                           self.y * other,
                           self.z * other)
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __div__(self, other):
        assert type(other) in scalar_types
        return Vector3(operator.div(self.x, other),
                       operator.div(self.y, other),
                       operator.div(self.z, other))
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __rdiv__(self, other):
        assert type(other) in scalar_types
        return Vector3(operator.div(other, self.x),
                       operator.div(other, self.y),
                       operator.div(other, self.z))
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
def __rdiv__(self, other):
        """Implement the ``/`` operator in reverse.

        See :meth:`.ColumnOperators.__div__`.

        """
        return self.reverse_operate(div, other)
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
def __div__(self, other):
        """Implement the ``/`` operator.

        In a column context, produces the clause ``a / b``.

        """
        return self.operate(div, other)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_div(self):
        self.assertRaises(TypeError, operator.div, 5)
        self.assertRaises(TypeError, operator.div, None, None)
        self.assertTrue(operator.floordiv(5, 2) == 2)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def __floordiv__(a, b):
        """a // b"""
        # Will be math.floor(a / b) in 3.0.
        div = a / b
        if isinstance(div, Rational):
            # trunc(math.floor(div)) doesn't work if the rational is
            # more precise than a float because the intermediate
            # rounding may cross an integer boundary.
            return div.numerator // div.denominator
        else:
            return math.floor(div)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def __rfloordiv__(b, a):
        """a // b"""
        # Will be math.floor(a / b) in 3.0.
        div = a / b
        if isinstance(div, Rational):
            # trunc(math.floor(div)) doesn't work if the rational is
            # more precise than a float because the intermediate
            # rounding may cross an integer boundary.
            return div.numerator // div.denominator
        else:
            return math.floor(div)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def __mod__(a, b):
        """a % b"""
        div = a // b
        return a - b * div