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

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

项目:npstreams    作者:LaurentRDC    | 项目源码 | 文件源码
def csum(arrays, dtype = None, ignore_nan = False):
    """ 
    CUDA-enabled sum of stream of arrays. Arrays are summed along 
    the streaming axis for performance reasons. 

    Parameters
    ----------
    arrays : iterable
        Arrays to be summed. 
    ignore_nan : bool, optional
        If True, NaNs are ignored. Default is propagation of NaNs.

    Returns
    -------
    cuda_sum : ndarray

    See Also
    --------
    isum : streaming sum of array elements, possibly along different axes
    """
    return cuda_inplace_reduce(arrays, operator = iadd, dtype = dtype, 
                               ignore_nan = ignore_nan, identity = 0)
项目:deb-python-pint    作者:openstack    | 项目源码 | 文件源码
def _test_quantity_iadd_isub(self, unit, func):
        x = self.Q_(unit, 'centimeter')
        y = self.Q_(unit, 'inch')
        z = self.Q_(unit, 'second')
        a = self.Q_(unit, None)

        func(op.iadd, x, x, self.Q_(unit + unit, 'centimeter'))
        func(op.iadd, x, y, self.Q_(unit + 2.54 * unit, 'centimeter'))
        func(op.iadd, y, x, self.Q_(unit + unit / 2.54, 'inch'))
        func(op.iadd, a, unit, self.Q_(unit + unit, None))
        self.assertRaises(DimensionalityError, op.iadd, 10, x)
        self.assertRaises(DimensionalityError, op.iadd, x, 10)
        self.assertRaises(DimensionalityError, op.iadd, x, z)

        func(op.isub, x, x, self.Q_(unit - unit, 'centimeter'))
        func(op.isub, x, y, self.Q_(unit - 2.54, 'centimeter'))
        func(op.isub, y, x, self.Q_(unit - unit / 2.54, 'inch'))
        func(op.isub, a, unit, self.Q_(unit - unit, None))
        self.assertRaises(DimensionalityError, op.sub, 10, x)
        self.assertRaises(DimensionalityError, op.sub, x, 10)
        self.assertRaises(DimensionalityError, op.sub, x, z)
项目:deb-python-pint    作者:openstack    | 项目源码 | 文件源码
def test_inplace_addition(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.iadd, q1_cp, q2)
        else:
            expected = np.array([expected[0]]*2, dtype=np.float), expected[1]
            self.assertEqual(op.iadd(q1_cp, q2).units, Q_(*expected).units)
            q1_cp = copy.copy(q1)
            self.assertQuantityAlmostEqual(op.iadd(q1_cp, q2), Q_(*expected),
                                           atol=0.01)
项目:memex-dossier-open    作者:dossier    | 项目源码 | 文件源码
def __iadd__(self, other):
        '''
        In-place add features from two FeatureCollections.

        >>> fc1 = FeatureCollection({'foo': Counter('abbb')})
        >>> fc2 = FeatureCollection({'foo': Counter('bcc')})
        >>> fc1 += fc2
        FeatureCollection({'foo': Counter({'b': 4, 'c': 2, 'a': 1})})

        Note that if a feature in either of the collections is not an
        instance of :class:`collections.Counter`, then it is ignored.
        '''
        if self.read_only:
            raise ReadOnlyException()
        fc = self.merge_with(other, operator.iadd)
        self._features = fc._features
        return self
项目:deb-python-pint    作者:openstack    | 项目源码 | 文件源码
def __iadd__(self, other):
        if isinstance(other, datetime.datetime):
            return self.to_timedelta() + other
        elif not isinstance(self._magnitude, ndarray):
            return self._add_sub(other, operator.add)
        else:
            return self._iadd_sub(other, operator.iadd)
项目:deb-python-pint    作者:openstack    | 项目源码 | 文件源码
def test_issue52(self):
        u1 = UnitRegistry()
        u2 = UnitRegistry()
        q1 = 1*u1.meter
        q2 = 1*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)
