コード例 #1
0
    def test_inplace_exponentiation(self, input_tuple, expected):
        self.ureg.default_as_delta = False
        in1, in2 = input_tuple
        if type(in1) is tuple and type(in2) is tuple:
            (q1v, q1u), (q2v, q2u) = in1, in2
            in1 = self.Q_(*(np.array([q1v] * 2, dtype=np.float), q1u))
            in2 = self.Q_(q2v, q2u)
        elif not type(in1) is tuple and type(in2) is tuple:
            in2 = self.Q_(*in2)
        else:
            in1 = self.Q_(*in1)

        input_tuple = in1, in2

        expected_copy = expected[:]
        for i, mode in enumerate([False, True]):
            self.ureg.autoconvert_offset_to_baseunit = mode
            in1_cp = copy.copy(in1)
            if expected_copy[i] == 'error':
                self.assertRaises(
                    (OffsetUnitCalculusError, DimensionalityError), op.ipow,
                    in1_cp, in2)
            else:
                if type(expected_copy[i]) is tuple:
                    expected = self.Q_(
                        np.array([expected_copy[i][0]] * 2, dtype=np.float),
                        expected_copy[i][1])
                    self.assertEqual(
                        op.ipow(in1_cp, in2).units, expected.units)
                else:
                    expected = np.array([expected_copy[i]] * 2, dtype=np.float)

                in1_cp = copy.copy(in1)
                self.assertQuantityAlmostEqual(op.ipow(in1_cp, in2), expected)
コード例 #2
0
ファイル: test_quantity.py プロジェクト: emilienkofman/pint
    def test_inplace_exponentiation(self, input_tuple, expected):
        self.ureg.default_as_delta = False
        in1, in2 = input_tuple
        if type(in1) is tuple and type(in2) is tuple:
            (q1v, q1u), (q2v, q2u) = in1, in2
            in1 = self.Q_(*(np.array([q1v]*2, dtype=np.float), q1u))
            in2 = self.Q_(q2v, q2u)
        elif not type(in1) is tuple and type(in2) is tuple:
            in2 = self.Q_(*in2)
        else:
            in1 = self.Q_(*in1)

        input_tuple = in1, in2

        expected_copy = expected[:]
        for i, mode in enumerate([False, True]):
            self.ureg.autoconvert_offset_to_baseunit = mode
            in1_cp = copy.copy(in1)
            if expected_copy[i] == 'error':
                self.assertRaises((OffsetUnitCalculusError,
                                   DimensionalityError), op.ipow, in1_cp, in2)
            else:
                if type(expected_copy[i]) is tuple:
                    expected = self.Q_(np.array([expected_copy[i][0]]*2,
                                                dtype=np.float),
                                       expected_copy[i][1])
                    self.assertEqual(op.ipow(in1_cp, in2).units, expected.units)
                else:
                    expected = np.array([expected_copy[i]]*2, dtype=np.float)


                in1_cp = copy.copy(in1)
                self.assertQuantityAlmostEqual(op.ipow(in1_cp, in2), expected)
コード例 #3
0
 def operator_ipow(size):
     a = Array(size, 'int32')
     b = Array(size, 'int32')
     for i in range(size):
         a[i] = nb_types.int32(i+1)
         b[i] = nb_types.int32(size-i)
     operator.ipow(a, b)
     return a
コード例 #4
0
ファイル: test_numpy.py プロジェクト: wiki01/pint
 def test_exponentiation_array_exp_2(self):
     arr = np.array(range(3), dtype=np.float)
     # q = self.Q_(copy.copy(arr), None)
     q = self.Q_(copy.copy(arr), "meter")
     arr_cp = copy.copy(arr)
     q_cp = copy.copy(q)
     # this fails as expected since numpy 1.8.0 but...
     with pytest.raises(DimensionalityError):
         op.pow(arr_cp, q_cp)
     # ..not for op.ipow !
     # q_cp is treated as if it is an array. The units are ignored.
     # Quantity.__ipow__ is never called
     arr_cp = copy.copy(arr)
     q_cp = copy.copy(q)
     with pytest.raises(DimensionalityError):
         op.ipow(arr_cp, q_cp)
