當前位置: 首頁>>代碼示例>>Python>>正文


Python operator.imul方法代碼示例

本文整理匯總了Python中operator.imul方法的典型用法代碼示例。如果您正苦於以下問題:Python operator.imul方法的具體用法?Python operator.imul怎麽用?Python operator.imul使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在operator的用法示例。


在下文中一共展示了operator.imul方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_inplace_multiplication

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def test_inplace_multiplication(self, input_tuple, expected):
        self.ureg.autoconvert_offset_to_baseunit = False
        (q1v, q1u), (q2v, q2u) = input_tuple
        # update input tuple with new values to have correct values on failure
        input_tuple = ((np.array([q1v]*2, dtype=np.float), q1u),
                       (np.array([q2v]*2, dtype=np.float), q2u))
        Q_ = self.Q_
        qin1, qin2 = input_tuple
        q1, q2 = Q_(*qin1), Q_(*qin2)
        q1_cp = copy.copy(q1)
        if expected == 'error':
            self.assertRaises(OffsetUnitCalculusError, op.imul, q1_cp, q2)
        else:
            expected = np.array([expected[0]]*2, dtype=np.float), expected[1]
            self.assertEqual(op.imul(q1_cp, q2).units, Q_(*expected).units)
            q1_cp = copy.copy(q1)
            self.assertQuantityAlmostEqual(op.imul(q1_cp, q2), Q_(*expected),
                                           atol=0.01) 
開發者ID:jmwright,項目名稱:cadquery-freecad-module,代碼行數:20,代碼來源:test_quantity.py

示例2: test_inplace_multiplication_with_autoconvert

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def test_inplace_multiplication_with_autoconvert(self, input_tuple, expected):
        self.ureg.autoconvert_offset_to_baseunit = True
        (q1v, q1u), (q2v, q2u) = input_tuple
        # update input tuple with new values to have correct values on failure
        input_tuple = ((np.array([q1v]*2, dtype=np.float), q1u),
                       (np.array([q2v]*2, dtype=np.float), q2u))
        Q_ = self.Q_
        qin1, qin2 = input_tuple
        q1, q2 = Q_(*qin1), Q_(*qin2)
        q1_cp = copy.copy(q1)
        if expected == 'error':
            self.assertRaises(OffsetUnitCalculusError, op.imul, q1_cp, q2)
        else:
            expected = np.array([expected[0]]*2, dtype=np.float), expected[1]
            self.assertEqual(op.imul(q1_cp, q2).units, Q_(*expected).units)
            q1_cp = copy.copy(q1)
            self.assertQuantityAlmostEqual(op.imul(q1_cp, q2), Q_(*expected),
                                           atol=0.01) 
開發者ID:jmwright,項目名稱:cadquery-freecad-module,代碼行數:20,代碼來源:test_quantity.py

示例3: test_operatorerrors

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def test_operatorerrors(self):
        f2 = self.f2
        f2p = self.f2p
        f256 = self.f256
        f19 = self.f19
        self.assertRaises(TypeError, operator.add, f2(1), f2p(2))
        self.assertRaises(TypeError, operator.iadd, f2(1), f2p(2))
        self.assertRaises(TypeError, operator.sub, f2(1), f256(2))
        self.assertRaises(TypeError, operator.isub, f2(1), f256(2))
        self.assertRaises(TypeError, operator.mul, f2(1), f19(2))
        self.assertRaises(TypeError, operator.imul, f2(1), f19(2))
        self.assertRaises(TypeError, operator.truediv, f256(1), f19(2))
        self.assertRaises(TypeError, operator.itruediv, f256(1), f19(2))
        self.assertRaises(TypeError, operator.truediv, 3.14, f19(2))
        self.assertRaises(TypeError, operator.lshift, f2(1), f2(1))
        self.assertRaises(TypeError, operator.ilshift, f2(1), f2(1))
        self.assertRaises(TypeError, operator.lshift, 1, f2(1))
        self.assertRaises(TypeError, operator.rshift, f19(1), f19(1))
        self.assertRaises(TypeError, operator.irshift, f19(1), f19(1))
        self.assertRaises(TypeError, operator.irshift, f256(1), f256(1))
        self.assertRaises(TypeError, operator.pow, f2(1), f19(2))
        self.assertRaises(TypeError, operator.pow, f19(1), 3.14) 
開發者ID:lschoe,項目名稱:mpyc,代碼行數:24,代碼來源:test_finfields.py

示例4: testIMul

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def testIMul(self):
        self.augmentedAssignCheck(operator.imul, imax=maxint)  # XXX doesn't work for long i??? 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:4,代碼來源:test_Signal.py