项目:deb-python-pint    作者:openstack    | 项目源码 | 文件源码
def operate(self, items, op=operator.iadd, cleanup=True):
        d = udict(self._d)
        for key, value in items:
            d[key] = op(d[key], value)

        if cleanup:
            keys = [key for key, value in d.items() if value == 0]
            for key in keys:
                del d[key]

        return self.__class__(self.scale, d)
项目:centos-base-consul    作者:zeroc0d3lab    | 项目源码 | 文件源码
def hl_join(segments):
        return reduce(operator.iadd, segments, [])
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_iadd_scalar(self):
        self.check_array_scalar_op(operator.iadd)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_iadd_array(self):
        self.check_array_array_op(operator.iadd)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_broadcasted_iadd(self):
        self.check_array_broadcasted_op(operator.iadd)
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def as_list(self):
        """Very efficiently convert the SortedList to a list."""
        return reduce(iadd, self._lists, [])
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def as_list(self):
        """Very efficiently convert the SortedList to a list."""
        return reduce(iadd, self._lists, [])
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def as_list(self):
        """Very efficiently convert the SortedList to a list."""
        return reduce(iadd, self._lists, [])
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def as_list(self):
        """Very efficiently convert the SortedList to a list."""
        return reduce(iadd, self._lists, [])
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def test_iadd_scalar(self):
        self.check_array_scalar_op(operator.iadd)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def test_iadd_array(self):
        self.check_array_array_op(operator.iadd)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def test_broadcasted_iadd(self):
        self.check_array_broadcasted_op(operator.iadd)
项目:splunk_ta_ps4_f1_2016    作者:jonathanvarley    | 项目源码 | 文件源码
def __add__(self, that):
        """
        Return a new sorted list containing all the elements in *self* and
        *that*. Elements in *that* do not need to be properly ordered with
        respect to *self*.
        """
        values = reduce(iadd, self._lists, [])
        values.extend(that)
        return self.__class__(values, load=self._load)
项目:splunk_ta_ps4_f1_2016    作者:jonathanvarley    | 项目源码 | 文件源码
def __mul__(self, that):
        """
        Return a new sorted list containing *that* shallow copies of each item
        in SortedList.
        """
        values = reduce(iadd, self._lists, []) * that
        return self.__class__(values, load=self._load)
项目:splunk_ta_ps4_f1_2016    作者:jonathanvarley    | 项目源码 | 文件源码
def __imul__(self, that):
        """
        Increase the length of the list by appending *that* shallow copies of
        each item.
        """
        values = reduce(iadd, self._lists, []) * that
        self._clear()
        self._update(values)
        return self
项目:splunk_ta_ps4_f1_2016    作者:jonathanvarley    | 项目源码 | 文件源码
def __add__(self, that):
        """
        Return a new sorted list containing all the elements in *self* and
        *that*. Elements in *that* do not need to be properly ordered with
        respect to *self*.
        """
        values = reduce(iadd, self._lists, [])
        values.extend(that)
        return self.__class__(values, key=self._key, load=self._load)
项目:splunk_ta_ps4_f1_2016    作者:jonathanvarley    | 项目源码 | 文件源码
def __imul__(self, that):
        """
        Increase the length of the list by appending *that* shallow copies of
        each item.
        """
        values = reduce(iadd, self._lists, []) * that
        self._clear()
        self._update(values)
        return self
项目:splunk_ta_ps4_f1_2016    作者:jonathanvarley    | 项目源码 | 文件源码
def __add__(self, that):
        """
        Return a new sorted list containing all the elements in *self* and
        *that*. Elements in *that* do not need to be properly ordered with
        respect to *self*.
        """
        values = reduce(iadd, self._lists, [])
        values.extend(that)
        return self.__class__(values, load=self._load)
项目:splunk_ta_ps4_f1_2016    作者:jonathanvarley    | 项目源码 | 文件源码
def __mul__(self, that):
        """
        Return a new sorted list containing *that* shallow copies of each item
        in SortedList.
        """
        values = reduce(iadd, self._lists, []) * that
        return self.__class__(values, load=self._load)
