python类div()的实例源码

operators.py 文件源码 项目:oa_qian 作者: sunqb 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __div__(self, other):
        """Implement the ``/`` operator.

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

        """
        return self.operate(div, other)
operators.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __rdiv__(self, other):
        """Implement the ``/`` operator in reverse.

        See :meth:`.ColumnOperators.__div__`.

        """
        return self.reverse_operate(div, other)
operators.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __div__(self, other):
        """Implement the ``/`` operator.

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

        """
        return self.operate(div, other)
operators.py 文件源码 项目:ShelbySearch 作者: Agentscreech 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __rdiv__(self, other):
        """Implement the ``/`` operator in reverse.

        See :meth:`.ColumnOperators.__div__`.

        """
        return self.reverse_operate(div, other)
operators.py 文件源码 项目:ShelbySearch 作者: Agentscreech 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __div__(self, other):
        """Implement the ``/`` operator.

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

        """
        return self.operate(div, other)
test_util.py 文件源码 项目:Vector-Tiles-Reader-QGIS-Plugin 作者: geometalab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __div__(self, y):
    return NonStandardInteger(operator.div(self.val, y))
test_util.py 文件源码 项目:Vector-Tiles-Reader-QGIS-Plugin 作者: geometalab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __rdiv__(self, y):
    return NonStandardInteger(operator.div(y, self.val))
test_ytarray.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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)
test_ytarray.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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)
euclid.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __div__(self, other):
        assert type(other) in scalar_types
        return Vector2(operator.div(self.x, other),
                       operator.div(self.y, other))
euclid.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __rdiv__(self, other):
        assert type(other) in scalar_types
        return Vector2(operator.div(other, self.x),
                       operator.div(other, self.y))
euclid.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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)
euclid.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
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))
euclid.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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))
operators.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __rdiv__(self, other):
        """Implement the ``/`` operator in reverse.

        See :meth:`.ColumnOperators.__div__`.

        """
        return self.reverse_operate(div, other)
operators.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def __div__(self, other):
        """Implement the ``/`` operator.

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

        """
        return self.operate(div, other)
test_operator.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_div(self):
        self.assertRaises(TypeError, operator.div, 5)
        self.assertRaises(TypeError, operator.div, None, None)
        self.assertTrue(operator.floordiv(5, 2) == 2)
fractions.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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)
fractions.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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)
fractions.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __mod__(a, b):
        """a % b"""
        div = a // b
        return a - b * div


问题


面经


文章

微信
公众号

扫码关注公众号