Python System.Single() Examples
The following are 17
code examples of System.Single().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
System
, or try the search function
.
Example #1
Source File: test_builtinfunc.py From ironpython2 with Apache License 2.0 | 6 votes |
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))))
Example #2
Source File: __init__.py From PyESAPI with MIT License | 6 votes |
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
Example #3
Source File: test_builtinfunc.py From ironpython3 with Apache License 2.0 | 6 votes |
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))))
Example #4
Source File: test_numtypes.py From ironpython2 with Apache License 2.0 | 5 votes |
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
Example #5
Source File: test_numtypes.py From ironpython2 with Apache License 2.0 | 5 votes |
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
Example #6
Source File: test_regressions.py From ironpython2 with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: test_cliclass.py From ironpython2 with Apache License 2.0 | 5 votes |
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()
Example #8
Source File: test_cliclass.py From ironpython2 with Apache License 2.0 | 5 votes |
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)
Example #9
Source File: test_numtypes.py From ironpython3 with Apache License 2.0 | 5 votes |
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
Example #10
Source File: test_numtypes.py From ironpython3 with Apache License 2.0 | 5 votes |
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
Example #11
Source File: test_regressions.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #12
Source File: test_cliclass.py From ironpython3 with Apache License 2.0 | 5 votes |
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()
Example #13
Source File: test_cliclass.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #14
Source File: test_delegate.py From ironpython3 with Apache License 2.0 | 4 votes |
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
Example #15
Source File: test_clrnuminterop.py From ironpython2 with Apache License 2.0 | 4 votes |
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"))
Example #16
Source File: test_clrnuminterop.py From ironpython3 with Apache License 2.0 | 4 votes |
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"))
Example #17
Source File: test_delegate.py From ironpython2 with Apache License 2.0 | 4 votes |
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