Python builtins 模块,round() 实例源码

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

项目:ngraph    作者:NervanaSystems    | 项目源码 | 文件源码
def memory_efficiency(self):
        mem = 100
        if self.memory_footprint() > 0:
            mem = round(float(self.memory_usage()) / float(self.memory_footprint()) * 100)
            mem = int(mem)
        return mem
项目:ngraph    作者:NervanaSystems    | 项目源码 | 文件源码
def memory_efficiency(self):
        footprint = self.memory_footprint()
        usage = 0
        for node in self.ops:
            usage = max(usage, node.memory_usage())
        result = 100
        if footprint > 0:
            result = int(round((float(usage) / float(footprint)) * 100))
        return result
项目:qtpandas    作者:draperjames    | 项目源码 | 文件源码
def test_numericalValues(self, model, index, value, dtype, precision):
        dataFrame = pandas.DataFrame([value], columns=['A'])
        dataFrame['A'] = dataFrame['A'].astype(dtype)
        model.setDataFrame(dataFrame)
        assert not model.dataFrame().empty
        assert model.dataFrame() is dataFrame

        assert index.isValid()

        newValue = value + 1
        model.enableEditing(True)
        assert model.setData(index, newValue)

        if precision:
            modelValue = model.data(index, role=Qt.DisplayRole)
            #assert abs(decimal.Decimal(str(modelValue)).as_tuple().exponent) == precision
            assert model.data(index) == round(newValue, precision)
            assert model.data(index, role=Qt.DisplayRole) == round(newValue, precision)
            assert model.data(index, role=Qt.EditRole) == round(newValue, precision)
        else:
            assert model.data(index) == newValue
            assert model.data(index, role=Qt.DisplayRole) == newValue
            assert model.data(index, role=Qt.EditRole) == newValue
        assert model.data(index, role=Qt.CheckStateRole) == None
        assert isinstance(model.data(index, role=DATAFRAME_ROLE), dtype)
        assert model.data(index, role=DATAFRAME_ROLE).dtype == dtype
项目:reframe    作者:eth-cscs    | 项目源码 | 文件源码
def round(number, *args):
    """Replacement for the built-in
    :func:`round() <python:round>` function."""
    return builtins.round(number, *args)
项目:qtpandas    作者:draperjames    | 项目源码 | 文件源码
def test_numericalValues(self, model, index, value, dtype, precision):
        dataFrame = pandas.DataFrame([value], columns=['A'])
        dataFrame['A'] = dataFrame['A'].astype(dtype)
        model.setDataFrame(dataFrame)
        assert not model.dataFrame().empty
        assert model.dataFrame() is dataFrame

        assert index.isValid()
        if precision:
            modelValue = model.data(index, role=Qt.DisplayRole)
            assert model.data(index) == round(value, precision)
            assert model.data(index, role=Qt.DisplayRole) == round(value, precision)
            assert model.data(index, role=Qt.EditRole) == round(value, precision)
        else:
            assert model.data(index) == value
            assert model.data(index, role=Qt.DisplayRole) == value
            assert model.data(index, role=Qt.EditRole) == value
        assert model.data(index, role=Qt.CheckStateRole) == None
        assert isinstance(model.data(index, role=DATAFRAME_ROLE), dtype)
        assert model.data(index, role=DATAFRAME_ROLE).dtype == dtype

    #@pytest.mark.parametrize(
        #"border1, modifier, border2, dtype", [
            #("min", -1, "max", numpy.uint8),
            #("max", +1, "min", numpy.uint8),
            #("min", -1, "max", numpy.uint16),
            #("max", +1, "min", numpy.uint16),
            #("min", -1, "max", numpy.uint32),
            #("max", +1, "min", numpy.uint32),
            #("min", -1, "max", numpy.uint64),
            ##("max", +1, "min", numpy.uint64),  # will raise OverFlowError caused by astype function,
                                                ## uneffects models data method
            #("min", -1, "max", numpy.int8),
            #("max", +1, "min", numpy.int8),
            #("min", -1, "max", numpy.int16),
            #("max", +1, "min", numpy.int16),
            #("min", -1, "max", numpy.int32),
            #("max", +1, "min", numpy.int32),
            ##("min", -1, "max", numpy.int64),   # will raise OverFlowError caused by astype function
                                                ## uneffects models data method
            ##("max", +1, "min", numpy.int64),   # will raise OverFlowError caused by astype function
                                                ## uneffects models data method
        #]
    #)
    #def test_integerBorderValues(self, model, index, border1, modifier, border2, dtype):
        #ii = numpy.iinfo(dtype)
        #dataFrame = pandas.DataFrame([getattr(ii, border1) + modifier], columns=['A'])
        #dataFrame['A'] = dataFrame['A'].astype(dtype)
        #model.setDataFrame(dataFrame)
        #assert not model.dataFrame().empty
        #assert model.dataFrame() is dataFrame

        #assert index.isValid()
        #assert model.data(index) == getattr(ii, border2)