guid¶
In [ ]:
//// test
open testing
guid¶
guid¶
In [ ]:
nominal guid_python =
`(
global "import uuid"
$'' : $'uuid.UUID'
)
type guid_switch =
{
Fsharp : $'System.Guid'
Python : guid_python
}
nominal guid = $'backend_switch `(guid_switch)'
new_guid¶
In [ ]:
inl new_guid (x : string) : guid =
x |> convert
new_raw_guid¶
In [ ]:
inl new_raw_guid () : guid =
backend_switch {
Fsharp = fun () => $'System.Guid.NewGuid' () : guid
Python = fun () => $'uuid.uuid4()' : guid
}
hash_guid¶
In [ ]:
type hash_guid = guid
let hash_guid (~hash : string) : hash_guid =
run_target function
| Rust (Contract) => fun () => null ()
| _ => fun () =>
inl hash = hash |> sm'.pad_left 32i32 '0'
backend_switch {
Fsharp = fun () =>
$'`hash_guid $"{!hash.[0..7]}-{!hash.[8..11]}-{!hash.[12..15]}-{!hash.[16..19]}-{!hash.[20..31]}"' : hash_guid
Python = fun () => $'f"{!hash[0:8]}-{!hash[8:12]}-{!hash[12:16]}-{!hash[16:20]}-{!hash[20:32]}"' : hash_guid
}
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
""
|> hash_guid
|> _assert_eq' (new_guid "00000000-0000-0000-0000-000000000000")
"123456789012345678901234567890123"
|> hash_guid
|> _assert_eq' (new_guid "12345678-9012-3456-7890-123456789012")
.py output (Cuda): __assert_eq' / actual: 00000000-0000-0000-0000-000000000000 / expected: 00000000-0000-0000-0000-000000000000 Traceback (most recent call last): __assert_eq' / actual: 12345678-9012-3456-7890-123456789012 / expected: 12345678-9012-3456-7890-123456789012 File "cupy/cuda/stream.pyx", line 36, in cupy.cuda.stream._ThreadLocal.get AttributeError: '_thread._local' object has no attribute 'tls' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/runner/work/polyglot/polyglot/target/spiral_Eval/packages/2a624d9e41158d1eaf1cae26c62273d35a36788b40f4a6aaa020223dfd3e93b6/main.py", line 125, in <module> if __name__ == '__main__': result = main(); None if result is None else print(result) ^^^^^^ File "/home/runner/work/polyglot/polyglot/target/spiral_Eval/packages/2a624d9e41158d1eaf1cae26c62273d35a36788b40f4a6aaa020223dfd3e93b6/main.py", line 122, in main cp.cuda.get_current_stream().synchronize() # This line is here so the `__trap()` calls on the kernel aren't missed. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "cupy/cuda/stream.pyx", line 87, in cupy.cuda.stream.get_current_stream File "cupy/cuda/stream.pyx", line 96, in cupy.cuda.stream.get_current_stream File "cupy/cuda/stream.pyx", line 38, in cupy.cuda.stream._ThreadLocal.get File "cupy/cuda/stream.pyx", line 24, in cupy.cuda.stream._ThreadLocal.__init__ File "cupy_backends/cuda/api/runtime.pyx", line 393, in cupy_backends.cuda.api.runtime.getDeviceCount File "cupy_backends/cuda/api/runtime.pyx", line 146, in cupy_backends.cuda.api.runtime.check_status cupy_backends.cuda.api.runtime.CUDARuntimeError: cudaErrorInsufficientDriver: CUDA driver version is insufficient for CUDA runtime version .rs output: __assert_eq' / actual: Guid(00000000-0000-0000-0000-000000000000) / expected: Guid(00000000-0000-0000-0000-000000000000) __assert_eq' / actual: Guid(12345678-9012-3456-7890-123456789012) / expected: Guid(12345678-9012-3456-7890-123456789012) .ts output: __assert_eq' / actual: 00000000-0000-0000-0000-000000000000 / expected: 00000000-0000-0000-0000-000000000000 __assert_eq' / actual: 12345678-9012-3456-7890-123456789012 / expected: 12345678-9012-3456-7890-123456789012 .py output: __assert_eq' / actual: 00000000-0000-0000-0000-000000000000 / expected: 00000000-0000-0000-0000-000000000000 __assert_eq' / actual: 12345678-9012-3456-7890-123456789012 / expected: 12345678-9012-3456-7890-123456789012
.fsx output: __assert_eq' / actual: 00000000-0000-0000-0000-000000000000 / expected: 00000000-0000-0000-0000-000000000000 __assert_eq' / actual: 12345678-9012-3456-7890-123456789012 / expected: 12345678-9012-3456-7890-123456789012
main¶
In [ ]:
inl main () =
$'let new_guid x = !new_guid x' : ()
$'let hash_guid x = !hash_guid x' : ()
$'let new_raw_guid x = !new_raw_guid x' : ()