text
stringlengths 12
786k
|
---|
let fun_ctb10 ( ) = Alcotest . ( check bool ) " fun_ctb10 " true ( To_test_transpose_conv2d_backward . fun10 ( ) ) |
let fun_ctb11 ( ) = Alcotest . ( check bool ) " fun_ctb11 " true ( To_test_transpose_conv2d_backward . fun11 ( ) ) |
let fun_ctb12 ( ) = Alcotest . ( check bool ) " fun_ctb12 " true ( To_test_transpose_conv2d_backward . fun12 ( ) ) |
let fun_ctb13 ( ) = Alcotest . ( check bool ) " fun_ctb13 " true ( To_test_transpose_conv2d_backward . fun13 ( ) ) |
let fun_ctb14 ( ) = Alcotest . ( check bool ) " fun_ctb14 " true ( To_test_transpose_conv2d_backward . fun14 ( ) ) |
let fun_ctb15 ( ) = Alcotest . ( check bool ) " fun_ctb15 " true ( To_test_transpose_conv2d_backward . fun15 ( ) ) |
let test_set = [ " fun_ctf00 " , ` Slow , fun_ctf00 ; " fun_ctf01 " , ` Slow , fun_ctf01 ; " fun_ctf02 " , ` Slow , fun_ctf02 ; " fun_ctf03 " , ` Slow , fun_ctf03 ; " fun_ctf04 " , ` Slow , fun_ctf04 ; " fun_ctf05 " , ` Slow , fun_ctf05 ; " fun_ctf06 " , ` Slow , fun_ctf06 ; " fun_ctf07 " , ` Slow , fun_ctf07 ; " fun_ctf08 " , ` Slow , fun_ctf08 ; " fun_ctb00 " , ` Slow , fun_ctb00 ; " fun_ctb01 " , ` Slow , fun_ctb01 ; " fun_ctb02 " , ` Slow , fun_ctb02 ; " fun_ctb03 " , ` Slow , fun_ctb03 ; " fun_ctb04 " , ` Slow , fun_ctb04 ; " fun_ctb05 " , ` Slow , fun_ctb05 ; " fun_ctb06 " , ` Slow , fun_ctb06 ; " fun_ctb07 " , ` Slow , fun_ctb07 ; " fun_ctb08 " , ` Slow , fun_ctb08 ; " fun_ctb09 " , ` Slow , fun_ctb09 ; " fun_ctb10 " , ` Slow , fun_ctb10 ; " fun_ctb11 " , ` Slow , fun_ctb11 ; " fun_ctb12 " , ` Slow , fun_ctb12 ; " fun_ctb13 " , ` Slow , fun_ctb13 ; " fun_ctb14 " , ` Slow , fun_ctb14 ; " fun_ctb15 " , ` Slow , fun_ctb15 ] |
let close a b = N . ( sub a b |> abs |> sum ' ) < tolerance_f32 |
let compute_trans_conv3d seq input_shape kernel_shape stride pad = let inp = N . ones input_shape in let kernel = if seq = false then N . ones kernel_shape else N . sequential ~ a : 1 . kernel_shape in N . transpose_conv3d ~ padding : pad inp kernel stride |
let compute_trans_conv3d_bi seq input_shape kernel_shape stride pad = let inp = N . ones input_shape in let kernel = if seq = false then N . ones kernel_shape else N . sequential ~ a : 1 . kernel_shape in let output = N . transpose_conv3d ~ padding : pad inp kernel stride in let os = N . shape output in let output ' = N . ones os in N . transpose_conv3d_backward_input inp kernel stride output ' |
let compute_trans_conv3d_bk seq input_shape kernel_shape stride pad = let inp = N . ones input_shape in let kernel = N . ones kernel_shape in let output = N . transpose_conv3d ~ padding : pad inp kernel stride in let os = N . shape output in let output ' = if seq = false then N . ones os else N . sequential ~ a : 1 . os in N . transpose_conv3d_backward_kernel inp kernel stride output ' |
let verify_value ( ? seq = false ) fn input_shape kernel_shape stride pad expected = let a = fn seq input_shape kernel_shape stride pad in let output_shape = N . shape a in let b = N . of_array expected output_shape in close a b |
module To_test_transpose_conv3d = struct let fun00 ( ) = let expected = [ | 1 . 0 ; 2 . 0 ; 3 . 0 ; 2 . 0 ; 1 . 0 ; 2 . 0 ; 4 . 0 ; 6 . 0 ; 4 . 0 ; 2 . 0 ; 3 . 0 ; 6 . 0 ; 9 . 0 ; 6 . 0 ; 3 . 0 ; 2 . 0 ; 4 . 0 ; 6 . 0 ; 4 . 0 ; 2 . 0 ; 1 . 0 ; 2 . 0 ; 3 . 0 ; 2 . 0 ; 1 . 0 ] | in verify_value compute_trans_conv3d [ | 1 ; 3 ; 3 ; 1 ; 1 ] | [ | 3 ; 3 ; 1 ; 1 ; 1 ] | [ | 1 ; 1 ; 1 ] | VALID expected let fun01 ( ) = let expected = [ | 2 . ; 2 . ; 4 . ; 2 . ; 2 . ; 2 . ; 4 . ; 2 . ] | in verify_value compute_trans_conv3d [ | 1 ; 2 ; 2 ; 1 ; 1 ] | [ | 3 ; 3 ; 1 ; 1 ; 1 ] | [ | 1 ; 2 ; 1 ] | SAME expected let fun02 ( ) = let expected = [ | 1 . ; 0 . ; 1 . ; 0 . ; 0 . ; 0 . ; 0 . ; 0 . ] | in verify_value compute_trans_conv3d [ | 1 ; 1 ; 2 ; 1 ; 1 ] | [ | 1 ; 1 ; 1 ; 1 ; 1 ] | [ | 2 ; 2 ; 1 ] | SAME expected let fun03 ( ) = let expected = [ | 1 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ; 4 . 0 ; 5 . 0 ; 10 . 0 ; 5 . 0 ; 8 . 0 ; 10 . 0 ; 20 . 0 ; 10 . 0 ; 4 . 0 ; 5 . 0 ; 10 . 0 ; 5 . 0 ] | in verify_value compute_trans_conv3d ~ seq : true [ | 1 ; 2 ; 2 ; 1 ; 1 ] | [ | 3 ; 3 ; 1 ; 1 ; 1 ] | [ | 2 ; 2 ; 1 ] | SAME expected let fun04 ( ) = let expected = [ | 2 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ; 2 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ; 4 . 0 ; 4 . 0 ; 8 . 0 ; 4 . 0 ; 2 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ; 4 . 0 ; 4 . 0 ; 8 . 0 ; 4 . 0 ; 2 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ; 2 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ; 2 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ; 4 . 0 ; 4 . 0 ; 8 . 0 ; 4 . 0 ; 2 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ; 4 . 0 ; 4 . 0 ; 8 . 0 ; 4 . 0 ; 2 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ; 4 . 0 ; 4 . 0 ; 8 . 0 ; 4 . 0 ; 4 . 0 ; 4 . 0 ; 8 . 0 ; 4 . 0 ; 8 . 0 ; 8 . 0 ; 16 . 0 ; 8 . 0 ; 4 . 0 ; 4 . 0 ; 8 . 0 ; 4 . 0 ; 8 . 0 ; 8 . 0 ; 16 . 0 ; 8 . 0 ; 4 . 0 ; 4 . 0 ; 8 . 0 ; 4 . 0 ; 2 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ; 2 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ; 4 . 0 ; 4 . 0 ; 8 . 0 ; 4 . 0 ; 2 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ; 4 . 0 ; 4 . 0 ; 8 . 0 ; 4 . 0 ; 2 . 0 ; 2 . 0 ; 4 . 0 ; 2 . 0 ] | in verify_value compute_trans_conv3d [ | 1 ; 2 ; 3 ; 2 ; 2 ] | [ | 3 ; 3 ; 3 ; 2 ; 1 ] | [ | 2 ; 2 ; 2 ] | SAME expected end |
module To_test_transpose_conv3d_backward = struct let fun00 ( ) = let expected = [ | 9 . ; 9 . ; 9 . ; 9 . ] | in verify_value compute_trans_conv3d_bi [ | 1 ; 2 ; 2 ; 1 ; 1 ] | [ | 3 ; 3 ; 1 ; 1 ; 1 ] | [ | 2 ; 2 ; 1 ] | VALID expected let fun01 ( ) = let expected = [ | 9 . ; 9 . ; 9 . ; 9 . ] | in verify_value compute_trans_conv3d_bi [ | 1 ; 2 ; 2 ; 1 ; 1 ] | [ | 3 ; 3 ; 1 ; 1 ; 1 ] | [ | 1 ; 1 ; 1 ] | VALID expected let fun02 ( ) = let expected = [ | 9 . ; 9 . ; 6 . ; 9 . ; 9 . ; 6 . ; 6 . ; 6 . ; 4 . ] | in verify_value compute_trans_conv3d_bi [ | 1 ; 3 ; 1 ; 3 ; 1 ] | [ | 3 ; 1 ; 3 ; 1 ; 1 ] | [ | 2 ; 1 ; 2 ] | SAME expected let fun03 ( ) = let expected = [ | 4 . ; 6 . ; 6 . ; 4 . ; 6 . ; 9 . ; 9 . ; 6 . ; 6 . ; 9 . ; 9 . ; 6 . ; 4 . ; 6 . ; 6 . ; 4 . ] | in verify_value compute_trans_conv3d_bi [ | 1 ; 4 ; 1 ; 4 ; 1 ] | [ | 3 ; 1 ; 3 ; 1 ; 1 ] | [ | 1 ; 1 ; 1 ] | SAME expected let fun04 ( ) = let expected = [ | 6 . ; 6 . ; 4 . ; 9 . ; 9 . ; 6 . ; 6 . ; 6 . ; 4 . ] | in verify_value compute_trans_conv3d_bi [ | 1 ; 3 ; 3 ; 1 ; 1 ] | [ | 3 ; 3 ; 1 ; 1 ; 1 ] | [ | 1 ; 2 ; 1 ] | SAME expected let fun05 ( ) = let expected = [ | 3 . ; 3 . ; 2 . ; 3 . ; 3 . ; 2 . ; 3 . ; 3 . ; 2 . ] | in verify_value compute_trans_conv3d_bi [ | 1 ; 3 ; 3 ; 1 ; 1 ] | [ | 1 ; 3 ; 1 ; 1 ; 1 ] | [ | 2 ; 2 ; 1 ] | SAME expected let fun06 ( ) = let expected = [ | 45 . ; 27 . ; 21 . ; 12 . ] | in verify_value compute_trans_conv3d_bi ~ seq : true [ | 1 ; 2 ; 2 ; 1 ; 1 ] | [ | 3 ; 3 ; 1 ; 1 ; 1 ] | [ | 2 ; 2 ; 1 ] | SAME expected let fun07 ( ) = let expected = [ | 18 . ; 18 . ; 12 . ; 12 . ; 12 . ; 12 . ; 8 . ; 8 . ] | in verify_value compute_trans_conv3d_bi [ | 1 ; 2 ; 2 ; 1 ; 2 ] | [ | 3 ; 3 ; 1 ; 2 ; 2 ] | [ | 2 ; 2 ; 1 ] | SAME expected let fun08 ( ) = let expected = [ | 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ] | in verify_value compute_trans_conv3d_bk [ | 1 ; 2 ; 1 ; 2 ; 1 ] | [ | 3 ; 1 ; 3 ; 1 ; 1 ] | [ | 2 ; 1 ; 2 ] | VALID expected let fun09 ( ) = let expected = [ | 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ] | in verify_value compute_trans_conv3d_bk [ | 1 ; 2 ; 2 ; 1 ; 1 ] | [ | 3 ; 3 ; 1 ; 1 ; 1 ] | [ | 1 ; 1 ; 1 ] | VALID expected let fun10 ( ) = let expected = [ | 9 . ; 9 . ; 6 . ; 9 . ; 9 . ; 6 . ; 6 . ; 6 . ; 4 . ] | in verify_value compute_trans_conv3d_bk [ | 1 ; 3 ; 3 ; 1 ; 1 ] | [ | 3 ; 3 ; 1 ; 1 ; 1 ] | [ | 2 ; 2 ; 1 ] | SAME expected let fun11 ( ) = let expected = [ | 9 . ; 12 . ; 9 . ; 12 . ; 16 . ; 12 . ; 9 . ; 12 . ; 9 . ] | in verify_value compute_trans_conv3d_bk [ | 1 ; 4 ; 4 ; 1 ; 1 ] | [ | 3 ; 3 ; 1 ; 1 ; 1 ] | [ | 1 ; 1 ; 1 ] | SAME expected let fun12 ( ) = let expected = [ | 6 . ; 6 . ; 4 . ; 9 . ; 9 . ; 6 . ; 6 . ; 6 . ; 4 . ] | in verify_value compute_trans_conv3d_bk [ | 1 ; 3 ; 3 ; 1 ; 1 ] | [ | 3 ; 3 ; 1 ; 1 ; 1 ] | [ | 1 ; 2 ; 1 ] | SAME expected let fun13 ( ) = let expected = [ | 9 . ; 9 . ; 6 . ] | in verify_value compute_trans_conv3d_bk [ | 1 ; 3 ; 1 ; 3 ; 1 ] | [ | 1 ; 1 ; 3 ; 1 ; 1 ] | [ | 2 ; 1 ; 2 ] | SAME expected let fun14 ( ) = let expected = [ | 24 . ; 28 . ; 14 . ; 40 . ; 44 . ; 22 . ; 20 . ; 22 . ; 11 . ] | in verify_value compute_trans_conv3d_bk ~ seq : true [ | 1 ; 2 ; 2 ; 1 ; 1 ] | [ | 3 ; 3 ; 1 ; 1 ; 1 ] | [ | 2 ; 2 ; 1 ] | SAME expected let fun15 ( ) = let expected = [ | 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 2 . ; 2 . ; 2 . ; 2 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 4 . ; 2 . ; 2 . ; 2 . ; 2 . ; 2 . ; 2 . ; 2 . ; 2 . ; 2 . ; 2 . ; 2 . ; 2 . ; 1 . ; 1 . ; 1 . ; 1 . ] | in verify_value compute_trans_conv3d_bk [ | 1 ; 2 ; 1 ; 2 ; 2 ] | [ | 3 ; 1 ; 3 ; 2 ; 2 ] | [ | 2 ; 1 ; 2 ] | SAME expected end |
let fun_ctf00 ( ) = Alcotest . ( check bool ) " fun_ctf00 " true ( To_test_transpose_conv3d . fun00 ( ) ) |
let fun_ctf01 ( ) = Alcotest . ( check bool ) " fun_ctf01 " true ( To_test_transpose_conv3d . fun01 ( ) ) |
let fun_ctf02 ( ) = Alcotest . ( check bool ) " fun_ctf02 " true ( To_test_transpose_conv3d . fun02 ( ) ) |
let fun_ctf03 ( ) = Alcotest . ( check bool ) " fun_ctf03 " true ( To_test_transpose_conv3d . fun03 ( ) ) |
let fun_ctf04 ( ) = Alcotest . ( check bool ) " fun_ctf04 " true ( To_test_transpose_conv3d . fun04 ( ) ) |
let fun_ctb00 ( ) = Alcotest . ( check bool ) " fun_ctb00 " true ( To_test_transpose_conv3d_backward . fun00 ( ) ) |
let fun_ctb01 ( ) = Alcotest . ( check bool ) " fun_ctb01 " true ( To_test_transpose_conv3d_backward . fun01 ( ) ) |
let fun_ctb02 ( ) = Alcotest . ( check bool ) " fun_ctb02 " true ( To_test_transpose_conv3d_backward . fun02 ( ) ) |
let fun_ctb03 ( ) = Alcotest . ( check bool ) " fun_ctb03 " true ( To_test_transpose_conv3d_backward . fun03 ( ) ) |
let fun_ctb04 ( ) = Alcotest . ( check bool ) " fun_ctb04 " true ( To_test_transpose_conv3d_backward . fun04 ( ) ) |
let fun_ctb05 ( ) = Alcotest . ( check bool ) " fun_ctb05 " true ( To_test_transpose_conv3d_backward . fun05 ( ) ) |
let fun_ctb06 ( ) = Alcotest . ( check bool ) " fun_ctb06 " true ( To_test_transpose_conv3d_backward . fun06 ( ) ) |
let fun_ctb07 ( ) = Alcotest . ( check bool ) " fun_ctb07 " true ( To_test_transpose_conv3d_backward . fun07 ( ) ) |
let fun_ctb08 ( ) = Alcotest . ( check bool ) " fun_ctb08 " true ( To_test_transpose_conv3d_backward . fun08 ( ) ) |
let fun_ctb09 ( ) = Alcotest . ( check bool ) " fun_ctb09 " true ( To_test_transpose_conv3d_backward . fun09 ( ) ) |
let fun_ctb10 ( ) = Alcotest . ( check bool ) " fun_ctb10 " true ( To_test_transpose_conv3d_backward . fun10 ( ) ) |
let fun_ctb11 ( ) = Alcotest . ( check bool ) " fun_ctb11 " true ( To_test_transpose_conv3d_backward . fun11 ( ) ) |
let fun_ctb12 ( ) = Alcotest . ( check bool ) " fun_ctb12 " true ( To_test_transpose_conv3d_backward . fun12 ( ) ) |
let fun_ctb13 ( ) = Alcotest . ( check bool ) " fun_ctb13 " true ( To_test_transpose_conv3d_backward . fun13 ( ) ) |
let fun_ctb14 ( ) = Alcotest . ( check bool ) " fun_ctb14 " true ( To_test_transpose_conv3d_backward . fun14 ( ) ) |
let fun_ctb15 ( ) = Alcotest . ( check bool ) " fun_ctb15 " true ( To_test_transpose_conv3d_backward . fun15 ( ) ) |
let test_set = [ " fun_ctf00 " , ` Slow , fun_ctf00 ; " fun_ctf01 " , ` Slow , fun_ctf01 ; " fun_ctf02 " , ` Slow , fun_ctf02 ; " fun_ctf03 " , ` Slow , fun_ctf03 ; " fun_ctf04 " , ` Slow , fun_ctf04 ; " fun_ctb00 " , ` Slow , fun_ctb00 ; " fun_ctb01 " , ` Slow , fun_ctb01 ; " fun_ctb02 " , ` Slow , fun_ctb02 ; " fun_ctb03 " , ` Slow , fun_ctb03 ; " fun_ctb04 " , ` Slow , fun_ctb04 ; " fun_ctb05 " , ` Slow , fun_ctb05 ; " fun_ctb06 " , ` Slow , fun_ctb06 ; " fun_ctb07 " , ` Slow , fun_ctb07 ; " fun_ctb08 " , ` Slow , fun_ctb08 ; " fun_ctb09 " , ` Slow , fun_ctb09 ; " fun_ctb10 " , ` Slow , fun_ctb10 ; " fun_ctb11 " , ` Slow , fun_ctb11 ; " fun_ctb12 " , ` Slow , fun_ctb12 ; " fun_ctb13 " , ` Slow , fun_ctb13 ; " fun_ctb14 " , ` Slow , fun_ctb14 ; " fun_ctb15 " , ` Slow , fun_ctb15 ] |
type t type ' a t type ' + _a t type ' - a t type ( ' a , ' + b , ( ' - c , ' - d ) ) t |
type t = A | B of ' a | C of ' a * ' b | D of ( ' a ) Array . t * ' b list | E of _ |
type t = { f1 : t1 ; f2 : ' a ; mutable f3 : t2 ; f4 : ' a ' b . t2 ; } |
type ' a t constraint ' a = t constraint ' b = ' a type ( ' a , ' + b , ( ' - c , ' - d ) ) t = { f1 : t1 ; f2 : ' a ; mutable f3 : t2 ; f4 : t1 * t2 ; } constraint ' a = t constraint ' b = ' a exception E exception E of ' a t * string exception E ' = E |
' ident _ ( t ) int -> int -> t -> t -> t lab1 : int -> lab2 : ( t ) -> t ? lab1 : ( ? _ : int -> t ) -> t ( t1 * t2 ) * ( t ) int ( ' a -> ' b ) Array . t int as ' bla [ ` _ | ` _ ' | ` _00 | ` Aa of int ] | ` _ | ` _ ' | ` _00 | ` Aa of int ] ` _ | ` _ ' | ` _00 | ` Aa of int ] [ | ` _ | ` _ ' | ` _00 | ` Aa of int ] | ` Bb of int & string & t | int > ` a ` _bbb ` c ` d ] < > < . . > < meth : int option ; meth2 : ' a . ' a option ; meth3 : ' a ' b . ( ' a , ' b ) Hashtbl . t > < meth : int option ; meth2 : ' a . ' a option ; meth3 : ' a ' b . ( ' a , ' b ) Hashtbl . t ; . . > # M . meth ' a # M . meth ( ' a , ' b ' * c ) # M . meth |
module Make ( N : Ndarray_Algodiff with type elt = float ) = struct let tolerance_f64 = 1e - 8 let tolerance_f32 = 5e - 4 let close a b = N . ( sub a b |> abs |> sum ' ) < tolerance_f32 let test_upsampling2d_forward input_shape size = let inp = N . sequential input_shape in let outp = N . upsampling2d inp size in let expected = N . repeat inp [ | 1 ; size . ( 0 ) ; size . ( 1 ) ; 1 ] | in close outp expected let test_upsampling2d_backward input_shape size = let inp = N . ones input_shape in let outp = N . upsampling2d inp size in let out_shp = N . shape outp in let outp ' = N . sequential out_shp in N . upsampling2d_backward inp size outp ' let verify_value input_shape size expected = let a = test_upsampling2d_backward input_shape size in let output_shape ' = N . shape a in assert ( output_shape ' = input_shape ) ; let b = N . of_array expected input_shape in close a b module To_test_upsampling2d = struct let fun00 ( ) = test_upsampling2d_forward [ | 1 ; 8 ; 7 ; 1 ] | [ | 2 ; 2 ] | let fun01 ( ) = test_upsampling2d_forward [ | 1 ; 8 ; 7 ; 1 ] | [ | 2 ; 3 ] | let fun02 ( ) = test_upsampling2d_forward [ | 4 ; 8 ; 7 ; 3 ] | [ | 3 ; 2 ] | let fun03 ( ) = test_upsampling2d_forward [ | 4 ; 8 ; 7 ; 3 ] | [ | 1 ; 1 ] | let fun04 ( ) = let expected = [ | 18 . ; 26 . ; 34 . ; 42 . ; 82 . ; 90 . ; 98 . ; 106 . ; 146 . ; 154 . ; 162 . ; 170 . ] | in verify_value [ | 1 ; 3 ; 4 ; 1 ] | [ | 2 ; 2 ] | expected let fun05 ( ) = let expected = [ | 56 . 0 ; 60 . 0 ; 64 . 0 ; 68 . 0 ; 88 . 0 ; 92 . 0 ; 96 . 0 ; 100 . 0 ; 120 . 0 ; 124 . 0 ; 128 . 0 ; 132 . 0 ; 248 . 0 ; 252 . 0 ; 256 . 0 ; 260 . 0 ; 280 . 0 ; 284 . 0 ; 288 . 0 ; 292 . 0 ; 312 . 0 ; 316 . 0 ; 320 . 0 ; 324 . 0 ] | in verify_value [ | 1 ; 2 ; 3 ; 4 ] | [ | 2 ; 2 ] | expected let fun06 ( ) = let expected = [ | 156 . 0 ; 162 . 0 ; 168 . 0 ; 174 . 0 ; 204 . 0 ; 210 . 0 ; 216 . 0 ; 222 . 0 ; 252 . 0 ; 258 . 0 ; 264 . 0 ; 270 . 0 ; 588 . 0 ; 594 . 0 ; 600 . 0 ; 606 . 0 ; 636 . 0 ; 642 . 0 ; 648 . 0 ; 654 . 0 ; 684 . 0 ; 690 . 0 ; 696 . 0 ; 702 . 0 ] | in verify_value [ | 1 ; 2 ; 3 ; 4 ] | [ | 3 ; 2 ] | expected let fun07 ( ) = let expected = [ | 66 . 0 ; 72 . 0 ; 102 . 0 ; 108 . 0 ; 138 . 0 ; 144 . 0 ; 282 . 0 ; 288 . 0 ; 318 . 0 ; 324 . 0 ; 354 . 0 ; 360 . 0 ; 498 . 0 ; 504 . 0 ; 534 . 0 ; 540 . 0 ; 570 . 0 ; 576 . 0 ; 714 . 0 ; 720 . 0 ; 750 . 0 ; 756 . 0 ; 786 . 0 ; 792 . 0 ; 930 . 0 ; 936 . 0 ; 966 . 0 ; 972 . 0 ; 1002 . 0 ; 1008 . 0 ; 1146 . 0 ; 1152 . 0 ; 1182 . 0 ; 1188 . 0 ; 1218 . 0 ; 1224 . 0 ] | in verify_value [ | 3 ; 2 ; 3 ; 2 ] | [ | 2 ; 3 ] | expected let fun08 ( ) = let expected = [ | 0 . ; 1 . ; 2 . ; 3 . ; 4 . ; 5 . ; 6 . ; 7 . ; 8 . ; 9 . ; 10 . ; 11 . ; 12 . ; 13 . ; 14 . ; 15 . ; 16 . ; 17 . ; 18 . ; 19 . ; 20 . ; 21 . ; 22 . ; 23 . ; 24 . ; 25 . ; 26 . ; 27 . ; 28 . ; 29 . ] | in verify_value [ | 1 ; 5 ; 6 ; 1 ] | [ | 1 ; 1 ] | expected end let fun_us2d00 ( ) = Alcotest . ( check bool ) " fun_us2d00 " true ( To_test_upsampling2d . fun00 ( ) ) let fun_us2d01 ( ) = Alcotest . ( check bool ) " fun_us2d01 " true ( To_test_upsampling2d . fun01 ( ) ) let fun_us2d02 ( ) = Alcotest . ( check bool ) " fun_us2d02 " true ( To_test_upsampling2d . fun02 ( ) ) let fun_us2d03 ( ) = Alcotest . ( check bool ) " fun_us2d03 " true ( To_test_upsampling2d . fun03 ( ) ) let fun_us2d04 ( ) = Alcotest . ( check bool ) " fun_us2d04 " true ( To_test_upsampling2d . fun04 ( ) ) let fun_us2d05 ( ) = Alcotest . ( check bool ) " fun_us2d05 " true ( To_test_upsampling2d . fun05 ( ) ) let fun_us2d06 ( ) = Alcotest . ( check bool ) " fun_us2d06 " true ( To_test_upsampling2d . fun06 ( ) ) let fun_us2d07 ( ) = Alcotest . ( check bool ) " fun_us2d07 " true ( To_test_upsampling2d . fun07 ( ) ) let fun_us2d08 ( ) = Alcotest . ( check bool ) " fun_us2d08 " true ( To_test_upsampling2d . fun08 ( ) ) let test_set = [ " fun_us2d00 " , ` Slow , fun_us2d00 ; " fun_us2d01 " , ` Slow , fun_us2d01 ; " fun_us2d02 " , ` Slow , fun_us2d02 ; " fun_us2d03 " , ` Slow , fun_us2d03 ; " fun_us2d04 " , ` Slow , fun_us2d04 ; " fun_us2d05 " , ` Slow , fun_us2d05 ; " fun_us2d06 " , ` Slow , fun_us2d06 ; " fun_us2d07 " , ` Slow , fun_us2d07 ; " fun_us2d08 " , ` Slow , fun_us2d08 ] end |
module V = Owl_view . Make ( N ) |
let x0 = N . sequential [ | 10 ] | |> V . of_arr |
let x1 = N . sequential [ | 10 ; 10 ] | |> V . of_arr |
let x2 = N . sequential [ | 10 ; 10 ; 10 ] | |> V . of_arr |
let x3 = N . sequential [ | 5 ; 5 ; 5 ; 5 ] | |> V . of_arr |
module To_test = struct let test_01 ( ) = let s = [ [ ] ] in let y = V . get_slice s x0 in V . equal y x0 let test_02 ( ) = let s = [ [ 3 ] ] in let y = V . get_slice s x0 in let z = N . of_array [ | 3 . ] | [ | 1 ] | in V . equal y ( V . of_arr z ) let test_03 ( ) = let s = [ [ 2 ; 5 ] ] in let y = V . get_slice s x0 in let z = N . of_array [ | 2 . ; 3 . ; 4 . ; 5 . ] | [ | 4 ] | in V . equal y ( V . of_arr z ) let test_04 ( ) = let s = [ [ 2 ; - 1 ; 3 ] ] in let y = V . get_slice s x0 in let z = N . of_array [ | 2 . ; 5 . ; 8 . ] | [ | 3 ] | in V . equal y ( V . of_arr z ) let test_05 ( ) = let s = [ [ - 2 ; 5 ] ] in let y = V . get_slice s x0 in let z = N . of_array [ | 8 . ; 7 . ; 6 . ; 5 . ] | [ | 4 ] | in V . equal y ( V . of_arr z ) let test_06 ( ) = let s = [ [ - 2 ; 4 ; - 2 ] ] in let y = V . get_slice s x0 in let z = N . of_array [ | 8 . ; 6 . ; 4 . ] | [ | 3 ] | in V . equal y ( V . of_arr z ) let test_07 ( ) = let s = [ [ ] ; [ ] ] in let y = V . get_slice s x1 in V . equal y x1 let test_08 ( ) = let s = [ [ 2 ] ; [ ] ] in let y = V . get_slice s x1 in let z = N . of_array [ | 20 . ; 21 . ; 22 . ; 23 . ; 24 . ; 25 . ; 26 . ; 27 . ; 28 . ; 29 . ] | [ | 1 ; 10 ] | in V . equal y ( V . of_arr z ) let test_09 ( ) = let s = [ [ 0 ; 5 ] ; [ ] ] in let y = V . get_slice s x1 in let z = N . sequential [ | 6 ; 10 ] | in V . equal y ( V . of_arr z ) let test_10 ( ) = let s = [ [ 0 ; 5 ; 2 ] ; [ ] ] in let y = V . get_slice s x1 in let z = N . of_array [ | 0 . ; 1 . ; 2 . ; 3 . ; 4 . ; 5 . ; 6 . ; 7 . ; 8 . ; 9 . ; 20 . ; 21 . ; 22 . ; 23 . ; 24 . ; 25 . ; 26 . ; 27 . ; 28 . ; 29 . ; 40 . ; 41 . ; 42 . ; 43 . ; 44 . ; 45 . ; 46 . ; 47 . ; 48 . ; 49 . ] | [ | 3 ; 10 ] | in V . equal y ( V . of_arr z ) let test_11 ( ) = let s = [ [ 5 ; 0 ; - 2 ] ; [ ] ] in let y = V . get_slice s x1 in let z = N . of_array [ | 50 . ; 51 . ; 52 . ; 53 . ; 54 . ; 55 . ; 56 . ; 57 . ; 58 . ; 59 . ; 30 . ; 31 . ; 32 . ; 33 . ; 34 . ; 35 . ; 36 . ; 37 . ; 38 . ; 39 . ; 10 . ; 11 . ; 12 . ; 13 . ; 14 . ; 15 . ; 16 . ; 17 . ; 18 . ; 19 . ] | [ | 3 ; 10 ] | in V . equal y ( V . of_arr z ) let test_12 ( ) = let s = [ [ 0 ; 5 ; 2 ] ; [ 1 ; 5 ] ] in let y = V . get_slice s x1 in let z = N . of_array [ | 1 . ; 2 . ; 3 . ; 4 . ; 5 . ; 21 . ; 22 . ; 23 . ; 24 . ; 25 . ; 41 . ; 42 . ; 43 . ; 44 . ; 45 . ] | [ | 3 ; 5 ] | in V . equal y ( V . of_arr z ) let test_13 ( ) = let s = [ [ 0 ; 5 ; 2 ] ; [ 1 ; 5 ; 3 ] ] in let y = V . get_slice s x1 in let z = N . of_array [ | 1 . ; 4 . ; 21 . ; 24 . ; 41 . ; 44 . ] | [ | 3 ; 2 ] | in V . equal y ( V . of_arr z ) let test_14 ( ) = let s = [ [ 0 ; 5 ; 2 ] ; [ - 5 ; 1 ] ] in let y = V . get_slice s x1 in let z = N . of_array [ | 5 . ; 4 . ; 3 . ; 2 . ; 1 . ; 25 . ; 24 . ; 23 . ; 22 . ; 21 . ; 45 . ; 44 . ; 43 . ; 42 . ; 41 . ] | [ | 3 ; 5 ] | in V . equal y ( V . of_arr z ) let test_15 ( ) = let s = [ [ 0 ; 5 ; 2 ] ; [ - 5 ; 1 ; - 2 ] ] in let y = V . get_slice s x1 in let z = N . of_array [ | 5 . ; 3 . ; 1 . ; 25 . ; 23 . ; 21 . ; 45 . ; 43 . ; 41 . ] | [ | 3 ; 3 ] | in V . equal y ( V . of_arr z ) let test_16 ( ) = let s = [ [ ] ; [ ] ; [ ] ] in let y = V . get_slice s x2 in V . equal y x2 let test_17 ( ) = let s = [ [ 0 ] ; [ ] ; [ ] ] in let y = V . get_slice s x2 in let z = N . sequential [ | 1 ; 10 ; 10 ] | in V . equal y ( V . of_arr z ) let test_18 ( ) = let s = [ [ 1 ] ; [ 2 ] ; [ ] ] in let y = V . get_slice s x2 in let z = N . of_array [ | 120 . ; 121 . ; 122 . ; 123 . ; 124 . ; 125 . ; 126 . ; 127 . ; 128 . ; 129 . ] | [ | 1 ; 1 ; 10 ] | in V . equal y ( V . of_arr z ) let test_19 ( ) = let s = [ [ 0 ; 5 ; 3 ] ; [ 0 ; 5 ; 3 ] ; [ 0 ; 2 ] ] in let y = V . get_slice s x2 in let z = N . of_array [ | 0 . ; 1 . ; 2 . ; 30 . ; 31 . ; 32 . ; 300 . ; 301 . ; 302 . ; 330 . ; 331 . ; 332 . ] | [ | 2 ; 2 ; 3 ] | in V . equal y ( V . of_arr z ) let test_20 ( ) = let s = [ [ 1 ] ; [ 2 ] ; [ 3 ] ] in let y = V . get_slice s x2 in let z = N . of_array [ | 123 . ] | [ | 1 ; 1 ; 1 ] | in V . equal y ( V . of_arr z ) let test_21 ( ) = let s = [ [ - 1 ; 0 ] ; [ - 1 ; 0 ] ; [ - 1 ; 0 ] ] in let y = V . get_slice s x2 in let z = N . reverse ( V . to_arr x2 ) in V . equal y ( V . of_arr z ) let test_22 ( ) = let s = [ [ - 1 ; 0 ] ; [ - 1 ; 0 ] ; [ - 1 ; 0 ] ; [ - 1 ; 0 ] ] in let y = V . get_slice s x3 in let z = N . reverse ( V . to_arr x3 ) in V . equal y ( V . of_arr z ) let test_23 ( ) = let s = [ [ 0 ; 2 ] ] in let x = V . to_arr x0 |> V . of_arr in let y = N . of_array [ | 2 . ; 3 . ; 5 . ] | [ | 3 ] | in V . set_slice s x ( V . of_arr y ) ; let z = N . of_array [ | 2 . ; 3 . ; 5 . ; 3 . ; 4 . ; 5 . ; 6 . ; 7 . ; 8 . ; 9 . ] | [ | 10 ] | in V . equal x ( V . of_arr z ) let test_24 ( ) = let s = [ [ 5 ; 3 ] ] in let x = V . to_arr x0 |> V . of_arr in let y = N . of_array [ | 2 . ; 3 . ; 5 . ] | [ | 3 ] | in V . set_slice s x ( V . of_arr y ) ; let z = N . of_array [ | 0 . ; 1 . ; 2 . ; 5 . ; 3 . ; 2 . ; 6 . ; 7 . ; 8 . ; 9 . ] | [ | 10 ] | in V . equal x ( V . of_arr z ) let test_25 ( ) = let s = [ [ 2 ; 8 ; 3 ] ] in let x = V . to_arr x0 |> V . of_arr in let y = N . of_array [ | 2 . ; 3 . ; 5 . ] | [ | 3 ] | in V . set_slice s x ( V . of_arr y ) ; let z = N . of_array [ | 0 . ; 1 . ; 2 . ; 3 . ; 4 . ; 3 . ; 6 . ; 7 . ; 5 . ; 9 . ] | [ | 10 ] | in V . equal x ( V . of_arr z ) let test_26 ( ) = let s = [ [ - 1 ] ; [ - 1 ] ] in let x = V . to_arr x1 |> V . of_arr in let y = N . of_array [ | 0 . ] | [ | 1 ; 1 ] | in V . set_slice s x ( V . of_arr y ) ; let z = V . to_arr x1 in N . set z [ | 9 ; 9 ] | 0 . ; V . equal x ( V . of_arr z ) let test_27 ( ) = let s = [ [ 0 ; 9 ; 9 ] ; [ 0 ; 9 ; 9 ] ] in let x = V . to_arr x1 |> V . of_arr in let y = N . of_array [ | 5 . ; 6 . ; 7 . ; 8 . ] | [ | 2 ; 2 ] | in V . set_slice s x ( V . of_arr y ) ; let z = V . to_arr x1 in N . set z [ | 0 ; 0 ] | 5 . ; N . set z [ | 0 ; 9 ] | 6 . ; N . set z [ | 9 ; 0 ] | 7 . ; N . set z [ | 9 ; 9 ] | 8 . ; V . equal x ( V . of_arr z ) let test_28 ( ) = let s = [ [ - 1 ; 0 ; - 9 ] ; [ - 1 ; 0 ; - 9 ] ] in let x = V . to_arr x1 |> V . of_arr in let y = N . of_array [ | 5 . ; 6 . ; 7 . ; 8 . ] | [ | 2 ; 2 ] | in V . set_slice s x ( V . of_arr y ) ; let z = V . to_arr x1 in N . set z [ | 0 ; 0 ] | 8 . ; N . set z [ | 0 ; 9 ] | 7 . ; N . set z [ | 9 ; 0 ] | 6 . ; N . set z [ | 9 ; 9 ] | 5 . ; V . equal x ( V . of_arr z ) let test_29 ( ) = let s = [ [ - 1 ] ; [ - 1 ] ; [ - 2 ] ] in let x = V . to_arr x2 |> V . of_arr in let y = N . of_array [ | 5 . ] | [ | 1 ; 1 ; 1 ] | in V . set_slice s x ( V . of_arr y ) ; let z = V . to_arr x2 in N . set z [ | 9 ; 9 ; 8 ] | 5 . ; V . equal x ( V . of_arr z ) let test_30 ( ) = let s = [ [ - 1 ] ; [ 5 ; 6 ] ; [ 0 ] ] in let x = V . to_arr x2 |> V . of_arr in let y = N . of_array [ | 1 . ; 2 . ] | [ | 1 ; 2 ; 1 ] | in V . set_slice s x ( V . of_arr y ) ; let z = V . to_arr x2 in N . set z [ | 9 ; 5 ; 0 ] | 1 . ; N . set z [ | 9 ; 6 ; 0 ] | 2 . ; V . equal x ( V . of_arr z ) end |
let test_01 ( ) = Alcotest . ( check bool ) " test 01 " true ( To_test . test_01 ( ) ) |
let test_02 ( ) = Alcotest . ( check bool ) " test 02 " true ( To_test . test_02 ( ) ) |
let test_03 ( ) = Alcotest . ( check bool ) " test 03 " true ( To_test . test_03 ( ) ) |
let test_04 ( ) = Alcotest . ( check bool ) " test 04 " true ( To_test . test_04 ( ) ) |
let test_05 ( ) = Alcotest . ( check bool ) " test 05 " true ( To_test . test_05 ( ) ) |
let test_06 ( ) = Alcotest . ( check bool ) " test 06 " true ( To_test . test_06 ( ) ) |
let test_07 ( ) = Alcotest . ( check bool ) " test 07 " true ( To_test . test_07 ( ) ) |
let test_08 ( ) = Alcotest . ( check bool ) " test 08 " true ( To_test . test_08 ( ) ) |
let test_09 ( ) = Alcotest . ( check bool ) " test 09 " true ( To_test . test_09 ( ) ) |
let test_10 ( ) = Alcotest . ( check bool ) " test 10 " true ( To_test . test_10 ( ) ) |
let test_11 ( ) = Alcotest . ( check bool ) " test 11 " true ( To_test . test_11 ( ) ) |
let test_12 ( ) = Alcotest . ( check bool ) " test 12 " true ( To_test . test_12 ( ) ) |
let test_13 ( ) = Alcotest . ( check bool ) " test 13 " true ( To_test . test_13 ( ) ) |
let test_14 ( ) = Alcotest . ( check bool ) " test 14 " true ( To_test . test_14 ( ) ) |
let test_15 ( ) = Alcotest . ( check bool ) " test 15 " true ( To_test . test_15 ( ) ) |
let test_16 ( ) = Alcotest . ( check bool ) " test 16 " true ( To_test . test_16 ( ) ) |
let test_17 ( ) = Alcotest . ( check bool ) " test 17 " true ( To_test . test_17 ( ) ) |
let test_18 ( ) = Alcotest . ( check bool ) " test 18 " true ( To_test . test_18 ( ) ) |
let test_19 ( ) = Alcotest . ( check bool ) " test 19 " true ( To_test . test_19 ( ) ) |
let test_20 ( ) = Alcotest . ( check bool ) " test 20 " true ( To_test . test_20 ( ) ) |
let test_21 ( ) = Alcotest . ( check bool ) " test 21 " true ( To_test . test_21 ( ) ) |
let test_22 ( ) = Alcotest . ( check bool ) " test 22 " true ( To_test . test_22 ( ) ) |
let test_23 ( ) = Alcotest . ( check bool ) " test 23 " true ( To_test . test_23 ( ) ) |
let test_24 ( ) = Alcotest . ( check bool ) " test 24 " true ( To_test . test_24 ( ) ) |
let test_25 ( ) = Alcotest . ( check bool ) " test 25 " true ( To_test . test_25 ( ) ) |
let test_26 ( ) = Alcotest . ( check bool ) " test 26 " true ( To_test . test_26 ( ) ) |
let test_27 ( ) = Alcotest . ( check bool ) " test 27 " true ( To_test . test_27 ( ) ) |
let test_28 ( ) = Alcotest . ( check bool ) " test 28 " true ( To_test . test_28 ( ) ) |
let test_29 ( ) = Alcotest . ( check bool ) " test 29 " true ( To_test . test_29 ( ) ) |
let test_30 ( ) = Alcotest . ( check bool ) " test 30 " true ( To_test . test_30 ( ) ) |
let test_set = [ " test 01 " , ` Slow , test_01 ; " test 02 " , ` Slow , test_02 ; " test 03 " , ` Slow , test_03 ; " test 04 " , ` Slow , test_04 ; " test 05 " , ` Slow , test_05 ; " test 06 " , ` Slow , test_06 ; " test 07 " , ` Slow , test_07 ; " test 08 " , ` Slow , test_08 ; " test 09 " , ` Slow , test_09 ; " test 10 " , ` Slow , test_10 ; " test 11 " , ` Slow , test_11 ; " test 12 " , ` Slow , test_12 ; " test 13 " , ` Slow , test_13 ; " test 14 " , ` Slow , test_14 ; " test 15 " , ` Slow , test_15 ; " test 16 " , ` Slow , test_16 ; " test 17 " , ` Slow , test_17 ; " test 18 " , ` Slow , test_18 ; " test 19 " , ` Slow , test_19 ; " test 20 " , ` Slow , test_20 ; " test 21 " , ` Slow , test_21 ; " test 22 " , ` Slow , test_22 ; " test 23 " , ` Slow , test_23 ; " test 24 " , ` Slow , test_24 ; " test 25 " , ` Slow , test_25 ; " test 26 " , ` Slow , test_26 ; " test 27 " , ` Slow , test_27 ; " test 28 " , ` Slow , test_28 ; " test 29 " , ` Slow , test_29 ; " test 30 " , ` Slow , test_30 ] |
let clientlst = ref [ ] |
type ( ' a , ' b ) t = State of ' a | Bundle of ' a * ( iworld_t * ' b ) list * iworld_t list |
let rec sendmail lst1 = match lst1 with [ ] -> ( ) | ( first1 , first2 ) :: rest -> begin if List . mem_assoc first1 ! clientlst then Socket . send ( Some first2 ) first1 ; sendmail rest end |
let initial_new state iworld = State state |
let initial_msg state iworld sexp = State state |
let initial_tick state = State state |
let initial_disconnect state iworld = Bundle ( state , [ ] , [ iworld ] ) |
let universe ( ? on_new = initial_new ) ( ? on_msg = initial_msg ) ( ? rate = 1 . 0 ) ( ? on_tick = initial_tick ) ( ? on_disconnect = initial_disconnect ) initial_state = let rate = int_of_float ( 1000 . . * rate ) in let state = ref initial_state in let server_sockfd = Socket . make_sockfd ( ) in let cut_communication client_sockfd = if List . mem_assoc client_sockfd ! clientlst then begin clientlst := List . remove_assoc client_sockfd ! clientlst ; Socket . close client_sockfd ; ! clientlst = [ ] end else false in let rec update_and_send result = match result with State newstate -> state := newstate | Bundle ( newstate , maillst , iworldlst ) -> state := newstate ; match iworldlst with first :: rest -> Socket . send None first ; GMain . Io . remove ( List . assoc first ! clientlst ) ; if cut_communication first then state := initial_state else update_and_send ( Bundle ( ! state , maillst , rest ) ) | _ -> sendmail maillst in let makemail client_sockfd = if ( List . mem_assoc client_sockfd ! clientlst ) then let result = let message = try Socket . receive client_sockfd with _ -> None in match message with None -> on_disconnect ! state client_sockfd | Some m -> on_msg ! state client_sockfd m in update_and_send result ; in let msg_event _ = let readlst = Socket . select_read ( fst ( List . split ! clientlst ) ) in List . iter makemail readlst ; true in let new_event _ = let client_sockfd = Socket . new_client_sockfd server_sockfd in let wid = ( GMain . Io . add_watch ~ cond [ ` : IN ] ~ callback : msg_event ( GMain . Io . channel_of_descr client_sockfd ) ) in clientlst := ( client_sockfd , wid ) :: ! clientlst ; let result = on_new ! state client_sockfd in update_and_send result ; true in let time_event _ = let result = on_tick ! state in update_and_send result ; true in Socket . listen server_sockfd ; let port_number = Socket . portnum server_sockfd in print_endline ( string_of_int port_number ) ; flush stdout ; ignore ( GMain . Io . add_watch ~ cond [ ` : IN ] ~ callback : new_event ( GMain . Io . channel_of_descr server_sockfd ) ) ; ignore ( GMain . Timeout . add ~ ms : rate ~ callback : time_event ) ; GMain . Main . main ( ) |
module Key = struct module Witness = struct type ' a t = . . end module type T = sig type t type ' a Witness . t += T : t Witness . t val id : int val name : string val to_dyn : t -> Dyn . t end type ' a t = ( module T with type t = ' a ) let next = ref 0 let create ( type a ) ~ name to_dyn = let n = ! next in next := n + 1 ; let module M = struct type t = a type ' a Witness . t += T : t Witness . t let id = n let to_dyn = to_dyn let name = name end in ( module M : T with type t = a ) let id ( type a ) ( module M : T with type t = a ) = M . id let eq ( type a b ) ( module A : T with type t = a ) ( module B : T with type t = b ) : ( a , b ) Type_eq . t = match A . T with | B . T -> Type_eq . T | _ -> assert false end |
module Binding = struct type t = T : ' a Key . t * ' a -> t end |
type t = Binding . t Int . Map . t |
let set ( type a ) t ( key : a Key . t ) x = let ( module M ) = key in let data = Binding . T ( key , x ) in Int . Map . set t M . id data |
let add ( type a ) t ( key : a Key . t ) ( x : a ) : ( t , a ) Result . t = let ( module M ) = key in let data = Binding . T ( key , x ) in match Int . Map . add t M . id data with | Ok x -> Ok x | Error ( Binding . T ( key ' , x ) ) -> let eq = Key . eq key ' key in Error ( Type_eq . cast eq x ) |
let update ( type a ) t ( key : a Key . t ) ~ f = let ( module M ) = key in Int . Map . update t M . id ~ f ( : function | None -> f None |> Option . map ~ f ( : fun x -> Binding . T ( key , x ) ) | Some ( Binding . T ( key ' , x ) ) -> let eq = Key . eq key ' key in let x = Type_eq . cast eq x in f ( Some x ) |> Option . map ~ f ( : fun x -> Binding . T ( key , x ) ) ) |
let mem t key = Int . Map . mem t ( Key . id key ) |
let remove t key = Int . Map . remove t ( Key . id key ) |
let find t key = match Int . Map . find t ( Key . id key ) with | None -> None | Some ( Binding . T ( key ' , v ) ) -> let eq = Key . eq key ' key in Some ( Type_eq . cast eq v ) |
let find_exn t key = match Int . Map . find t ( Key . id key ) with | None -> failwith " Univ_map . find_exn " | Some ( Binding . T ( key ' , v ) ) -> let eq = Key . eq key ' key in Type_eq . cast eq v |
let singleton key v = Int . Map . singleton ( Key . id key ) ( Binding . T ( key , v ) ) |
let to_dyn ( t : t ) = let open Dyn . Encoder in Dyn . Map ( Int . Map . values t |> List . map ~ f ( : fun ( Binding . T ( key , v ) ) -> let ( module K ) = key in ( string K . name , K . to_dyn v ) ) ) |
module type S = sig type t module Key : sig type ' a t val create : name : string -> ( ' a -> Dyn . t ) -> ' a t end val empty : t val is_empty : t -> bool val mem : t -> ' a Key . t -> bool val set : t -> ' a Key . t -> ' a -> t val add : t -> ' a Key . t -> ' a -> ( t , ' a ) Result . t val update : t -> ' a Key . t -> f ( ' : a option -> ' a option ) -> t val remove : t -> ' a Key . t -> t val find : t -> ' a Key . t -> ' a option val find_exn : t -> ' a Key . t -> ' a val singleton : ' a Key . t -> ' a -> t val superpose : t -> t -> t val to_dyn : t -> Dyn . t val to_dyns : t -> ( string * Dyn . t ) list end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.