コード例 #5
0
ファイル: test_operator.py プロジェクト: 0xBADCA7/grumpy
 def test_inplace(self):
     #operator = self.module
     class C(object):
         def __iadd__     (self, other): return "iadd"
         def __iand__     (self, other): return "iand"
         def __ifloordiv__(self, other): return "ifloordiv"
         def __ilshift__  (self, other): return "ilshift"
         def __imod__     (self, other): return "imod"
         def __imul__     (self, other): return "imul"
         def __ior__      (self, other): return "ior"
         def __ipow__     (self, other): return "ipow"
         def __irshift__  (self, other): return "irshift"
         def __isub__     (self, other): return "isub"
         def __itruediv__ (self, other): return "itruediv"
         def __ixor__     (self, other): return "ixor"
         def __getitem__(self, other): return 5  # so that C is a sequence
     c = C()
     self.assertEqual(operator.iadd     (c, 5), "iadd")
     self.assertEqual(operator.iand     (c, 5), "iand")
     self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv")
     self.assertEqual(operator.ilshift  (c, 5), "ilshift")
     self.assertEqual(operator.imod     (c, 5), "imod")
     self.assertEqual(operator.imul     (c, 5), "imul")
     self.assertEqual(operator.ior      (c, 5), "ior")
     self.assertEqual(operator.ipow     (c, 5), "ipow")
     self.assertEqual(operator.irshift  (c, 5), "irshift")
     self.assertEqual(operator.isub     (c, 5), "isub")
     self.assertEqual(operator.itruediv (c, 5), "itruediv")
     self.assertEqual(operator.ixor     (c, 5), "ixor")
     self.assertEqual(operator.iconcat  (c, c), "iadd")
コード例 #6
0
def main():

    x,y = 5,6
    a,b = 7,8

    # Incremental Add : x += y
    iAdd = operator.iadd(5, 6)
    print("iAdd: ", iAdd)

    # Incremental Concatenate
    iConCat = operator.iconcat("Hello", "World")
    print("iConCat:", iConCat)

    # Incremental Subtraction
    iSub = operator.isub(5, 6)
    print("iSub: ", iSub)

    # Incremental Multiplication
    iMul = operator.imul(5,6)
    print("iMul:", iMul)

    # Incremental Division
    iDiv = operator.itruediv(10, 5)
    print("iDiv: ", iDiv)

    # Incremental Modulus
    iMod = operator.imod(10, 6)
    print("iMod: ", iMod)

    # Incremental Exponential
    iPow = operator.ipow(2, 4)
    print("iPow: ", iPow)
コード例 #7
0
    def test_inplace(self):
        #operator = self.module
        class C(object):
            def __iadd__(self, other):
                return "iadd"

            def __iand__(self, other):
                return "iand"

            def __ifloordiv__(self, other):
                return "ifloordiv"

            def __ilshift__(self, other):
                return "ilshift"

            def __imod__(self, other):
                return "imod"

            def __imul__(self, other):
                return "imul"

            def __ior__(self, other):
                return "ior"

            def __ipow__(self, other):
                return "ipow"

            def __irshift__(self, other):
                return "irshift"

            def __isub__(self, other):
                return "isub"

            def __itruediv__(self, other):
                return "itruediv"

            def __ixor__(self, other):
                return "ixor"

            def __getitem__(self, other):
                return 5  # so that C is a sequence

        c = C()
        self.assertEqual(operator.iadd(c, 5), "iadd")
        self.assertEqual(operator.iand(c, 5), "iand")
        self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv")
        self.assertEqual(operator.ilshift(c, 5), "ilshift")
        self.assertEqual(operator.imod(c, 5), "imod")
        self.assertEqual(operator.imul(c, 5), "imul")
        self.assertEqual(operator.ior(c, 5), "ior")
        self.assertEqual(operator.ipow(c, 5), "ipow")
        self.assertEqual(operator.irshift(c, 5), "irshift")
        self.assertEqual(operator.isub(c, 5), "isub")
        self.assertEqual(operator.itruediv(c, 5), "itruediv")
        self.assertEqual(operator.ixor(c, 5), "ixor")
        self.assertEqual(operator.iconcat(c, c), "iadd")
