コード例 #1
0
 def operator_ifloordiv2(size):
     a = Array(size, 'double')
     b = Array(size, 'double')
     for i in range(size):
         a[i] = nb_types.double(i+10)
         b[i] = nb_types.double(i+3)
     operator.ifloordiv(a, b)
     return a
コード例 #2
0
 def operator_ifloordiv(size):
     a = Array(size, 'int32')
     b = Array(size, 'int32')
     for i in range(size):
         a[i] = nb_types.int32(i+10)
         b[i] = nb_types.int32(i+3)
     operator.ifloordiv(a, b)
     return a
コード例 #3
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")
コード例 #4
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")
コード例 #5
0
    def test_class_binary_inplace_operators(self):
        class WithLotsOfOperators(Class):
            def __iadd__(self, other):
                return (self, "iadd", other)

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

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

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

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

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

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

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

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

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

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

            def __imatmul__(self, other):
                return (self, "imatmul", other)

        c = WithLotsOfOperators()

        self.assertEqual(operator.iadd(c, 0), (c, "iadd", 0))
        self.assertEqual(operator.isub(c, 0), (c, "isub", 0))
        self.assertEqual(operator.imul(c, 0), (c, "imul", 0))
        self.assertEqual(operator.imod(c, 0), (c, "imod", 0))
        self.assertEqual(operator.itruediv(c, 0), (c, "itruediv", 0))
        self.assertEqual(operator.ifloordiv(c, 0), (c, "ifloordiv", 0))
        self.assertEqual(operator.ilshift(c, 0), (c, "ilshift", 0))
        self.assertEqual(operator.irshift(c, 0), (c, "irshift", 0))
        self.assertEqual(operator.ior(c, 0), (c, "ior", 0))
        self.assertEqual(operator.iand(c, 0), (c, "iand", 0))
        self.assertEqual(operator.ixor(c, 0), (c, "ixor", 0))
        self.assertEqual(operator.imatmul(c, 0), (c, "imatmul", 0))
コード例 #6
0
 def _test_quantity_floordiv(self, unit, func):
     a = self.Q_("10*meter")
     b = self.Q_("3*second")
     with pytest.raises(DimensionalityError):
         op.floordiv(a, b)
     with pytest.raises(DimensionalityError):
         op.floordiv(self.NON_INT_TYPE("3"), b)
     with pytest.raises(DimensionalityError):
         op.floordiv(a, self.NON_INT_TYPE("3"))
     with pytest.raises(DimensionalityError):
         op.ifloordiv(a, b)
     with pytest.raises(DimensionalityError):
         op.ifloordiv(self.NON_INT_TYPE("3"), b)
     with pytest.raises(DimensionalityError):
         op.ifloordiv(a, self.NON_INT_TYPE("3"))
     func(
         op.floordiv,
         unit * self.NON_INT_TYPE("10"),
         "4.2*meter/meter",
         self.NON_INT_TYPE("2"),
         unit,
     )
     func(op.floordiv, "10*meter", "4.2*inch", self.NON_INT_TYPE("93"),
          unit)
コード例 #7
0
ファイル: test_operators.py プロジェクト: GaZ3ll3/numba
 def ifloordiv_usecase(x, y):
     return operator.ifloordiv(x, y)
コード例 #8
0
ファイル: test_operators.py プロジェクト: menghaozhu/hat
 def ifloordiv_usecase(x, y):
     return operator.ifloordiv(x, y)
コード例 #9
0
ファイル: operator_demo.py プロジェクト: sjl421/Python_Lib
a = 8
b = operator.ixor(a, 1)
print a
print b

#将与自身相除取整的值赋给自身 同 /=
#但是不改变自身的值,返回值返回相除的结果
a = 9
b = operator.idiv(a, 4)
print a
print b

#将与自身相除取整的值赋给自身 同 //=
#但是不改变自身的值,返回值返回相除的结果
a = 9.04
b = operator.ifloordiv(a, 4)
print a
print b

#将与自身相移位的值赋给自身 同 <<=
#但是不改变自身的值,返回值返回移位的结果
a = 3
b = operator.ilshift(3, 2)
print a
print b

#将与自身相移位的值赋给自身 同 >>=
#但是不改变自身的值,返回值返回移位的结果
a = 3
b = operator.irshift(3, 2)
print a
コード例 #10
0
 def update_event(self, inp=-1):
     self.set_output_val(0, operator.ifloordiv(self.input(0),
                                               self.input(1)))
コード例 #11
0
ファイル: operator_demo.py プロジェクト: windard/Python_Lib
a = 8
b = operator.ixor(a,1)
print a
print b

#将与自身相除取整的值赋给自身 同 /=
#但是不改变自身的值,返回值返回相除的结果
a = 9
b = operator.idiv(a,4)
print a
print b

#将与自身相除取整的值赋给自身 同 //=
#但是不改变自身的值,返回值返回相除的结果
a = 9.04
b = operator.ifloordiv(a,4)
print a
print b

#将与自身相移位的值赋给自身 同 <<=
#但是不改变自身的值,返回值返回移位的结果
a = 3
b = operator.ilshift(3,2)
print a
print b

#将与自身相移位的值赋给自身 同 >>=
#但是不改变自身的值,返回值返回移位的结果
a = 3
b = operator.irshift(3,2)
print a
コード例 #12
0
#!/usr/bin/env python

import cytoolz.curried as cc
import itertools as it
from pprint import pprint as pp
import sys
import operator as op

data_input = cc.pipe(sys.stdin.readlines(),
                     cc.map(lambda x: x.replace('\n', '')), list)


def evenly_divisible_pair(num_line):
    for (n1, n2) in it.product(num_line, num_line):
        if n1 != n2:
            if n1 % n2 == 0:
                return (n1, n2)
            elif n2 % n1 == 0:
                return (n2, n1)


answer = cc.pipe(data_input, cc.map(str.split), lambda x:
                 (cc.map(int, row) for row in x), cc.map(list),
                 cc.map(evenly_divisible_pair),
                 cc.map(lambda x: op.ifloordiv(*x)), sum)

pp(answer)