当前位置: 首页>>代码示例>>Python>>正文


Python operator函数代码示例

本文整理汇总了Python中operator函数的典型用法代码示例。如果您正苦于以下问题:Python operator函数的具体用法?Python operator怎么用?Python operator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了operator函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _operator_on_other

 def _operator_on_other(self, other, operator):
     try:
         return Position(operator(self.x, other[0]),
                         operator(self.y, other[1]))
     except TypeError:
         return Position(operator(self.x, other),
                         operator(self.y, other))
开发者ID:Widdershin,项目名称:Scroll,代码行数:7,代码来源:helpers.py

示例2: limit_versions

def limit_versions(language, limit, operator):
    """
    Limits given languages with the given operator:

    :param language:
        A `Language` instance.
    :param limit:
        A number to limit the versions.
    :param operator:
        The operator to use for the limiting.
    :return:
        A new `Language` instance with limited versions.
    :raises ValueError:
        If no version is left anymore.
    """
    if isinstance(limit, int):
        versions = [version for version in language.versions
                    if operator(int(version), limit)]
    else:

        versions = [version for version in language.versions
                    if operator(version, limit)]
    if not versions:
        raise ValueError('No versions left')
    return type(language)(*versions)
开发者ID:arush0311,项目名称:coala,代码行数:25,代码来源:Language.py

示例3: _mul_div

 def _mul_div(self, other, operator):
     if isinstance(other, self.__class__):
         result = operator(self.value, other.value)
         return result.plus_minus((self.rel ** 2.0 + other.rel ** 2.0) ** (1/2), relative=True)
     else:
         result = operator(self.value, other)
         return result.plus_minus(abs(operator(self.error, other)))
开发者ID:Aircraft-Design-UniNa,项目名称:SUAVE,代码行数:7,代码来源:measurement.py

示例4: should_record_call

 def should_record_call(self):
     for operator in self.operators:
         left, right = Dingus.many(2)
         operator(left, right)
         operator_name_without_mangling = operator.__name__.replace('_', '')
         magic_method_name = '__%s__' % operator_name_without_mangling
         yield assert_call_was_logged, left, magic_method_name, right
开发者ID:Ciemaar,项目名称:dingus,代码行数:7,代码来源:test_dingus.py

示例5: test_device_ordering

 def test_device_ordering(self, context, operator):
     try:
         device = Device.from_path(context, "/devices/platform")
     except DeviceNotFoundAtPathError:
         pytest.skip("device not found")
     with pytest.raises(TypeError) as exc_info:
         operator(device, device)
     assert str(exc_info.value) == "Device not orderable"
开发者ID:bjornarg,项目名称:pyudev,代码行数:8,代码来源:test_device.py

示例6: edit

    def edit(self, activity, options):
        operator, delta = self._parse_time_delta(options.time)

        for lap in activity.laps:
            lap.start_time = operator(lap.start_time, delta)

            for trackpoint in lap.trackpoints:
                trackpoint.time = operator(trackpoint.time, delta)
开发者ID:K-Phoen,项目名称:runner,代码行数:8,代码来源:editor.py

示例7: test_rate_operator_negative_rate_full

    def test_rate_operator_negative_rate_full(self):
        from anuga.config import rho_a, rho_w, eta_w
        from math import pi, cos, sin

        a = [0.0, 0.0]
        b = [0.0, 2.0]
        c = [2.0, 0.0]
        d = [0.0, 4.0]
        e = [2.0, 2.0]
        f = [4.0, 0.0]

        points = [a, b, c, d, e, f]
        #             bac,     bce,     ecf,     dbe
        vertices = [[1, 0, 2], [1, 2, 4], [4, 2, 5], [3, 1, 4]]

        domain = Domain(points, vertices)

        # Flat surface with 1m of water
        domain.set_quantity("elevation", 0)
        domain.set_quantity("stage", 10.0)
        domain.set_quantity("friction", 0)

        Br = Reflective_boundary(domain)
        domain.set_boundary({"exterior": Br})

        #        print domain.quantities['elevation'].centroid_values
        #        print domain.quantities['stage'].centroid_values
        #        print domain.quantities['xmomentum'].centroid_values
        #        print domain.quantities['ymomentum'].centroid_values

        # Apply operator to these triangles
        indices = [0, 1, 3]

        # Catchment_Rain_Polygon = read_polygon(join('CatchmentBdy.csv'))
        # rainfall = file_function(join('1y120m.tms'), quantities=['rainfall'])
        rate = -1.0
        factor = 10.0
        default_rate = 0.0

        operator = Rate_operator(domain, rate=rate, factor=factor, indices=None, default_rate=default_rate)

        # Apply Operator
        domain.timestep = 2.0
        operator()

        stage_ex = [0.0, 0.0, 0.0, 0.0]
        step_integral = -80.0

        # print domain.quantities['elevation'].centroid_values
        # print domain.quantities['stage'].centroid_values
        # print domain.quantities['xmomentum'].centroid_values
        # print domain.quantities['ymomentum'].centroid_values
        # print domain.fractional_step_volume_integral

        assert num.allclose(domain.quantities["stage"].centroid_values, stage_ex)
        assert num.allclose(domain.quantities["xmomentum"].centroid_values, 0.0)
        assert num.allclose(domain.quantities["ymomentum"].centroid_values, 0.0)
        assert num.allclose(domain.fractional_step_volume_integral, step_integral)
