Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-bridge/blob/main/tests/native/pykinds.py # omega-bridge Omega-first language interoperability: checked conversion backends and native language bindings Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-bridge / tests / native / pykinds.py` 46 lines ยท 2563 bytes Raw Blame History 1 # Python caller for the f32 and ushort array kinds through the binding tools' `python` word generates 2 # (ctypes, standard library only). argv: the folder holding omega_native.py and libomega_native.so. 3 # Every expected value is computed here in Python (struct), independently of the Omega code. 4 import ctypes, struct, sys 5 sys.path.insert(0, sys.argv[1]) 6 import omega_native as om 7 fails = 0 8 def check(name, ok): 9 global fails 10 print(("PASS " if ok else "FAIL ") + name) 11 fails += not ok 12 def f32(x): 13 return struct.unpack(" f32 edit == Python", 30 om.omega_fsum(ctypes.byref(r), a, 4, h, 4, o, 4) == 0 and list(o) == want) 31 check("fsum result bits == Python", r.value == f32bits(f32(want[0] + want[3]))) 32 g = (H * 3)(*[f16bits(x) for x in (3.0, -0.75, 1024.0)]) 33 check("halve ushort edit written in place == Python", 34 om.omega_halve(ctypes.byref(r), g, 3) == 0 and list(g) == [f16bits(x) for x in (1.5, -0.375, 512.0)]) 35 # Negative controls: what the ABI cannot carry is refused before the Omega code runs. 36 r = ctypes.c_uint64(SENT); o2 = (F * 4)() 37 check("fsum wrong length 3 refused (status 32), output and result untouched", 38 om.omega_fsum(ctypes.byref(r), a, 3, h, 4, o2, 4) == 32 and list(o2) == [0.0] * 4 and r.value == SENT) 39 check("halve wrong length 4 refused (status 32), array untouched", 40 om.omega_halve(ctypes.byref(r), g, 4) == 32 and list(g) == [f16bits(x) for x in (1.5, -0.375, 512.0)]) 41 check("f64 array for an f32 view refused", refused(lambda: om.omega_fsum(ctypes.byref(r), (ctypes.c_double * 4)(), 4, h, 4, o, 4))) 42 check("int32 array for an f32 view refused", refused(lambda: om.omega_fsum(ctypes.byref(r), (ctypes.c_int32 * 4)(), 4, h, 4, o, 4))) 43 check("bytes for an edit ushort array refused", refused(lambda: om.omega_halve(ctypes.byref(r), bytes(6), 3))) 44 check("length 2**64 refused", refused(lambda: om.omega_halve(ctypes.byref(r), g, 2**64))) 45 print(("FAIL " if fails else "PASS ") + "%d failure(s)" % fails) 46 sys.exit(fails != 0)