项目:splunk_ta_ps4_f1_2016    作者:jonathanvarley    | 项目源码 | 文件源码
def __imul__(self, that):
        """
        Increase the length of the list by appending *that* shallow copies of
        each item.
        """
        values = reduce(iadd, self._lists, []) * that
        self._clear()
        self._update(values)
        return self
项目:splunk_ta_ps4_f1_2016    作者:jonathanvarley    | 项目源码 | 文件源码
def __mul__(self, that):
        """
        Return a new sorted list containing *that* shallow copies of each item
        in SortedListWithKey.
        """
        values = reduce(iadd, self._lists, []) * that
        return self.__class__(values, key=self._key, load=self._load)
项目:splunk_ta_ps4_f1_2016    作者:jonathanvarley    | 项目源码 | 文件源码
def __imul__(self, that):
        """
        Increase the length of the list by appending *that* shallow copies of
        each item.
        """
        values = reduce(iadd, self._lists, []) * that
        self._clear()
        self._update(values)
        return self
项目:TA-SyncKVStore    作者:georgestarcher    | 项目源码 | 文件源码
def __add__(self, that):
        """
        Return a new sorted list containing all the elements in *self* and
        *that*. Elements in *that* do not need to be properly ordered with
        respect to *self*.
        """
        values = reduce(iadd, self._lists, [])
        values.extend(that)
        return self.__class__(values, load=self._load)
项目:TA-SyncKVStore    作者:georgestarcher    | 项目源码 | 文件源码
def __mul__(self, that):
        """
        Return a new sorted list containing *that* shallow copies of each item
        in SortedList.
        """
        values = reduce(iadd, self._lists, []) * that
        return self.__class__(values, load=self._load)
项目:TA-SyncKVStore    作者:georgestarcher    | 项目源码 | 文件源码
def __imul__(self, that):
        """
        Increase the length of the list by appending *that* shallow copies of
        each item.
        """
        values = reduce(iadd, self._lists, []) * that
        self._clear()
        self._update(values)
        return self
项目:TA-SyncKVStore    作者:georgestarcher    | 项目源码 | 文件源码
def __add__(self, that):
        """
        Return a new sorted list containing all the elements in *self* and
        *that*. Elements in *that* do not need to be properly ordered with
        respect to *self*.
        """
        values = reduce(iadd, self._lists, [])
        values.extend(that)
        return self.__class__(values, key=self._key, load=self._load)
项目:TA-SyncKVStore    作者:georgestarcher    | 项目源码 | 文件源码
def __imul__(self, that):
        """
        Increase the length of the list by appending *that* shallow copies of
        each item.
        """
        values = reduce(iadd, self._lists, []) * that
        self._clear()
        self._update(values)
        return self
项目:TA-SyncKVStore    作者:georgestarcher    | 项目源码 | 文件源码
def __add__(self, that):
        """
        Return a new sorted list containing all the elements in *self* and
        *that*. Elements in *that* do not need to be properly ordered with
        respect to *self*.
        """
        values = reduce(iadd, self._lists, [])
        values.extend(that)
        return self.__class__(values, load=self._load)
项目:TA-SyncKVStore    作者:georgestarcher    | 项目源码 | 文件源码
def __mul__(self, that):
        """
        Return a new sorted list containing *that* shallow copies of each item
        in SortedList.
        """
        values = reduce(iadd, self._lists, []) * that
        return self.__class__(values, load=self._load)
项目:TA-SyncKVStore    作者:georgestarcher    | 项目源码 | 文件源码
def __imul__(self, that):
        """
        Increase the length of the list by appending *that* shallow copies of
        each item.
        """
        values = reduce(iadd, self._lists, []) * that
        self._clear()
        self._update(values)
        return self
项目:TA-SyncKVStore    作者:georgestarcher    | 项目源码 | 文件源码
def __mul__(self, that):
        """
        Return a new sorted list containing *that* shallow copies of each item
        in SortedListWithKey.
        """
        values = reduce(iadd, self._lists, []) * that
        return self.__class__(values, key=self._key, load=self._load)