コード例 #8
0
ファイル: quantity.py プロジェクト: felixhummel/pint
 def __pow__(self, other):
     ret = copy.copy(self)
     return operator.ipow(ret, other)
コード例 #9
0
 def check_broadcasted_ipow(self, xp, x_type, y_type):
     a = xp.array([[1, 2, 3], [4, 5, 6]], x_type)
     b = xp.array([[1], [2]], y_type)
     return operator.ipow(a, b)
コード例 #10
0
 def check_ipow_array(self, xp, x_type, y_type):
     a = xp.array([[1, 2, 3], [4, 5, 6]], x_type)
     b = xp.array([[6, 5, 4], [3, 2, 1]], y_type)
     return operator.ipow(a, b)
コード例 #11
0
 def check_ipow_scalar(self, xp, x_type, y_type):
     a = testing.shaped_arange((2, 3), xp, x_type)
     return operator.ipow(a, y_type(3))
コード例 #12
0
# Working of ixor() and ipow()

import operator
x = 10
y = 5

# using ixor() to exclusive or and assign value
x = operator.ixor(x, y)
print("The value after xoring and assigning : ", end="")
print(x)

# using ipow() to exponentiate and assign value
x = 5
y = 4
x = operator.ipow(x, y)
print("The value after exponentiating and assigning : ", end="")
print(x)

# using ior() to or, and assign value
x = 10
y = 5
x = operator.ior(x, y)
print("The value after bitwise or, and assigning : ", end="")
print(x)

x = 5
y = 4
x = operator.iand(x, y)
print("The value after bitwise and, and assigning : ", end="")
print(x)
コード例 #13
0
 def __ipow__(self, other, *args):
     return operator.ipow(self._wrapped(), other, *args)
コード例 #14
0
ファイル: quantity.py プロジェクト: tiagocoutinho/pint
 def __pow__(self, other):
     ret = copy.copy(self)
     return operator.ipow(ret, other)
コード例 #15
0
 def update_event(self, inp=-1):
     self.set_output_val(0, operator.ipow(self.input(0), self.input(1)))
コード例 #16
0
print(li)
operator.delitem(li, slice(1, 4))
print(li)
print(operator.getitem(li, slice(0, 2)))
s1 = "testing "
s2 = "operator"
print(operator.concat(s1, s2))
if (operator.contains(s1, s2)):
    print("Contains")
else:
    print("It doesn't")
a = 1
b = 0
print(operator.and_(a, b))
print(operator.or_(a, b))
print(operator.invert(a))

x = 10
y = 5
print(operator.iadd(x, y))
print(operator.isub(x, y))
print(operator.iconcat(s1, s2))
print(operator.imul(x, y))
print(operator.itruediv(x, y))
print(operator.imod(x, y))
print(operator.ixor(x, y))
print(operator.ipow(x, y))
print(operator.iand(x, y))
print(operator.ior(x, y))
print(operator.ilshift(x, y))
print(operator.irshift(x, y))
コード例 #17
0
 def check_broadcasted_ipow(self, xp, x_type, y_type):
     a = testing.shaped_arange((2, 3), dtype=x_type)
     b = testing.shaped_arange((2, 1), dtype=y_type)
     return operator.ipow(a, b)
コード例 #18
0
 def check_ipow_array(self, xp, x_type, y_type):
     a = testing.shaped_arange((2, 3), xp, x_type)
     b = testing.shaped_reverse_arange((2, 3), xp, y_type)
     return operator.ipow(a, b)
コード例 #19
0
 def check_ipow_scalar(self, xp, x_type, y_type):
     a = testing.shaped_arange((2, 3), xp, x_type)
     return operator.ipow(a, y_type(3))
