base¶
In [ ]:
//// test
open testing
execution¶
emit¶
In [ ]:
inl emit forall t. (x : t) : t =
$'!x '
emit_unit¶
In [ ]:
inl emit_unit forall t. (x : t) : () =
$'!x '
use¶
In [ ]:
inl use forall t. (x : t) : t =
$'use !x = !x ' : ()
$'!x '
type¶
unit¶
In [ ]:
nominal unit = $'unit'
target¶
backend_switch¶
In [ ]:
inl backend_switch forall t. x : t =
real
inl backend key : t =
inl s = real_core.string_lit_to_symbol key
real_core.record_type_try_find `(`x) s
(forall v'. => (x s) ())
(fun () => $'' : t)
!!!!BackendSwitch (
("Fsharp", backend "Fsharp"),
("Python", backend "Python"),
("Cuda", backend "Cuda")
)
target_runtime¶
In [ ]:
union target_runtime =
| Native
| Wasm
| Contract
target¶
In [ ]:
union target =
| Fsharp : target_runtime
| Cuda : target_runtime
| Rust : target_runtime
| TypeScript : target_runtime
| Python : target_runtime
run_target_args'¶
In [ ]:
inl run_target_args' forall t u. (args : u) (fn : target -> (u -> t)) : t =
backend_switch {
Fsharp = fun () =>
inl result = $'()' : unit
inl emit_result x : () =
$'let _!result = !x '
$'\n#if FABLE_COMPILER || WASM || CONTRACT'
$'\n#if FABLE_COMPILER_RUST && \!WASM && \!CONTRACT'
inl target = Rust Native
fn target args |> emit_result
$'#endif\n#if FABLE_COMPILER_RUST && WASM'
inl target = Rust Wasm
fn target args |> emit_result
$'#endif\n#if FABLE_COMPILER_RUST && CONTRACT'
inl target = Rust Contract
fn target args |> emit_result
$'#endif\n#if FABLE_COMPILER_TYPESCRIPT'
inl target = TypeScript Native
fn target args |> emit_result
$'#endif\n#if FABLE_COMPILER_PYTHON'
inl target = Python Native
fn target args |> emit_result
$'#endif\n#if \!FABLE_COMPILER_RUST && \!FABLE_COMPILER_TYPESCRIPT && \!FABLE_COMPILER_PYTHON'
inl target = Fsharp Wasm
fn target args |> emit_result
$'#endif\n#else'
inl target = Fsharp Native
fn target args |> emit_result
$'#endif'
$'_!result ' : t
Python = fun () =>
inl target = Cuda Native
fn target args
}
run_target_args¶
In [ ]:
inl run_target_args forall t u. (args : () -> u) (fn : target -> (u -> t)) : t =
inl args = args () |> dyn
fn |> run_target_args' args
run_target¶
In [ ]:
inl run_target forall t. (fn : target -> (() -> t)) : t =
run_target_args id fn
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
run_target function
| Fsharp (Native) => fun () => $'1uy'
| Cuda (Native) => fun () => $'1'
| Rust (Native) => fun () => $'1uy'
| TypeScript (Native) => fun () => $'1uy'
| Python (Native) => fun () => $'1uy'
| _ => fun () => $'2uy'
|> _assert_eq 1u8
.py output (Cuda): __assert_eq / actual: 1 / expected: 1 Traceback (most recent call last): 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/9dbd634f2b57be35eb685f57e44d687506aabee76b117fe2b693dbde79f9fc74/main.py", line 85, 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/9dbd634f2b57be35eb685f57e44d687506aabee76b117fe2b693dbde79f9fc74/main.py", line 82, 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: 1 / expected: 1 .ts output: __assert_eq / actual: 1 / expected: 1 .py output: __assert_eq / actual: 1 / expected: 1
.fsx output: __assert_eq / actual: 1uy / expected: 1uy
function¶
eval¶
In [ ]:
inl eval fn =
fn ()
do¶
In [ ]:
inl do (body : () -> ()) : () =
!!!!Do (body())
indent¶
In [ ]:
inl indent (body : () -> ()) : () =
inl body =
fun () =>
body ()
$'(*' : ()
!!!!Indent (body())
$'*)'
let'¶
In [ ]:
inl let' fn =
inl result : unit = $'()'
$'let _!result ='
fn |> indent
$'_!result '
exec_unit¶
In [ ]:
inl exec_unit (fn : () -> ()) : () =
backend_switch {
Fsharp = fun () =>
inl unit = $'()' : $'unit'
($'(fun () -> !fn (); !unit) ()' : $'unit') |> ignore
Python = fun () => fn ()
}
lazy¶
In [ ]:
nominal lazy t = $'Lazy<`t>'
memoize¶
In [ ]:
nominal lazy t = $'Lazy<`t>'
inl memoize forall t. (fn : () -> t) : () -> t =
inl fn = join fn
backend_switch {
Fsharp = fun () =>
inl result : lazy t = $'lazy !fn ()'
fun () => $'!result.Value' : t
Python = fun () =>
inl result = mut None
inl computed = mut false
fun () =>
if *computed
then *result
else
result <- fn () |> Some
computed <- true
*result
|> optionm.value
}
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
inl count = mut 0i32
inl add =
fun () =>
count <- *count + 1
count
|> memoize
add () |> ignore
add () |> ignore
add () |> ignore
*count
|> _assert_eq 1
.py output (Cuda): __assert_eq / actual: 1 / expected: 1 Traceback (most recent call last): 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/444da12d1616d25e89847523cbc12345feb57a6ce608beed30ac23dc433bc936/main.py", line 156, 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/444da12d1616d25e89847523cbc12345feb57a6ce608beed30ac23dc433bc936/main.py", line 153, 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: 1 / expected: 1 .ts output: __assert_eq / actual: 1 / expected: 1 .py output: __assert_eq / actual: 1 / expected: 1
.fsx output: __assert_eq / actual: 1 / expected: 1
capture¶
In [ ]:
inl capture forall t. (fn : () -> t) : t =
inl result = dyn true
$'let mutable _!result : `t option = None '
$'('
$'(fun () ->'
$'(fun () ->'
fn () |> emit_unit
$')'
$'|> fun x -> x ()'
$') () )'
$'|> fun x -> _!result <- Some x'
$'match _!result with Some x -> x | None -> failwith "base.capture / _!result=None"'
arithmetic¶
(+.)¶
In [ ]:
inl (+.) forall t. (a : t) (b : t) : t =
$'!a + !b '
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
($'3' : i32) +. ($'-6' : i32)
|> _assert_eq -3i32
.py output (Cuda): __assert_eq / actual: -3 / expected: -3 Traceback (most recent call last): 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/cb2dcd64f6c2f8e2e59421451a511b7e133334325ce501e9d636e7d1eafd80bd/main.py", line 88, 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/cb2dcd64f6c2f8e2e59421451a511b7e133334325ce501e9d636e7d1eafd80bd/main.py", line 85, 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: -3 / expected: -3 .ts output: __assert_eq / actual: -3 / expected: -3 .py output: __assert_eq / actual: -3 / expected: -3
.fsx output: __assert_eq / actual: -3 / expected: -3
(-.)¶
In [ ]:
inl (-.) forall t. (a : t) (b : t) : t =
$'!a - !b '
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
($'3' : i32) -. ($'6' : i32)
|> _assert_eq -3i32
.py output (Cuda): __assert_eq / actual: -3 / expected: -3 Traceback (most recent call last): 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/75c364d8307ac0d12e7b33ec7a78c9edc8426bacf9221a85a0e49841634ef219/main.py", line 88, 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/75c364d8307ac0d12e7b33ec7a78c9edc8426bacf9221a85a0e49841634ef219/main.py", line 85, 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: -3 / expected: -3 .ts output: __assert_eq / actual: -3 / expected: -3 .py output: __assert_eq / actual: -3 / expected: -3
.fsx output: __assert_eq / actual: -3 / expected: -3
(*.)¶
In [ ]:
inl (*.) forall t. (a : t) (b : t) : t =
$'!a * !b '
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
($'3' : i32) *. ($'-1' : i32)
|> _assert_eq -3i32
.py output (Cuda): Traceback (most recent call last): __assert_eq / actual: -3 / expected: -3 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/2a5ee4e1708999cf6408fe21697eb314e2c9193d57bcd112ac092ff3f7906687/main.py", line 88, 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/2a5ee4e1708999cf6408fe21697eb314e2c9193d57bcd112ac092ff3f7906687/main.py", line 85, 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: -3 / expected: -3 .ts output: __assert_eq / actual: -3 / expected: -3 .py output: __assert_eq / actual: -3 / expected: -3
.fsx output: __assert_eq / actual: -3 / expected: -3
(/.)¶
In [ ]:
inl (/.) forall t. (a : t) (b : t) : t =
$'!a / !b '
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
($'-3' : i32) /. ($'1' : i32)
|> _assert_eq -3i32
.py output (Cuda): __assert_eq / actual: -3.0 / expected: -3 Traceback (most recent call last): 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/29c06d104afd3bd689051c74e42a4f620d943c21c2bdb37728878d38e324e9a5/main.py", line 88, 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/29c06d104afd3bd689051c74e42a4f620d943c21c2bdb37728878d38e324e9a5/main.py", line 85, 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: -3 / expected: -3 .ts output: __assert_eq / actual: -3 / expected: -3 .py output: __assert_eq / actual: -3 / expected: -3
.fsx output: __assert_eq / actual: -3 / expected: -3
comparison¶
(=.)¶
In [ ]:
inl (=.) forall t. (a : t) (b : t) : bool =
backend_switch {
Fsharp = fun () => $'!a = !b ' : bool
Python = fun () => $'!a == !b ' : bool
}
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
($'-3' : i32) =. ($'-3' : i32)
|> _assert_eq true
.py output (Cuda): __assert_eq / actual: True / expected: True Traceback (most recent call last): 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/16ce27d290bb50defca4505e5d552f14aa043236df6d17bbb87fc9b084d98647/main.py", line 86, 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/16ce27d290bb50defca4505e5d552f14aa043236df6d17bbb87fc9b084d98647/main.py", line 83, 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: true / expected: true .ts output: __assert_eq / actual: true / expected: true .py output: __assert_eq / actual: true / expected: true
.fsx output: __assert_eq / actual: true / expected: true
(<>.)¶
In [ ]:
inl (<>.) forall t. (a : t) (b : t) : bool =
backend_switch {
Fsharp = fun () => $'!a <> !b ' : bool
Python = fun () => $'!a \!= !b ' : bool
}
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
($'-3' : i32) <>. ($'3' : i32)
|> _assert_eq true
.py output (Cuda): __assert_eq / actual: True / expected: True Traceback (most recent call last): 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/8653524afdfc5d25d61335dfe2ce9bffc32290d678c20c90bef584d9d72f6b18/main.py", line 86, 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/8653524afdfc5d25d61335dfe2ce9bffc32290d678c20c90bef584d9d72f6b18/main.py", line 83, 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: true / expected: true .ts output: __assert_eq / actual: true / expected: true .py output: __assert_eq / actual: true / expected: true
.fsx output: __assert_eq / actual: true / expected: true
(<>..)¶
In [ ]:
inl (<>..) a b =
fun () => a = b
|> dyn
|> eval
|> not
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
($'-3' : i32) <>.. ($'3' : i32)
|> _assert_eq true
.py output (Cuda): __assert_eq / actual: True / expected: True Traceback (most recent call last): 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/97c9365d18ee8c7cece1f17d4d01e843b9e57d4eb0e2f73c03ab8291e759e7b5/main.py", line 98, 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/97c9365d18ee8c7cece1f17d4d01e843b9e57d4eb0e2f73c03ab8291e759e7b5/main.py", line 95, 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: true / expected: true .ts output: __assert_eq / actual: true / expected: true .py output: __assert_eq / actual: true / expected: true
.fsx output: __assert_eq / actual: true / expected: true
composition¶
append¶
In [ ]:
prototype append t : t -> t -> t
(++)¶
In [ ]:
inl (++) a b =
b |> append a
application¶
(||>)¶
In [ ]:
inl (||>) (arg1, arg2) fn =
arg2 |> fn arg1
fix_condition¶
In [ ]:
inl fix_condition x a b =
if x ()
then a () |> fun x => $'(*' : ()
else
$'*) else' : ()
b () |> fun x => $'(*' : ()
|> fun x => $'*)' : ()
type¶
infer¶
In [ ]:
nominal infer = $'_'
infer'¶
In [ ]:
nominal infer' t = $'_'
any¶
In [ ]:
nominal any = $'obj'
null¶
In [ ]:
inl null forall t. () : t =
backend_switch {
Fsharp = fun () => $'null |> unbox<`t>' : t
Python = fun () => $'None' : t
}
defaultof¶
In [ ]:
inl defaultof forall t. () : t =
$'Unchecked.defaultof<`t>'
choice2'¶
In [ ]:
nominal choice2' a b = $'Choice<`a, `b>'
choice2_unbox¶
In [ ]:
inl choice2_unbox forall t1 t2. (choice : choice2' t1 t2) : choice2 t1 t2 =
run_target_args (fun () => choice) function
| Fsharp _ => fun choice =>
inl c1of2 (x : t1) : _ _ t2 = C1of2 x
inl c2of2 (x : t2) : _ t1 _ = C2of2 x
inl c1of2 = join c1of2
inl c2of2 = join c2of2
$'match !choice with Choice1Of2 x -> !c1of2 x | Choice2Of2 x -> !c2of2 x'
| _ => fun _ => null ()
pair¶
pair¶
In [ ]:
nominal pair a b = $'(`a * `b)'
inl pair x y =
x, y
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
pair 1i32 2i32
|> _assert_eq (1, 2)
.py output (Cuda): __assert_eq / actual: (1, 2) / expected: (1, 2) Traceback (most recent call last): 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/c3af5773403ce8d003f1c2570d42937203995bd6e5ab2d5c73ffa32807b08bda/main.py", line 70, 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/c3af5773403ce8d003f1c2570d42937203995bd6e5ab2d5c73ffa32807b08bda/main.py", line 67, 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: (1, 2) / expected: (1, 2) .ts output: __assert_eq / actual: 1,2 / expected: 1,2 .py output: __assert_eq / actual: (1, 2) / expected: (1, 2)
.fsx output: __assert_eq / actual: struct (1, 2) / expected: struct (1, 2)
new_pair¶
In [ ]:
inl new_pair forall a b. (a : a) (b : b) : pair a b =
$'!a, !b '
from_pair¶
In [ ]:
inl from_pair forall a b. (pair : pair a b) : a * b =
backend_switch {
Fsharp = fun () =>
$'let (a, b) = !pair '
($'a' : a), ($'b' : b)
Python = fun () =>
$'a, b = !pair '
($'a' : a), ($'b' : b)
}
In [ ]:
//// test
///! fsharp
///! cuda
///! rust
///! typescript
///! python
new_pair "a" (new_pair 1i32 "b")
|> from_pair
|> _assert_eq' ("a", (new_pair 1i32 "b"))
.py output (Cuda): __assert_eq' / actual: ('a', (1, 'b')) / expected: ('a', (1, 'b')) Traceback (most recent call last): 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/6acf9ea73e216a4a6c8e64b7eddf2cf10cff2d2fec52dfb6e582b19ef47e2a26/main.py", line 95, 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/6acf9ea73e216a4a6c8e64b7eddf2cf10cff2d2fec52dfb6e582b19ef47e2a26/main.py", line 92, 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: ("a", (1, "b")) / expected: ("a", (1, "b")) .ts output: __assert_eq' / actual: a,1,b / expected: a,1,b .py output: __assert_eq' / actual: ('a', (1, 'b')) / expected: ('a', (1, 'b'))
.fsx output: __assert_eq' / actual: struct ("a", (1, "b")) / expected: struct ("a", (1, "b"))
ref¶
ref¶
In [ ]:
nominal ref t = $'`t ref'
new_ref¶
In [ ]:
inl new_ref forall t. (x : t) : ref t =
$'ref !x '
ref_value¶
In [ ]:
inl ref_value forall t. (x : ref t) : t =
$'!x.Value'
ref_set_value¶
In [ ]:
inl ref_set_value forall t. (value : t) (ref : ref t) : ref t =
$'!ref.Value <- !value '
ref
convert¶
to¶
In [ ]:
inl to forall t u. (x : t) : u =
$'!x ' : u
convert¶
In [ ]:
inl convert forall t u. (x : t) : u =
backend_switch {
Fsharp = fun () => $'!x |> `u ' : u
Python = fun () => x |> to : u
}
unbox¶
In [ ]:
inl unbox forall t u. (x : t) : u =
backend_switch {
Fsharp = fun () => $'!x |> unbox<`u>' : u
Python = fun () => x |> to : u
}
u8¶
In [ ]:
inl u8 forall t. (x : t) : u8 =
x |> $'uint8'
u16¶
In [ ]:
inl u16 forall t. (x : t) : u16 =
x |> $'uint16'
u64¶
In [ ]:
inl u64 forall t. (x : t) : u64 =
x |> $'uint64'
i32¶
In [ ]:
inl i32 forall t. (x : t) : i32 =
x |> $'int32'
i64¶
In [ ]:
inl i64 forall t. (x : t) : i64 =
x |> $'int64'
f32¶
In [ ]:
inl f32 forall t. (x : t) : f32 =
x |> $'float32'
f64¶
In [ ]:
inl f64 forall t. (x : t) : f64 =
x |> $'float'
unativeint¶
In [ ]:
nominal unativeint = $'unativeint'
convert_i32¶
In [ ]:
inl convert_i32 forall t. (x : t) : i32 =
x |> $'System.Convert.ToInt32'
convert_i32_base¶
In [ ]:
inl convert_i32_base forall t. (base : i32) (x : t) : i32 =
$'System.Convert.ToInt32 (!x, !base)'
error¶
exn¶
In [ ]:
nominal exn = $"backend_switch `({ Fsharp : $'exn'; Python : $'BaseException' })"
inl exn x =
x |> $'`exn '
try¶
In [ ]:
inl try forall t. (fn : () -> t) (ex_fn : exn -> option t) : option t =
backend_switch {
Fsharp = fun () =>
inl some x : option t = Some x
inl some = dyn some
inl fn = dyn fn
inl ex_fn = dyn ex_fn
$'let result = ref !(None : option t)'
$'try'
$' result.Value <- !fn () |> !some '
$'with ex ->'
$' result.Value <- !ex_fn ex '
$'result.Value' : option t
Python = fun () =>
$'result = !(None : option t)'
inl fn = dyn fn
inl ex_fn = dyn ex_fn
$'try:'
$' result = !fn()\n \'\'\''
$'\'\'\''
$'except Exception as e:'
$' result = !ex_fn(e)'
$'result' : option t
}
In [ ]:
//// test
///! fsharp
////! cuda // cudaErrorInsufficientDriver: CUDA driver version is insufficient for CUDA runtime version
///! rust
///! typescript
///! python
try
fun () => a ;[ 0i32 ] |> am'.index 1i32 |> sm'.format
(fun ex => $'!ex ' |> sm'.format_exception |> Some)
|> optionm.value
|> _assert_eq (run_target function
| Fsharp => fun () => join "System.IndexOutOfRangeException: Index was outside the bounds of the array."
| Cuda => fun () => "array index out of range"
| Rust => fun () => "Exception { message: \"index out of bounds: the len is 1 but the index is 1\" }"
| TypeScript => fun () => "Error: Index was outside the bounds of the array.\\nParameter name: index"
| Python => fun () => "array index out of range"
)
.rs output: __assert_eq / actual: "Exception { message: "index out of bounds: the len is 1 but the index is 1" }" / expected: "Exception { message: "index out of bounds: the len is 1 but the index is 1" }" .ts output: __assert_eq / actual: Error: Index was outside the bounds of the array.\nParameter name: index / expected: Error: Index was outside the bounds of the array.\nParameter name: index .py output: __assert_eq / actual: array index out of range / expected: array index out of range
.fsx output: __assert_eq / actual: "System.IndexOutOfRangeException: Index was outside the bounds of the array." / expected: "System.IndexOutOfRangeException: Index was outside the bounds of the array."
try_unit¶
In [ ]:
inl try_unit forall t. (fn : () -> ()) (ex_fn : exn -> ()) : t =
$'try'
fn ()
|> ignore
$'with ex ->'
fun () =>
ex_fn $'ex'
|> ignore
|> indent
$'(*'
$'*)'
try_unit'¶
In [ ]:
inl try_unit' forall t. (ex_fn : exn -> ()) (fn : () -> ()) : t =
$'try'
fn ()
|> ignore
$'with ex ->'
fun () =>
ex_fn $'ex'
|> ignore
|> indent
$'(*'
$'*)'
try_finally¶
In [ ]:
inl try_finally forall t. (fn : () -> ()) (finally : () -> ()) : t =
$'try'
fn ()
|> ignore
$'finally'
finally ()
|> ignore
$'(*'
$'*)'