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


Python System.Single方法代码示例

本文整理汇总了Python中System.Single方法的典型用法代码示例。如果您正苦于以下问题:Python System.Single方法的具体用法?Python System.Single怎么用?Python System.Single使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System的用法示例。


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

示例1: test_cp16000

# 需要导入模块: import System [as 别名]
# 或者: from System import Single [as 别名]
def test_cp16000(self):
        class K(object):
            FOO = 39
            def fooFunc():
                return K.FOO
            def memberFunc(self):
                return K.FOO * 3.14


        temp_list = [   None, str, int, long, K,
                        "", "abc", u"abc", 34, long(1111111111111), 3.14, K(), K.FOO,
                        id, hex, K.fooFunc, K.memberFunc, K().memberFunc,
                    ]

        if is_cli:
            import System
            temp_list += [  System.Exception, System.InvalidOperationException(),
                            System.Single, System.UInt16(5), System.Version(0, 0)]

        for x in temp_list:
            self.assertTrue(type(id(x)) in [int, long],
                str(type(id(x)))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_builtinfunc.py

示例2: set_fluence_nparray

# 需要导入模块: import System [as 别名]
# 或者: from System import Single [as 别名]
def set_fluence_nparray(beam, shaped_fluence, beamlet_size_mm=2.5):
    """sets optimal fluence in beam given numpy array and beamlet size (asserts square fluence, and zero collimator rotation)."""
    # assumes all fluence is square with isocenter at center of image
    # TODO: implement functionality below to remove assertions
    assert beamlet_size_mm == 2.5, "beamlet sizes of other than 2.5 mm are not implemented"
    assert shaped_fluence.shape[0] == shaped_fluence.shape[1], "non-square fluence not implemented"
    assert beam.ControlPoints[0].CollimatorAngle == 0.0, "non-zero collimator angle not implemented"

    _buffer = Array.CreateInstance(System.Single, shaped_fluence.shape[0], shaped_fluence.shape[1])

    # note: the shape -1, then divide by 2.0 gives desired center of corner beamlet (half pixel shift)
    x_origin = - float(shaped_fluence.shape[0] - 1) * beamlet_size_mm / 2.0
    y_origin = + float(shaped_fluence.shape[1] - 1) * beamlet_size_mm / 2.0

    for i in range(shaped_fluence.shape[0]):
        for j in range(shaped_fluence.shape[1]):
            _buffer[i, j] = shaped_fluence[i, j]

    fluence = Fluence(_buffer, x_origin, y_origin)
    beam.SetOptimalFluence(fluence)


## where the magic happens ##

# add Lot accessors to objects with IEnumerable childeren 
开发者ID:VarianAPIs,项目名称:PyESAPI,代码行数:27,代码来源:__init__.py

示例3: get_values

# 需要导入模块: import System [as 别名]
# 或者: from System import Single [as 别名]
def get_values(values, itypes, ftypes):
    """
    This will return structure of values converted to variety of types as a list of tuples:
    [ ...
    ( python_value, [ all_values ] ),
    ... ]

    all_values: Byte, UInt16, UInt32, UInt64, SByte, Int16, Int32, Int64, Single, Double, myint, mylong, myfloat
    """
    all = []
    for v in values:
        sv  = str(v)
        py  = int(v)
        clr = get_clr_values(sv, itypes)
        clr.append(long(py))
        clr.append(myint(py))
        clr.append(mylong(py))
        all.append( (py, clr) )

        py  = long(v)
        clr = get_clr_values(sv, itypes)
        clr.append(py)
        clr.append(myint(py))
        clr.append(mylong(py))
        all.append( (py, clr) )

        py  = float(v)
        clr = get_clr_values(sv, ftypes)
        clr.append(myfloat(py))
        all.append( (py, clr) )

        for imag in [0j, 1j, -1j]:
            py = complex(v + imag)
            all.append( (py, [ py, mycomplex(py) ] ) )

    all.append( (True, [ True ] ))
    all.append( (False, [ False ] ))

    return all 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:41,代码来源:test_numtypes.py

示例4: mystr

# 需要导入模块: import System [as 别名]
# 或者: from System import Single [as 别名]
def mystr(x):
    if isinstance(x, tuple):
        return "(" + ", ".join(mystr(e) for e in x) + ")"
    elif isinstance(x, Single):
        return str(round(float(str(x)), 3))
    elif isinstance(x, Double):
        return str(round(x, 3))
    else:
        s = str(x)
        if s.endswith("L"): return s[:-1]
        else: return s 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_numtypes.py

示例5: test_cp24802

# 需要导入模块: import System [as 别名]
# 或者: from System import Single [as 别名]
def test_cp24802(self):
        import clr
        clr.AddReference('System.Drawing')
        import System
        p = System.Drawing.Pen(System.Drawing.Color.Blue)
        p.Width = System.Single(3.14)
        self.assertEqual(p.Width, System.Single(3.14))
        p.Width = 4.0
        self.assertEqual(p.Width, 4.0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_regressions.py

示例6: test_nonzero

# 需要导入模块: import System [as 别名]
# 或者: from System import Single [as 别名]
def test_nonzero(self):
        from System import Single, Byte, SByte, Int16, UInt16, Int64, UInt64
        for t in [Single, Byte, SByte, Int16, UInt16, Int64, UInt64]:
            self.assertTrue(hasattr(t, '__nonzero__'))
            if t(0): self.assertUnreachable()
            if not t(1): self.assertUnreachable() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_cliclass.py

示例7: test_bad_inheritance

# 需要导入模块: import System [as 别名]
# 或者: from System import Single [as 别名]
def test_bad_inheritance(self):
        """verify a bad inheritance reports the type name you're inheriting from"""
        def f(): 
            class x(System.Single): pass
        def g(): 
            class x(System.Version): pass
        
        self.assertRaisesPartialMessage(TypeError, 'System.Single', f)
        self.assertRaisesPartialMessage(TypeError, 'System.Version', g) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_cliclass.py

示例8: test_identity

# 需要导入模块: import System [as 别名]
# 或者: from System import Single [as 别名]
def test_identity(self):
        import IronPythonTest
        from System.Threading import ParameterizedThreadStart, Thread, ThreadStart
        global called
        global globalSelf
        def identity(x): return x

        r = IronPythonTest.ReturnTypes()
        r.floatEvent += identity

        import System
        self.assertEqual(r.RunFloat(1.4), System.Single(1.4))


        # try parameterized thread
        a = foo()
        t = Thread(ParameterizedThreadStart(foo.bar))
        t.Start(a)
        t.Join()

        self.assertEqual(called, True)
        self.assertEqual(globalSelf, a)

        # try non-parameterized
        a = foo()
        called = False

        t = Thread(ThreadStart(a.bar))
        t.Start()
        t.Join()

        self.assertEqual(called, True)
        self.assertEqual(globalSelf, a)

        # parameterized w/ self
        a = foo()
        called = False

        t = Thread(ParameterizedThreadStart(a.baz))
        t.Start('hello')
        t.Join()

        self.assertEqual(called, True)
        self.assertEqual(globalSelf, a)
        self.assertEqual(globalArg, 'hello')

        # parameterized w/ self & extra arg, should throw
        try:
            pts = ParameterizedThreadStart(foo.baz)
            pts("Hello")
            self.assertUnreachable()
        except TypeError: pass

# SuperDelegate Tests 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:56,代码来源:test_delegate.py

示例9: test_sanity

# 需要导入模块: import System [as 别名]
# 或者: from System import Single [as 别名]
def test_sanity(self):
        '''Make sure that numbers within the constraints of the numerical types are allowed.'''
        import clr
        import System
        temp_list = [   ["System.Byte", 0, 255],
                        ["System.SByte", -128, 127],
                        ["System.Byte", 0, 255],
                        ["System.Int16", -32768, 32767],
                        ["System.UInt16", 0, 65535],
                        ["System.Int32", -2147483648, 2147483647],
                        ["System.UInt32", 0, 4294967295],
                        ["System.Int64", -9223372036854775808, 9223372036854775807],
                        ["System.UInt64", 0, 18446744073709551615],
                        ["System.Single", -3.40282e+038, 3.40282e+038],
                        ["System.Double", -1.79769313486e+308, 1.79769313486e+308],
                        ["System.Decimal", -79228162514264337593543950335, 79228162514264337593543950335],
                        ["int", -2147483648, 2147483647]
                    ]

        for num_type, small_val, large_val in temp_list:
            self.assertTrue(self.num_ok_for_type(1, num_type))
            self.assertTrue(self.num_ok_for_type(1.0, num_type))

            #Minimum value
            self.assertTrue(self.num_ok_for_type(small_val, num_type))
            self.assertTrue(self.num_ok_for_type(small_val + 1, num_type))
            self.assertTrue(self.num_ok_for_type(small_val + 2, num_type))

            #Maximum value
            self.assertTrue(self.num_ok_for_type(large_val, num_type))
            self.assertTrue(self.num_ok_for_type(large_val - 1, num_type))
            self.assertTrue(self.num_ok_for_type(large_val - 2, num_type))

            #Negative cases
            if num_type!="System.Single" and num_type!="System.Double" and num_type!="System.Decimal":
                self.assertTrue(not self.num_ok_for_type(small_val - 1, num_type))
                self.assertTrue(not self.num_ok_for_type(small_val - 2, num_type))
                self.assertTrue(not self.num_ok_for_type(large_val + 1, num_type))
                self.assertTrue(not self.num_ok_for_type(large_val + 2, num_type))

        #Special cases
        self.assertTrue(self.num_ok_for_type(0, "long"))
        self.assertTrue(self.num_ok_for_type(1, "long"))
        self.assertTrue(self.num_ok_for_type(-1, "long"))
        self.assertTrue(self.num_ok_for_type(5, "long"))
        self.assertTrue(self.num_ok_for_type(-92233720368547758080000, "long"))
        self.assertTrue(self.num_ok_for_type( 18446744073709551615000, "long"))

        self.assertTrue(self.num_ok_for_type(0.0, "float"))
        self.assertTrue(self.num_ok_for_type(1.0, "float"))
        self.assertTrue(self.num_ok_for_type(-1.0, "float"))
        self.assertTrue(self.num_ok_for_type(3.14, "float"))
        self.assertTrue(self.num_ok_for_type(-92233720368547758080000.0, "float"))
        self.assertTrue(self.num_ok_for_type( 18446744073709551615000.0, "float")) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:56,代码来源:test_clrnuminterop.py


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