示例5: test_failures

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def test_failures():
    c1 = cycler(c='rgb')
    c2 = cycler(c=c1)
    pytest.raises(ValueError, add, c1, c2)
    pytest.raises(ValueError, iadd, c1, c2)
    pytest.raises(ValueError, mul, c1, c2)
    pytest.raises(ValueError, imul, c1, c2)
    pytest.raises(TypeError, iadd, c2, 'aardvark')
    pytest.raises(TypeError, imul, c2, 'aardvark')

    c3 = cycler(ec=c1)

    pytest.raises(ValueError, cycler, c=c2+c3) 
開發者ID:matplotlib,項目名稱:cycler,代碼行數:15,代碼來源:test_cycler.py

示例6: test_inplace_dense

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def test_inplace_dense(self):
        a = np.ones((3, 4))
        b = self.spmatrix(a)

        x = a.copy()
        y = a.copy()
        x += a
        y += b
        assert_array_equal(x, y)

        x = a.copy()
        y = a.copy()
        x -= a
        y -= b
        assert_array_equal(x, y)

        # This is matrix product, from __rmul__
        assert_raises(ValueError, operator.imul, x, b)
        x = a.copy()
        y = a.copy()
        x = x.dot(a.T)
        y *= b.T
        assert_array_equal(x, y)

        # Matrix (non-elementwise) floor division is not defined
        assert_raises(TypeError, operator.ifloordiv, x, b) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:28,代碼來源:test_base.py

示例7: test_buffer

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def test_buffer(self):
        a = array.array(self.typecode, self.example)
        m = memoryview(a)
        expected = m.tobytes()
        self.assertEqual(a.tobytes(), expected)
        self.assertEqual(a.tobytes()[0], expected[0])
        # Resizing is forbidden when there are buffer exports.
        # For issue 4509, we also check after each error that
        # the array was not modified.
        self.assertRaises(BufferError, a.append, a[0])
        self.assertEqual(m.tobytes(), expected)
        self.assertRaises(BufferError, a.extend, a[0:1])
        self.assertEqual(m.tobytes(), expected)
        self.assertRaises(BufferError, a.remove, a[0])
        self.assertEqual(m.tobytes(), expected)
        self.assertRaises(BufferError, a.pop, 0)
        self.assertEqual(m.tobytes(), expected)
        self.assertRaises(BufferError, a.fromlist, a.tolist())
        self.assertEqual(m.tobytes(), expected)
        self.assertRaises(BufferError, a.frombytes, a.tobytes())
        self.assertEqual(m.tobytes(), expected)
        if self.typecode == 'u':
            self.assertRaises(BufferError, a.fromunicode, a.tounicode())
            self.assertEqual(m.tobytes(), expected)
        self.assertRaises(BufferError, operator.imul, a, 2)
        self.assertEqual(m.tobytes(), expected)
        self.assertRaises(BufferError, operator.imul, a, 0)
        self.assertEqual(m.tobytes(), expected)
        self.assertRaises(BufferError, operator.setitem, a, slice(0, 0), a)
        self.assertEqual(m.tobytes(), expected)
        self.assertRaises(BufferError, operator.delitem, a, 0)
        self.assertEqual(m.tobytes(), expected)
        self.assertRaises(BufferError, operator.delitem, a, slice(0, 1))
        self.assertEqual(m.tobytes(), expected) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:36,代碼來源:test_array.py

示例8: test_imul_scalar

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def test_imul_scalar(self):
        self.check_array_scalar_op(operator.imul) 
開發者ID:cupy,項目名稱:cupy,代碼行數:4,代碼來源:test_ndarray_elementwise_op.py

示例9: test_imul_array

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def test_imul_array(self):
        self.check_array_array_op(operator.imul) 
開發者ID:cupy,項目名稱:cupy,代碼行數:4,代碼來源:test_ndarray_elementwise_op.py

示例10: test_broadcasted_imul

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def test_broadcasted_imul(self):
        self.check_array_broadcasted_op(operator.imul) 
開發者ID:cupy,項目名稱:cupy,代碼行數:4,代碼來源:test_ndarray_elementwise_op.py

示例11: _test_quantity_imul_idiv

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def _test_quantity_imul_idiv(self, unit, func):
        #func(op.imul, 10.0, '4.2*meter', '42*meter')
        func(op.imul, '4.2*meter', 10.0, '42*meter', unit)
        func(op.imul, '4.2*meter', '10*inch', '42*meter*inch', unit)
        #func(op.truediv, 42, '4.2*meter', '10/meter')
        func(op.itruediv, '4.2*meter', unit * 10.0, '0.42*meter', unit)
        func(op.itruediv, '4.2*meter', '10*inch', '0.42*meter/inch', unit) 
開發者ID:jmwright,項目名稱:cadquery-freecad-module,代碼行數:9,代碼來源:test_quantity.py

