text
stringlengths
0
601k
let cut = test " String . Sub . cut " @@ fun ( ) -> let ppp = pp_option pp_pair in let eqo = eqs_pair_opt in let s s = String . sub ~ start : 1 ~ stop ( : 1 + ( String . length s ) ) ( strf " \ x00 % s \ x00 " s ) in let cut ? rev ~ sep str = String . Sub . cut ? rev ~ sep ( : s sep ) ( s str ) in app_invalid ~ pp : pp...
let cuts = test " String . Sub . cuts " @@ fun ( ) -> let ppl = pp_list String . Sub . dump in let eql subs l = let subs = List . map String . Sub . to_string subs in eq_list ~ eq : String . equal ~ pp : String . dump subs l in let s s = String . sub ~ start : 1 ~ stop ( : 1 + ( String . length s ) ) ( strf " \ x00 % s...
let fields = test " String . Sub . fields " @@ fun ( ) -> let eql subs l = let subs = List . map String . Sub . to_string subs in eq_list ~ eq : String . equal ~ pp : String . dump subs l in let s s = String . sub ~ start : 1 ~ stop ( : 1 + ( String . length s ) ) ( strf " \ x00 % s \ x00 " s ) in let fields ? empty ? ...
let find = test " String . Sub . find " @@ fun ( ) -> let abcbd = " abcbd " in let empty = String . sub ~ start : 3 ~ stop : 3 abcbd in let a = String . sub ~ start : 0 ~ stop : 1 abcbd in let ab = String . sub ~ start : 0 ~ stop : 2 abcbd in let c = String . sub ~ start : 2 ~ stop : 3 abcbd in let b0 = String . sub ~ ...
let find_sub = test " String . Sub . find_sub " @@ fun ( ) -> let abcbd = " abcbd " in let empty = String . sub ~ start : 3 ~ stop : 3 abcbd in let ab = String . sub ~ start : 0 ~ stop : 2 abcbd in let b0 = String . sub ~ start : 1 ~ stop : 2 abcbd in let b1 = String . sub ~ start : 3 ~ stop : 4 abcbd in let abcbd = St...
let map = test " String . Sub . map [ i ] " @@ fun ( ) -> let next_letter c = Char . ( of_byte @@ to_int c + 1 ) in let base = " i34abcdbbb " in let abcd = String . Sub . v ~ start : 3 ~ stop : 7 base in let empty = String . Sub . v ~ start : 2 ~ stop : 2 base in eqs ( String . Sub . map ( fun c -> fail " invoked " ; c...
let fold = test " String . Sub . fold_ { left , right } " @@ fun ( ) -> let empty = String . Sub . v ~ start : 2 ~ stop : 2 " ab " in let abc = String . Sub . v ~ start : 3 ~ stop : 6 " i34abcdbbb " in let eql = eq_list ~ eq ( ) := ~ pp : pp_char in String . Sub . fold_left ( fun _ _ -> fail " invoked " ) ( ) empty ; e...
let iter = test " String . Sub . iter [ i ] " @@ fun ( ) -> let empty = String . Sub . v ~ start : 2 ~ stop : 2 " ab " in let abc = String . Sub . v ~ start : 3 ~ stop : 6 " i34abcdbbb " in String . Sub . iter ( fun _ -> fail " invoked " ) empty ; String . Sub . iteri ( fun _ _ -> fail " invoked " ) empty ; ( let i = r...
let suite = suite " Base String functions " [ misc ; head ; to_string ; start ; stop ; tail ; base ; extend ; reduce ; extent ; overlap ; append ; concat ; is_empty ; is_prefix ; is_infix ; is_suffix ; for_all ; exists ; same_base ; equal_bytes ; compare_bytes ; equal ; compare ; with_range ; with_index_range ; span ; ...
let print_expr expr = Pprintast . string_of_structure [ % str let ( ) = [ % e expr ] ] |> print_string ; ; Ppx_let_expander . expand ~ modul : None Sub [ % expr let MY_PAT = MY_EXPR in MY_BODY ] |> print_expr ; [ % expect { | let ( ) = Let_syntax . sub MY_EXPR ~ f ( : fun ( MY_PAT ) -> MY_BODY ) } ] | ; ; Ppx_let_expan...
let assert_fails_with_syntax_error ~ f = try ignore ( f ( ) ) ; assert false with | ex -> Location . Error . of_exn ex |> ( fun a -> Option . value_exn a ) |> Location . Error . message |> print_endline ; ; assert_fails_with_syntax_error ~ f ( : fun ( ) -> Ppx_let_expander . expand ~ modul : None Sub [ % expr let MY_PA...
module Test ( Base : sig type t val of_string : string -> t end ) ( Substring : Substring . S with type base = Base . t ) : sig end = struct open Substring let % test_module " get " = ( module struct let hello = Base . of_string " hello " let % test _ = let lo = create ~ pos : 3 ~ len : 2 hello in Char . equal ( get lo...
let ( ) += r x = r := ! r + x
let compat3 = match Sundials . Config . sundials_version with | 3 , _ , _ -> true | _ -> false
module ArrayBand_tests = struct type k = Matrix . custom type m = Matrix . ArrayBand . t type nd = Nvector_serial . data type nk = Nvector_serial . kind type t = nk Matrix . arrayband type nvec = Nvector_serial . t let rewrap = Matrix . wrap_arrayband let check_matrix a b tol = let ca , cb = Matrix . ( unwrap a , unwra...
module Test = Test_matrix . Test ( ArrayBand_tests ) ( Nvector_serial . Ops )
let main ( ) = let fails = ref 0 in if Array . length Sys . argv < 5 then ( printf " ERROR : FOUR ( 4 ) Inputs required : matrix cols , matrix uband , matrix lband , print timing @\ n " ; exit ( - 1 ) ) ; let cols = int_of_string Sys . argv . ( 1 ) in if cols <= 0 then ( printf " ERROR : number of matrix columns must b...
let reps = try int_of_string ( Unix . getenv " NUM_REPS " ) with Not_found | Failure _ -> 1
let gc_at_end = try int_of_string ( Unix . getenv " GC_AT_END " ) <> 0 with Not_found | Failure _ -> false
let gc_each_rep = try int_of_string ( Unix . getenv " GC_EACH_REP " ) <> 0 with Not_found | Failure _ -> false
let _ = for _ = 1 to reps do main ( ) ; if gc_each_rep then Gc . compact ( ) done ; if gc_at_end then Gc . compact ( )
let ( ) += r x = r := ! r + x
let compat2_3 = match Sundials . Config . sundials_version with | 2 , _ , _ -> true | 3 , _ , _ -> true | _ -> false
module ArrayDense_tests = struct type k = Matrix . custom type m = Matrix . ArrayDense . t type nd = Nvector_serial . data type nk = Nvector_serial . kind type t = nk Matrix . arraydense type nvec = Nvector_serial . t let rewrap = Matrix . wrap_arraydense let check_matrix a b tol = let ca , cb = Matrix . ( unwrap a , u...
module Test = Test_matrix . Test ( ArrayDense_tests ) ( Nvector_serial . Ops )
let main ( ) = let fails = ref 0 in if Array . length Sys . argv < 4 then ( printf " ERROR : THREE ( 3 ) Input required : matrix rows , matrix cols , print timing @\ n " ; exit ( - 1 ) ) ; let matrows = int_of_string Sys . argv . ( 1 ) in if matrows <= 0 then ( printf " ERROR : number of rows must be a positive integer...
let reps = try int_of_string ( Unix . getenv " NUM_REPS " ) with Not_found | Failure _ -> 1
let gc_at_end = try int_of_string ( Unix . getenv " GC_AT_END " ) <> 0 with Not_found | Failure _ -> false
let gc_each_rep = try int_of_string ( Unix . getenv " GC_EACH_REP " ) <> 0 with Not_found | Failure _ -> false
let _ = for _ = 1 to reps do main ( ) ; if gc_each_rep then Gc . compact ( ) done ; if gc_at_end then Gc . compact ( )
let ( ) += r x = r := ! r + x
let compat3 = match Sundials . Config . sundials_version with | 3 , _ , _ -> true | _ -> false
module Band_tests = struct type k = Matrix . standard type m = Matrix . Band . t type nd = Nvector_serial . data type nk = Nvector_serial . kind type t = nk Matrix . band type nvec = Nvector_serial . t let rewrap = Matrix . wrap_band let check_matrix a b tol = let ca , cb = Matrix . ( unwrap a , unwrap b ) in let open ...
module Test = Test_matrix . Test ( Band_tests ) ( Nvector_serial . Ops )
let main ( ) = let fails = ref 0 in if Array . length Sys . argv < 5 then ( printf " ERROR : FOUR ( 4 ) Inputs required : matrix cols , matrix uband , matrix lband , print timing @\ n " ; exit ( - 1 ) ) ; let cols = int_of_string Sys . argv . ( 1 ) in if cols <= 0 then ( printf " ERROR : number of matrix columns must b...
let reps = try int_of_string ( Unix . getenv " NUM_REPS " ) with Not_found | Failure _ -> 1
let gc_at_end = try int_of_string ( Unix . getenv " GC_AT_END " ) <> 0 with Not_found | Failure _ -> false
let gc_each_rep = try int_of_string ( Unix . getenv " GC_EACH_REP " ) <> 0 with Not_found | Failure _ -> false
let _ = for _ = 1 to reps do main ( ) ; if gc_each_rep then Gc . compact ( ) done ; if gc_at_end then Gc . compact ( )
let ( ) += r x = r := ! r + x
let compat2_3 = match Sundials . Config . sundials_version with | 2 , _ , _ -> true | 3 , _ , _ -> true | _ -> false
module Dense_tests = struct type k = Matrix . standard type m = Matrix . Dense . t type nd = Nvector_serial . data type nk = Nvector_serial . kind type t = nk Matrix . dense type nvec = Nvector_serial . t let rewrap = Matrix . wrap_dense let check_matrix a b tol = let ca , cb = Matrix . ( unwrap a , unwrap b ) in let (...
module Test = Test_matrix . Test ( Dense_tests ) ( Nvector_serial . Ops )
let main ( ) = let fails = ref 0 in if Array . length Sys . argv < 4 then ( printf " ERROR : THREE ( 3 ) Input required : matrix rows , matrix cols , print timing @\ n " ; exit ( - 1 ) ) ; let matrows = int_of_string Sys . argv . ( 1 ) in if matrows <= 0 then ( printf " ERROR : number of rows must be a positive integer...
let reps = try int_of_string ( Unix . getenv " NUM_REPS " ) with Not_found | Failure _ -> 1
let gc_at_end = try int_of_string ( Unix . getenv " GC_AT_END " ) <> 0 with Not_found | Failure _ -> false
let gc_each_rep = try int_of_string ( Unix . getenv " GC_EACH_REP " ) <> 0 with Not_found | Failure _ -> false
let _ = for _ = 1 to reps do main ( ) ; if gc_each_rep then Gc . compact ( ) done ; if gc_at_end then Gc . compact ( )
let ( ) += r x = r := ! r + x
let rand_float ( ) = ( float_of_int ( Test_matrix . rand ( ) ) . / float_of_int ( Test_matrix . rand_max ) )
module Sparse_tests ( S : sig type sformat end ) = struct type k = Matrix . standard type m = S . sformat Matrix . Sparse . t type nd = Nvector_serial . data type nk = Nvector_serial . kind type t = ( S . sformat , nk ) Matrix . sparse type nvec = Nvector_serial . t let rewrap = Matrix . wrap_sparse let check_matrix a ...
let clone a = Matrix . ( wrap_sparse ( ( get_ops a ) . m_clone ( unwrap a ) ) )
let test_sunmatscaleadd2 check_vector a b x y z = let tol = match Sundials . Config . sundials_version with | 2 , _ , _ | 3 , 1 , 0 | 3 , 1 , 1 | 3 , 1 , 2 -> 1e - 14 | _ -> 100 . 0 . * Sundials . Config . unit_roundoff in try let c = clone a in let u = Nvector_serial . Ops . clone y in let v = Nvector_serial . Ops . c...
let test_sunmatscaleaddi2 check_vector a x y = let tol = match Sundials . Config . sundials_version with | 2 , _ , _ | 3 , 1 , 0 | 3 , 1 , 1 | 3 , 1 , 2 -> 1e - 14 | _ -> 100 . 0 . * Sundials . Config . unit_roundoff in try let b = clone a in let z = Nvector_serial . Ops . clone x in let w = Nvector_serial . Ops . clon...
let test_sunsparsematrix_convert ( type s ) ( check_matrix : ( s , ' a ) Matrix . sparse -> ( s , ' a ) Matrix . sparse -> float -> bool ) ( am : ( s , ' a ) Matrix . sparse ) = let tol = 200 . 0 . * Sundials . Config . unit_roundoff in let a = Matrix . unwrap am in match Matrix . Sparse . ( ( sformat a : s sformat ) )...
let int_of_mattype ( type s ) : s Matrix . Sparse . sformat -> int = function | Matrix . Sparse . CSC -> 0 | Matrix . Sparse . CSR -> 1
let rec main ( ) = if Array . length Sys . argv < 5 then ( printf " ERROR : FOUR ( 4 ) Input required : matrix rows , matrix cols , matrix type ( 0 / 1 ) , print timing @\ n " ; exit ( - 1 ) ) ; let matrows = int_of_string Sys . argv . ( 1 ) in if matrows <= 0 then ( printf " ERROR : number of rows must be a positive i...
let reps = try int_of_string ( Unix . getenv " NUM_REPS " ) with Not_found | Failure _ -> 1
let gc_at_end = try int_of_string ( Unix . getenv " GC_AT_END " ) <> 0 with Not_found | Failure _ -> false
let gc_each_rep = try int_of_string ( Unix . getenv " GC_EACH_REP " ) <> 0 with Not_found | Failure _ -> false
let _ = for _ = 1 to reps do main ( ) ; if gc_each_rep then Gc . compact ( ) done ; if gc_at_end then Gc . compact ( )
let sungte500 = let n , _ , _ = Sundials_configuration . sundials_version in n >= 5
let tol = if sungte500 then 100 . 0 . * sqrt ( Config . unit_roundoff ) else 1 . 0e - 4
let mxiter = if sungte500 then 20 else 10
let ytrue = if sungte500 then one else zero
let conv_test _ ( del : RealArray . t ) tol _ _ = if Nvector_serial . DataOps . maxnorm del <= tol then NLS . Success else NLS . Continue
let fp_function_lt500 y f _ = f . { 0 } <- ( one . / three ) . * cos ( y . { 1 } . * y . { 2 } ) . + ( one . / six ) ; f . { 1 } <- ( one . / nine ) . * sqrt ( y . { 0 } . * y . { 0 } . + sin ( y . { 2 } ) . + oneptzerosix ) . - ptone ; f . { 2 } <- . ( - one . / twenty ) . * exp ( . - y . { 0 } . * y . { 1 } ) . - ( t...
let fp_function ( y0 , ycur ) ycor gvec _ = Nvector_serial . DataOps . linearsum one y0 one ycor ycur ; let x = ycur . { 0 } in let y = ycur . { 1 } in let z = ycur . { 2 } in gvec . { 0 } <- ( one . / three ) . * cos ( ( y . - one ) . * z ) . + ( one . / six ) ; gvec . { 1 } <- ( one . / nine ) . * sqrt ( x . * x . + ...
let check_ans data tol = printf " Computed solution :\ n " ; printf " y1 = % g \ n " data . { 0 } ; printf " y2 = % g \ n " data . { 1 } ; printf " y3 = % g \ n " data . { 2 } ; let ex = abs_float ( data . { 0 } . - xtrue ) in let ey = abs_float ( data . { 1 } . - ytrue ) in let ez = abs_float ( data . { 2 } . - ztrue ...
let main ( ) = let argc = Array . length Sys . argv in let maa = if argc > 1 then int_of_string Sys . argv . ( 1 ) else 0 in let damping = if argc > 2 then float_of_string Sys . argv . ( 2 ) else 1 . 0 in if sungte500 then begin printf " Solve the nonlinear system :\ n " ; printf " 3x - cos ( ( y - 1 ) z ) - 1 / 2 = 0 ...
let reps = try int_of_string ( Unix . getenv " NUM_REPS " ) with Not_found | Failure _ -> 1
let gc_at_end = try int_of_string ( Unix . getenv " GC_AT_END " ) <> 0 with Not_found | Failure _ -> false
let gc_each_rep = try int_of_string ( Unix . getenv " GC_EACH_REP " ) <> 0 with Not_found | Failure _ -> false
let _ = for _ = 1 to reps do main ( ) ; if gc_each_rep then Gc . compact ( ) done ; if gc_at_end then Gc . compact ( )
let jac _ y j = j . { 0 , 0 } <- two . * y . { 0 } ; j . { 1 , 0 } <- two . * y . { 1 } ; j . { 2 , 0 } <- two . * y . { 2 } ; j . { 0 , 1 } <- four . * y . { 0 } ; j . { 1 , 1 } <- two . * y . { 1 } ; j . { 2 , 1 } <- . - four ; j . { 0 , 2 } <- six . * y . { 0 } ; j . { 1 , 2 } <- . - four ; j . { 2 , 2 } <- two . * ...
type ' k integrator_mem_rec = { y0 : Nvector_serial . t ; ycur : Nvector_serial . t ; ycor : Nvector_serial . t ; w : Nvector_serial . t ; x : Nvector_serial . t ; a : ' k Matrix . dense ; ls : ( Matrix . Dense . t , ' k , [ ` Dls ] ) LS . serial_t ; }
let lsetup imem _ _ = jac zero ( Nvector . unwrap imem . ycur ) ( Matrix . ( Dense . unwrap ( unwrap imem . a ) ) ) ; LS . setup imem . ls imem . a ; true
let lsolve imem b _ = LS . solve imem . ls imem . a imem . x ( Nvector_serial . wrap b ) zero ; NVOps . scale one ( Nvector_serial . unwrap imem . x ) b
let conv_test _ _ del tol ewt _ = let delnrm = NVOps . wrmsnorm del ewt in if delnrm <= tol then NLS . Success else NLS . Continue
let res imem y f _ = let y1 , y2 , y3 = if Sundials_impl . Version . lt500 then y . { 0 } , y . { 1 } , y . { 2 } else begin Nvector_serial . Ops . linearsum one imem . y0 one imem . ycor imem . ycur ; let ycur = Nvector . unwrap imem . ycur in ycur . { 0 } , ycur . { 1 } , ycur . { 2 } end in f . { 0 } <- y1 . * y1 . ...
let main ( ) = let x = Nvector_serial . make neq 0 . 0 in let y0 = Nvector_serial . wrap ( RealArray . of_array [ | half ; half ; half ] ) | in let ycur = Nvector . clone y0 in let ycor = Nvector_serial . make neq zero in let w = Nvector_serial . make neq one in let a = Matrix . dense neq in let ls = DLS . dense y0 a i...
let reps = try int_of_string ( Unix . getenv " NUM_REPS " ) with Not_found | Failure _ -> 1
let gc_at_end = try int_of_string ( Unix . getenv " GC_AT_END " ) <> 0 with Not_found | Failure _ -> false
let gc_each_rep = try int_of_string ( Unix . getenv " GC_EACH_REP " ) <> 0 with Not_found | Failure _ -> false
let _ = for _ = 1 to reps do main ( ) ; if gc_each_rep then Gc . compact ( ) done ; if gc_at_end then Gc . compact ( )
let wrong_k message = fun _ -> assert_failure message
let with_text_limit n f = let limit = ! Text . length_limit in Text . length_limit := n ; try f ( ) ; Text . length_limit := limit with exn -> Text . length_limit := limit ; raise exn
let expect_error : ? allow_recovery : int -> location -> Error . t -> ( Error . parse_handler -> unit ) -> unit = fun ( ? allow_recovery = 0 ) l error f -> let errors = ref 0 in let report l ' error ' _ k = errors := ! errors + 1 ; if ! errors > 1 + allow_recovery then sprintf " got additional error ' % s ' " ( Error ....
let expect_sequence ( ? prefix = false ) id to_string sequence = let assert_failure s = assert_failure ( id ^ " \ n " ^ s ) in let sequence = ref sequence in let invalid = ref false in let receive s throw = if ! invalid then ( ) else match ! sequence with | [ ] -> if not prefix then begin invalid := true ; sprintf " go...
let iter iterate s = Kstream . iter iterate s ( function | Exit -> ( ) | exn -> raise exn ) ignore
type ' a general_signal = S of ' a | E of Error . t
let expect_signals ? prefix signal_to_string id signals = let to_string = function | l , c , S s -> sprintf " line % i , column % i : % s " l c ( signal_to_string s ) | l , c , E e -> sprintf " line % i , column % i : % s " l c ( Error . to_string e ) in let receive , ended = expect_sequence ? prefix id to_string signa...
let expect_strings id strings = let to_string = function | S s -> s | E e -> Error . to_string e in let receive , ended = expect_sequence id to_string strings in let report _ e throw k = receive ( E e ) throw ; k ( ) in let string s throw k = receive ( S s ) throw ; k ( ) in report , string , ended
require [ % here ] ( equal ( intern " foo " ) ( intern " foo " ) ) ; return ( ) ; ; require [ % here ] ( not ( equal ( intern " foo " ) ( intern " bar " ) ) ) ; return ( ) ; ; require [ % here ] ( not ( equal ( create ~ name " : foo " ) ( create ~ name " : foo " ) ) ) ; return ( ) ; ; print_s [ % sexp ( name ( intern "...
let test_bracket_succeed ( ) = let state = ref ` uninitialised in let setup ( ) = state := ` test_start ; state in let teardown state = assert_equal ! state ` test_end ; state := ` torn_down in Sync . bracket setup ( fun state -> assert_equal ! state ` test_start ; state := ` test_end ) teardown ( ) ; assert_equal ! st...
let test_bracket_fail ( ) = let state = ref ` uninitialised in let setup ( ) = state := ` test_start ; state in let teardown state = state := ` torn_down in try Sync . bracket setup ( fun state -> assert_equal ! state ` test_start ; assert_equal 5 6 ) teardown ( ) ; with TestFailure " not equal " -> assert_equal ! stat...
let test_bracket_error ( ) = let state = ref ` uninitialised in let setup ( ) = state := ` test_start ; state in let teardown state = state := ` torn_down in try Sync . bracket setup ( fun state -> assert_equal ! state ` test_start ; raise TestException ) teardown ( ) ; with TestException -> assert_equal ! state ` torn...
let suite = " sync " >::: [ " test_bracket_succeed " >:: test_bracket_succeed ; " test_bracket_fail " >:: test_bracket_fail ; " test_bracket_error " >:: test_bracket_error ; ]
let prn = function | Synchronised { is_chain_stuck = true } -> " Synchronised ( stuck ) " | Not_synchronised -> " Not synchronised " | Synchronised { is_chain_stuck = false } -> " Synchronised ( not stuck ) "
let forge_peer_id ( ) = let identity = P2p_identity . generate_with_pow_target_0 ( ) in identity . peer_id