开发者ID:pabryan,项目名称:anuga_core,代码行数:58,代码来源:test_rate_operators.py

示例8: combine

 def combine(self, other, operator):
   result = collections.defaultdict(fractions.Fraction)
   for x, px in self._dist.iteritems():
     if isinstance(other, self.__class__):
       for y, py in other._dist.iteritems():
         result[operator(x, y)] += px * py
     else:
       result[operator(x, other)] += px
   return self.__class__(result)
开发者ID:durandal42,项目名称:projects,代码行数:9,代码来源:distribution.py

示例9: end

    def end(operator, record, arg):
        logger.debug("comparing end times %r(%r, %r)", operator, record.endTime, arg)

        # We need a special-case for NULL endTime for conferences in progress
        if record.endTime is None:
            return operator(None, arg)

        end = arrow.get(record.endTime)
        if arg is None:
            return operator(end, None)
        return operator(end, _ReplayFilters._normalize_time_val(arg))
开发者ID:ajenta,项目名称:oydiv-rpc,代码行数:11,代码来源:replay.py

示例10: mod_karma

def mod_karma(thing, operator):
    thing = thing.strip()

    if thing in memory:
        memory[thing] = operator(memory[thing], 1)
    else:
        memory[thing] = operator(0, 1)

    log.info("%s's new karma: %s" % (thing, memory[thing]))
    with open( jsoned_memory, "wb" ) as f:
        json.dump( memory, f )
开发者ID:BBBSnowball,项目名称:edi,代码行数:11,代码来源:karma.py

示例11: test_rate_operator_simple

    def test_rate_operator_simple(self):
        from anuga.config import rho_a, rho_w, eta_w
        from math import pi, cos, sin

        a = [0.0, 0.0]
        b = [0.0, 2.0]
        c = [2.0, 0.0]
        d = [0.0, 4.0]
        e = [2.0, 2.0]
        f = [4.0, 0.0]

        points = [a, b, c, d, e, f]
        #             bac,     bce,     ecf,     dbe
        vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]

        domain = Domain(points, vertices)

        #Flat surface with 1m of water
        domain.set_quantity('elevation', 0)
        domain.set_quantity('stage', 1.0)
        domain.set_quantity('friction', 0)

        Br = Reflective_boundary(domain)
        domain.set_boundary({'exterior': Br})


#        print domain.quantities['stage'].centroid_values
#        print domain.quantities['xmomentum'].centroid_values
#        print domain.quantities['ymomentum'].centroid_values

        # Apply operator to these triangles
        indices = [0,1,3]

        rate = 1.0
        factor = 10.0
        default_rate= 0.0

        operator = Rate_operator(domain, rate=rate, factor=factor, \
                      indices=indices, default_rate = default_rate)
        
        # Apply Operator
        domain.timestep = 2.0
        operator()

        stage_ex = [ 21.,  21.,   1.,  21.]

#        print domain.quantities['stage'].centroid_values
#        print domain.quantities['xmomentum'].centroid_values
#        print domain.quantities['ymomentum'].centroid_values

        assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
        assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
        assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
        assert num.allclose(domain.fractional_step_volume_integral, factor*domain.timestep*(rate*domain.areas[indices]).sum())
开发者ID:MattAndersonPE,项目名称:anuga_core,代码行数:54,代码来源:test_rate_operators.py

示例12: _operate

    def _operate(self, other, operator):
        K1 = self.keys()
        K2 = other.keys()
        keys = set(K1 + K2)

        default = operator(self.default, other.default)
        
        result = SparseVector(default=default)
        for key in keys:
            result[key] = operator(self.get(key, self.default), other.get(key, self.default))

        return result
开发者ID:htomeht,项目名称:py-universe,代码行数:12,代码来源:vague.py

示例13: reverse_binary_operator

 def reverse_binary_operator(self, other, operator):
     try:
         self.assert_same_keys(other)
         result = self._get_empty_self()
         for key in self:
             result[key] = operator(other[key], self[key])
         return result
     except TypeError:
         result = self._get_empty_self()
         for key in self:
             result[key] = operator(other, self[key])
         return result
开发者ID:znah,项目名称:yoxel-voxel,代码行数:12,代码来源:arithmetic_container.py

示例14: do_operator

	def do_operator(self, operator, query, value, result):
		op = operator(mock_queryable, value)
		assert isinstance(op, Op)
		assert op.operation == query[1:]
		assert op.as_query == result
		
		if __debug__:
			a = MockQueryable()
			a.__disallowed_operators__ = {query}
			
			try:
				operator(a, value)
			except NotImplementedError as e:
				assert query in str(e)
开发者ID:djdduty,项目名称:mongo,代码行数:14,代码来源:test_query.py

示例15: __init__

    def __init__(self, inputs, cols="1", operator=None):

        self.cols = make_colspec(cols)
        self.ops = map(lambda x: operator([x]), inputs)
        self.name = "catcol(%s, %s)" % (",".join(map(str, self.cols)), str(self.ops[0]))
        # print self.cols, self.ops
        Operator.__init__(self, inputs, operators.OP_N_TO_N)
开发者ID:Alwnikrotikz,项目名称:smap-data,代码行数:7,代码来源:util.py


注:本文中的operator函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。