示例12: test_issue52

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def test_issue52(self):
        u1 = UnitRegistry()
        u2 = UnitRegistry()
        q1 = u1.meter
        q2 = u2.meter
        import operator as op
        for fun in (op.add, op.iadd,
                    op.sub, op.isub,
                    op.mul, op.imul,
                    op.floordiv, op.ifloordiv,
                    op.truediv, op.itruediv):
            self.assertRaises(ValueError, fun, q1, q2) 
開發者ID:jmwright,項目名稱:cadquery-freecad-module,代碼行數:14,代碼來源:test_issues.py

示例13: test_unitcontainer_arithmetic

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def test_unitcontainer_arithmetic(self):
        x = UnitsContainer(meter=1)
        y = UnitsContainer(second=1)
        z = UnitsContainer(meter=1, second=-2)

        self._test_not_inplace(op.mul, x, y, UnitsContainer(meter=1, second=1))
        self._test_not_inplace(op.truediv, x, y, UnitsContainer(meter=1, second=-1))
        self._test_not_inplace(op.pow, z, 2, UnitsContainer(meter=2, second=-4))
        self._test_not_inplace(op.pow, z, -2, UnitsContainer(meter=-2, second=4))

        self._test_inplace(op.imul, x, y, UnitsContainer(meter=1, second=1))
        self._test_inplace(op.itruediv, x, y, UnitsContainer(meter=1, second=-1))
        self._test_inplace(op.ipow, z, 2, UnitsContainer(meter=2, second=-4))
        self._test_inplace(op.ipow, z, -2, UnitsContainer(meter=-2, second=4)) 
開發者ID:jmwright,項目名稱:cadquery-freecad-module,代碼行數:16,代碼來源:test_unit.py

示例14: __imul__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def __imul__(self, other):
        if not isinstance(self._magnitude, ndarray):
            return self._mul_div(other, operator.mul)
        else:
            return self._imul_div(other, operator.imul) 
開發者ID:jmwright,項目名稱:cadquery-freecad-module,代碼行數:7,代碼來源:quantity.py

示例15: _test_errors

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import imul [as 別名]
def _test_errors(self, poly):
        self.assertRaises(ValueError, poly.from_terms, 'x**2')
        self.assertRaises(TypeError, poly, 0.1)
        self.assertRaises(TypeError, poly, gfpx.GFpX(257)(0))
        self.assertRaises(ValueError, poly, [poly.p])
        self.assertRaises(TypeError, operator.add, poly(0), 0.1)
        self.assertRaises(TypeError, operator.iadd, poly(0), 0.1)
        self.assertRaises(TypeError, operator.sub, poly(0), 0.1)
        self.assertRaises(TypeError, operator.sub, 0.1, poly(0))
        self.assertRaises(TypeError, operator.isub, poly(0), 0.1)
        self.assertRaises(TypeError, operator.mul, poly(0), 0.1)
        self.assertRaises(TypeError, operator.imul, poly(0), 0.1)
        self.assertRaises(TypeError, operator.lshift, poly(0), 0.1)
        self.assertRaises(TypeError, operator.lshift, 0.1, poly(0))
        self.assertRaises(TypeError, operator.ilshift, poly(0), 0.1)
        self.assertRaises(TypeError, operator.rshift, poly(0), 0.1)
        self.assertRaises(TypeError, operator.rshift, 0.1, poly(0))
        self.assertRaises(TypeError, operator.irshift, poly(0), 0.1)
        self.assertRaises(TypeError, operator.floordiv, poly(0), 0.1)
        self.assertRaises(TypeError, operator.floordiv, 0.1, poly(0))
        self.assertRaises(TypeError, operator.ifloordiv, poly(0), 0.1)
        self.assertRaises(TypeError, operator.mod, poly(0), 0.1)
        self.assertRaises(TypeError, operator.mod, 0.1, poly(0))
        self.assertRaises(TypeError, operator.imod, poly(0), 0.1)
        self.assertRaises(TypeError, divmod, poly(0), 0.1)
        self.assertRaises(TypeError, divmod, 0.1, poly(0))
        self.assertRaises(TypeError, operator.lt, poly(0), 0.1)
        self.assertRaises(TypeError, operator.lt, 0.1, poly(0))  # NB: tests >
        self.assertRaises(TypeError, operator.le, poly(0), 0.1)
        self.assertRaises(TypeError, operator.le, 0.1, poly(0))  # NB: tests <
        self.assertRaises(ZeroDivisionError, poly.invert, poly(283), poly(0))
        self.assertRaises(ZeroDivisionError, poly.invert, poly(283), poly(283))
        self.assertRaises(ZeroDivisionError, poly.mod, poly(283), poly(0))
        self.assertRaises(ZeroDivisionError, poly.divmod, poly(283), poly(0))
        self.assertRaises(ValueError, operator.pow, poly(3), -16) 
開發者ID:lschoe,項目名稱:mpyc,代碼行數:37,代碼來源:test_gfpx.py


注:本文中的operator.imul方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。