项目:TA-SyncKVStore    作者:georgestarcher    | 项目源码 | 文件源码
def __imul__(self, that):
        """
        Increase the length of the list by appending *that* shallow copies of
        each item.
        """
        values = reduce(iadd, self._lists, []) * that
        self._clear()
        self._update(values)
        return self
项目:cb-defense-splunk-app    作者:carbonblack    | 项目源码 | 文件源码
def __add__(self, that):
        """
        Return a new sorted list containing all the elements in *self* and
        *that*. Elements in *that* do not need to be properly ordered with
        respect to *self*.
        """
        values = reduce(iadd, self._lists, [])
        values.extend(that)
        return self.__class__(values, load=self._load)
项目:cb-defense-splunk-app    作者:carbonblack    | 项目源码 | 文件源码
def __mul__(self, that):
        """
        Return a new sorted list containing *that* shallow copies of each item
        in SortedList.
        """
        values = reduce(iadd, self._lists, []) * that
        return self.__class__(values, load=self._load)
项目:cb-defense-splunk-app    作者:carbonblack    | 项目源码 | 文件源码
def __imul__(self, that):
        """
        Increase the length of the list by appending *that* shallow copies of
        each item.
        """
        values = reduce(iadd, self._lists, []) * that
        self._clear()
        self._update(values)
        return self
项目:cb-defense-splunk-app    作者:carbonblack    | 项目源码 | 文件源码
def __add__(self, that):
        """
        Return a new sorted list containing all the elements in *self* and
        *that*. Elements in *that* do not need to be properly ordered with
        respect to *self*.
        """
        values = reduce(iadd, self._lists, [])
        values.extend(that)
        return self.__class__(values, key=self._key, load=self._load)
项目:cb-defense-splunk-app    作者:carbonblack    | 项目源码 | 文件源码
def __imul__(self, that):
        """
        Increase the length of the list by appending *that* shallow copies of
        each item.
        """
        values = reduce(iadd, self._lists, []) * that
        self._clear()
        self._update(values)
        return self
项目:cb-defense-splunk-app    作者:carbonblack    | 项目源码 | 文件源码
def __add__(self, that):
        """
        Return a new sorted list containing all the elements in *self* and
        *that*. Elements in *that* do not need to be properly ordered with
        respect to *self*.
        """
        values = reduce(iadd, self._lists, [])
        values.extend(that)
        return self.__class__(values, load=self._load)
项目:cb-defense-splunk-app    作者:carbonblack    | 项目源码 | 文件源码
def __mul__(self, that):
        """
        Return a new sorted list containing *that* shallow copies of each item
        in SortedList.
        """
        values = reduce(iadd, self._lists, []) * that
        return self.__class__(values, load=self._load)
项目:cb-defense-splunk-app    作者:carbonblack    | 项目源码 | 文件源码
def __imul__(self, that):
        """
        Increase the length of the list by appending *that* shallow copies of
        each item.
        """
        values = reduce(iadd, self._lists, []) * that
        self._clear()
        self._update(values)
        return self
项目:cb-defense-splunk-app    作者:carbonblack    | 项目源码 | 文件源码
def __mul__(self, that):
        """
        Return a new sorted list containing *that* shallow copies of each item
        in SortedListWithKey.
        """
        values = reduce(iadd, self._lists, []) * that
        return self.__class__(values, key=self._key, load=self._load)
项目:cb-defense-splunk-app    作者:carbonblack    | 项目源码 | 文件源码
def __imul__(self, that):
        """
        Increase the length of the list by appending *that* shallow copies of
        each item.
        """
        values = reduce(iadd, self._lists, []) * that
        self._clear()
        self._update(values)
        return self
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def as_list(self):
        """Very efficiently convert the SortedList to a list."""
        return reduce(iadd, self._lists, [])
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def as_list(self):
        """Very efficiently convert the SortedList to a list."""
        return reduce(iadd, self._lists, [])