コード例 #20
0
 def check_ipow_array(self, xp, x_type, y_type):
     a = testing.shaped_arange((2, 3), xp, x_type)
     b = testing.shaped_reverse_arange((2, 3), xp, y_type)
     return operator.ipow(a, b)
コード例 #21
0
print("the string after concatenation is : ", end="")
print(y)

x = operator.isub(2, 3)
print("the value after subtracting and assiging : ", end="")
print(x)

x = operator.imul(2, 3)
print("the value after multiplying and assiging : ", end="")
print(x)

x = operator.itruediv(2, 3)
print("the value after dividing and assign : ", end="")
print(x)

x = operator.ixor(10, 5)
print("the value after xoring and assigning : ", end="")
print(x)

x = operator.ipow(5, 4)
print("the value after exponentiating and assigning : ", end="")
print(x)

x = operator.ilshift(8, 2)
print("the value after bitwise left shift and assigning : ", end="")
print(x)

x = operator.irshift(8, 2)
print("the value after bitwise right shift and assigning : ", end="")
print(x)
コード例 #22
0
 def check_broadcasted_ipow(self, xp, x_type, y_type):
     a = xp.array([[1, 2, 3], [4, 5, 6]], x_type)
     b = xp.array([[1], [2]], y_type)
     return operator.ipow(a, b)
コード例 #23
0
b = 2
print(operator.imod(a, b))

"""7. ixor() :- This function is used to assign and xor the current value. This operation does “a^ = b” operation. Assigning is not performed in case of immutable
containers, such as strings, numbers and tuples."""

a = 1
b = 0
print(operator.ixor(a, b))

"""8.ipow() :- This function is used to assign and exponentiate the current value. This operation does “a ** = b” operation. Assigning is not performed in case of
immutable containers, such as strings, numbers and tuples."""

a = 3
b = 2
print(operator.ipow(a, b))

"""9.iand() :- This function is used to assign and bitwise and the current value. This operation does “a &= b” operation. Assigning is not performed in case of
immutable containers, such as strings, numbers and tuples"""

a = 1
b = 1
print(operator.iand(a, b))

"""10.ior()-  This function is used to assign and bitwise or the current value. This operation does “a |=b ” operation. Assigning is not performed in case of
immutable containers, such as strings, numbers and tuples."""
a = 5
b = 1
print(operator.ior(a, b))

"""11.ilshift()-This function is used to assign and bitwise leftshift the current value by second argument. This operation does “a <<=b ” operation. Assigning is not
コード例 #24
0
 def check_broadcasted_ipow(self, xp, x_type, y_type):
     a = testing.shaped_arange((2, 3), dtype=x_type)
     b = testing.shaped_arange((2, 1), dtype=y_type)
     return operator.ipow(a, b)
コード例 #25
0
ファイル: test_operators.py プロジェクト: GaZ3ll3/numba
 def ipow_usecase(x, y):
     return operator.ipow(x, y)
コード例 #26
0
def test_operator():
    my_assert(operator.add(2, 2) == 4, "add operator")
    my_assert(operator.ipow(3, 2) == 9, "ipow operator")
コード例 #27
0
 def check_ipow_array(self, xp, x_type, y_type):
     a = xp.array([[1, 2, 3], [4, 5, 6]], x_type)
     b = xp.array([[6, 5, 4], [3, 2, 1]], y_type)
     return operator.ipow(a, b)
コード例 #28
0
ファイル: test_operators.py プロジェクト: menghaozhu/hat
 def ipow_usecase(x, y):
     return operator.ipow(x, y)
コード例 #29
0
 def check_ipow_scalar(self, xp, x_type, y_type):
     a = xp.array([[1, 2, 3], [4, 5, 6]], x_type)
     return operator.ipow(a, y_type(3))
コード例 #30
0
 def check_ipow_scalar(self, xp, x_type, y_type):
     a = xp.array([[1, 2, 3], [4, 5, 6]], x_type)
     return operator.ipow(a, y_type(3))