text stringlengths 0 601k |
|---|
let leave_trace = ref false |
let refresh_delay = ref ( 1 . 0 . / 60 . ) |
let start scale_val timestep trace ( piv_x , piv_y ) ( obs_x , obs_y ) = Graphics . open_graph " " ; Graphics . auto_synchronize false ; Graphics . clear_graph ( ) ; let width = Graphics . size_x ( ) and height = Graphics . size_y ( ) in scale := float_of_int height . / scale_val ; let piv_x = piv_x . * float_of_int wi... |
let rec minisleep ( sec : float ) = try ignore ( Unix . select [ ] [ ] [ ] sec ) with Unix . Unix_error ( Unix . EINTR , _ , _ ) -> minisleep sec |
let last_x = ref 0 . 0 |
let last_y = ref 0 . 0 |
let show ( x , y ) = Graphics . set_color Graphics . background ; Graphics . moveto ( fst ! pivot ) ( snd ! pivot ) ; Graphics . lineto ( xc ! last_x ) ( yc ! last_y ) ; if ( not ! leave_trace ) then begin Graphics . fill_circle ( xc ! last_x ) ( yc ! last_y ) ball_radius ; show_objects ( ) end ; Graphics . set_color G... |
let stop ( ) = Graphics . set_color Graphics . white ; Graphics . moveto 2 2 ; Graphics . draw_string " Simulation finished . Press a key to exit . " ; Graphics . synchronize ( ) ; let _ = Graphics . wait_next_event [ Graphics . Key_pressed ] in Graphics . close_graph ( ) |
let show_current_event ppf = if ! Parameters . time then begin fprintf ppf " Time : % Li " ( current_time ( ) ) ; ( match current_pc ( ) with | Some pc -> fprintf ppf " - pc : % i :% i " pc . frag pc . pos | _ -> ( ) ) ; end ; update_current_event ( ) ; reset_frame ( ) ; match current_report ( ) with | None -> if ! Par... |
let show_one_frame framenum ppf ev = let pos = Events . get_pos ev . ev_ev in let cnum = try let buffer = get_buffer pos ev . ev_ev . ev_module in snd ( start_and_cnum buffer pos ) with _ -> pos . Lexing . pos_cnum in if ! machine_readable then fprintf ppf " #% i Pc : % i :% i % s char % i . " @ framenum ev . ev_frag e... |
let show_current_frame ppf selected = match ! selected_event with | None -> fprintf ppf " . @ No frame selected . . " @ | Some sel_ev -> show_one_frame ! current_frame ppf sel_ev ; begin match breakpoints_at_pc { frag = sel_ev . ev_frag ; pos = sel_ev . ev_ev . ev_pos } with | [ ] -> ( ) | [ breakpoint ] -> fprintf ppf... |
let print_line buffer line_number start point before = let linefeed = next_linefeed buffer start and content = buffer_content buffer in printf " % i " line_number ; let line_end = if linefeed > 0 && content . [ linefeed - 1 ] = ' \ r ' then linefeed - 1 else linefeed in if point <= line_end && point >= start then ( pri... |
let show_no_point ( ) = if ! emacs then printf " \ 026 \ 026H \ n " |
let show_point ev selected = let mdle = ev . ev_module in let before = ( ev . ev_kind = Event_before ) in if ! emacs && selected then begin try let buffer = get_buffer ( Events . get_pos ev ) mdle in let source = source_of_module ev . ev_loc . Location . loc_start mdle in printf " \ 026 \ 026M % s :% i :% i " source ( ... |
let show_listing pos mdle start stop point before = try let buffer = get_buffer pos mdle in let rec aff ( line_start , line_number ) = if line_number <= stop then aff ( print_line buffer line_number line_start point before + 1 , line_number + 1 ) in aff ( pos_of_line buffer start ) with Out_of_range -> prerr_endline " ... |
method ! wrap_tr_function_str ~ loc tdecl gcata_on_new_expr = super # wrap_tr_function_str ~ loc tdecl gcata_on_new_expr method ! prepare_fa_args ~ loc tdecl = List . concat @@ map_type_param_names tdecl . ptype_params ~ f ( : fun s -> [ Pat . sprintf ~ loc " typ_ % s " s ; Pat . sprintf ~ loc " f % s " s ] ) method ap... |
let g = ( new g :> ( Plugin_intf . plugin_args -> ( loc , Exp . t , Typ . t , type_arg , Ctf . t , Cf . t , Str . t , Sig . t ) Plugin_intf . typ_g ) ) end |
let register ( ) = Expander . register_plugin trait_name ( module Make : Plugin_intf . PluginRes ) |
let ( ) = register ( ) ) * |
let int = { GT . gcata = GT . gcata_int ; GT . plugins = object method show = GT . int . GT . plugins # show method html = GT . int . GT . plugins # html method gmap = GT . int . GT . plugins # gmap method compare = GT . int . GT . plugins # compare method eq = GT . int . GT . plugins # eq method foldl = GT . int . GT ... |
let string = { GT . gcata = GT . gcata_string ; GT . plugins = object method show = GT . string . GT . plugins # show method html = GT . string . GT . plugins # html method gmap = GT . string . GT . plugins # gmap method compare = GT . string . GT . plugins # compare method eq = GT . string . GT . plugins # eq method f... |
let tuple2 = { GT . gcata = GT . gcata_pair ; GT . plugins = object method show = GT . tuple2 . GT . plugins # show method html = GT . tuple2 . GT . plugins # html method gmap = GT . tuple2 . GT . plugins # gmap method compare = GT . tuple2 . GT . plugins # compare method eq = GT . tuple2 . GT . plugins # eq method fol... |
let tuple3 = { GT . gcata = GT . gcata_pair ; GT . plugins = object method show = GT . tuple2 . GT . plugins # show method html = GT . tuple2 . GT . plugins # html method gmap = GT . tuple2 . GT . plugins # gmap method compare = GT . tuple2 . GT . plugins # compare method eq = GT . tuple2 . GT . plugins # eq method fol... |
let show_typed t = t . plugins # show_typed |
module T : sig type ' a t val atomic : _ t val create : ( ' a -> ' a Sequence . t ) -> ' a t val shrink : ' a t -> ' a -> ' a Sequence . t type ' a t = ' a -> ' a Sequence . t let atomic _ = Sequence . empty let create = Fn . id let shrink = Fn . id end |
let map t ~ f ~ f_inverse = create ( fun x -> Sequence . map ~ f ( shrink t ( f_inverse x ) ) ) |
let filter t ~ f = create ( fun x -> Sequence . filter ~ f ( shrink t x ) ) |
let filter_map t ~ f ~ f_inverse = create ( fun x -> Sequence . filter_map ~ f ( shrink t ( f_inverse x ) ) ) ; ; |
let of_lazy lazy_t = create ( fun x -> Sequence . of_lazy ( lazy ( shrink ( force lazy_t ) x ) ) ) |
let fixed_point of_shrinker = let rec lazy_t = lazy ( of_shrinker ( of_lazy lazy_t ) ) in of_lazy lazy_t ; ; |
let both fst_t snd_t = create ( fun ( fst , snd ) -> Sequence . round_robin [ Sequence . map ( shrink fst_t fst ) ~ f ( : fun fst -> fst , snd ) ; Sequence . map ( shrink snd_t snd ) ~ f ( : fun snd -> fst , snd ) ] ) ; ; |
let bigarray1 src = let dim = Bigarray . Array1 . dim src in match dim with | 0 -> Sequence . empty | _ -> let kind = Bigarray . Array1 . kind src in let layout = Bigarray . Array1 . layout src in let offset = Bigarray_helpers . Layout . offset layout in Sequence . init dim ~ f ( : fun to_skip -> let to_skip = to_skip ... |
let bigstring = create bigarray1 |
let float32_vec = create bigarray1 |
let float64_vec = create bigarray1 |
let bigarray2 = let module Dims = struct type t = { dim1 : int ; dim2 : int } [ @@ deriving fields ] let create a = Bigarray . Array2 . { dim1 = dim1 a ; dim2 = dim2 a } end in let shrink field src = let dims = Dims . create src in match Field . get field dims with | 0 -> Sequence . empty | _ -> let kind = Bigarray . A... |
let float32_mat = create bigarray2 |
let float64_mat = create bigarray2 |
let option value_t = create ( function | None -> Sequence . empty | Some value -> Sequence . append ( Sequence . singleton None ) ( Sequence . map ~ f : Option . return ( shrink value_t value ) ) ) ; ; |
let list elt_t = fixed_point ( fun list_t -> create ( function | [ ] -> Sequence . empty | head :: tail -> Sequence . round_robin [ Sequence . singleton tail ; Sequence . map ( shrink elt_t head ) ~ f ( : fun head -> head :: tail ) ; Sequence . map ( shrink list_t tail ) ~ f ( : fun tail -> head :: tail ) ] ) ) ; ; |
let string = map ( list char ) ~ f : String . of_char_list ~ f_inverse : String . to_list |
let sexp = fixed_point ( fun shrinker -> create ( function | Sexp . Atom _ -> Sequence . empty | Sexp . List l -> let shrink_list = shrink ( list shrinker ) l |> Sequence . map ~ f ( : fun l -> Sexp . List l ) in let shrink_tree = Sequence . of_list l in Sequence . round_robin [ shrink_list ; shrink_tree ] ) ) ; ; |
let either fst_t snd_t = create ( fun either -> match ( either : _ Either . t ) with | First fst -> Sequence . map ( shrink fst_t fst ) ~ f : Either . first | Second snd -> Sequence . map ( shrink snd_t snd ) ~ f : Either . second ) ; ; |
let result ok_t err_t = map ( either ok_t err_t ) ~ f ( : function | First ok -> Ok ok | Second err -> Error err ) ~ f_inverse ( : function | Ok ok -> First ok | Error err -> Second err ) ; ; |
let map_tree_using_comparator ~ comparator key_t data_t = create ( fun tree -> let alist = Map . Using_comparator . Tree . to_alist tree in let drop_keys = Sequence . map ( Sequence . of_list alist ) ~ f ( : fun ( k , _ ) -> Map . Using_comparator . Tree . remove ~ comparator tree k ) in let shrink_keys = Sequence . ro... |
let set_tree_using_comparator ~ comparator elt_t = create ( fun tree -> let list = Set . Using_comparator . Tree . to_list tree in let drop_elts = Sequence . map ( Sequence . of_list list ) ~ f ( : fun elt -> Set . Using_comparator . Tree . remove ~ comparator tree elt ) in let shrink_elts = Sequence . round_robin ( Li... |
let map_t key_t data_t = create ( fun map_t -> let comparator = Map . comparator map_t in let t = map ( map_tree_using_comparator ~ comparator key_t data_t ) ~ f ( : Map . Using_comparator . of_tree ~ comparator ) ~ f_inverse : Map . Using_comparator . to_tree in shrink t map_t ) ; ; |
let set_t elt_t = create ( fun set_t -> let comparator = Set . comparator set_t in let t = map ( set_tree_using_comparator ~ comparator elt_t ) ~ f ( : Set . Using_comparator . of_tree ~ comparator ) ~ f_inverse : Set . Using_comparator . to_tree in shrink t set_t ) ; ; |
module Sorted_list = struct type t = int list [ @@ deriving sexp ] let of_list list = List . stable_sort ~ compare : Int . compare list let to_list t = t let quickcheck_generator elt = let open Generator . Monad_infix in List . quickcheck_generator elt >>| of_list ; ; let custom_int_shrinker = Shrinker . create ( fun n... |
let time f ( ) = let start_time = Sys . time ( ) in let res = f ( ) in let end_time = Sys . time ( ) in ( end_time . - start_time , res ) res |
let sum_timing_pairs times = let sum_timings = List . fold_left ( ) . + 0 . 0 in let t1 , t2 = List . split times in sum_timings t1 , sum_timings t2 |
let get_name ( Test . Test cell ) cell = Test . get_name cell |
let run_timed_test seed cell = let open TestResult in let rand = Random . State . make [ | seed ] | in let shr_attempts = ref 0 in let handler _ _ e = match e with | Test . Shrinking ( _ , _ , _ ) _ -> incr shr_attempts | _ -> ( ) in let dur , res = time ( fun ( ) -> QCheck . Test . check_cell ~ rand ~ handler cell ) c... |
let run_timed_test_pair seed ( Test . Test c1 , Test . Test c2 ) c2 = let ( dur1 , res_str1 , shr_c1 , shr_att1 ) shr_att1 = run_timed_test seed c1 in let ( dur2 , res_str2 , shr_c2 , shr_att2 ) shr_att2 = run_timed_test seed c2 in if res_str1 <> res_str2 then failwith ( Printf . sprintf " benchmark % s gave different ... |
let non_repeatable_tests = [ " big bound issue59 " ; " ints < 209609 ] " |
let run_timing ch seeds testpairs = let fprintf = Printf . fprintf in let multiple_runs = List . length seeds > 1 in Printf . fprintf ch " %- 48s " " " ; List . iter ( fun seed -> fprintf ch " iteration seed %- 7i " %! seed ) seed seeds ; if multiple_runs then fprintf ch " total \ n " %! else print_newline ( ) ; fprint... |
let rec merge_and_validate xs ys = match xs , ys with | [ ] [ ] , -> [ ] | [ ] , _ -> failwith " QCheck2_tests . Shrink has more tests than QCheck_tests . Shrink " | _ [ ] , -> failwith " QCheck_tests . Shrink has more tests than QCheck2_tests . Shrink " | t1 :: xs , t2 :: ys -> if get_name t1 = get_name t2 then ( t1 ,... |
let seeds = [ 1234 ; 8743 ; 6789 ; ] |
let ( ) = let ch = open_out " shrink_bench . log " in try merge_and_validate QCheck_tests ( . Shrink . tests @ Function . tests ) tests QCheck2_tests ( . Shrink . tests @ Function . tests ) tests |> run_timing ch seeds ; close_out ch with e -> close_out ch ; raise e |
let todo = ref [ ] |
let at_shutdown f = let backtrace = Backtrace . get ( ) in if debug then Debug . log " at_shutdown " backtrace [ % sexp_of : Backtrace . t ] ; todo := ( backtrace , f ) :: ! todo ; ; |
let shutting_down_ref = ref ` No |
let default_force_ref = ref ( fun ( ) -> Clock . after ( sec 10 . ) ) |
let default_force ( ) = ! default_force_ref |
let set_default_force force = default_force_ref := force |
let shutting_down ( ) = ! shutting_down_ref |
let is_shutting_down ( ) = match shutting_down ( ) with | ` No -> false | ` Yes _ -> true ; ; |
let ignore_exn f = try f ( ) with | _ -> ( ) ; ; |
let exit_reliably status = match ( exit status : Nothing . t ) with | exception exn -> ignore_exn ( fun ( ) -> Core . Debug . eprints " Caml . exit raised " exn [ % sexp_of : Exn . t ] ) ; Core . Unix . exit_immediately ( if status = 0 then 1 else status ) | _ -> . ; ; |
let shutdown ? force status = if debug then ignore_exn ( fun ( ) -> Debug . log " shutdown " status [ % sexp_of : int ] ) ; match ! shutting_down_ref with | ` Yes status ' -> if status <> 0 && status ' <> 0 && status <> status ' then raise_s [ % message " shutdown with inconsistent status " ( status : int ) ( status ' ... |
let shutdown_on_unhandled_exn ( ) = Monitor . detach_and_iter_errors Monitor . main ~ f ( : fun exn -> ignore_exn ( fun ( ) -> Debug . log " shutting down due to unhandled exception " exn [ % sexp_of : exn ] ) ; try shutdown 1 with | _ -> ( ) ) ; ; |
let exit ? force status = shutdown ? force status ; Deferred . never ( ) ; ; |
let don ' t_finish_before = let proceed_with_shutdown = Ivar . create ( ) in let num_waiting = ref 0 in let check ( ) = if ! num_waiting = 0 then Ivar . fill proceed_with_shutdown ( ) in at_shutdown ( fun ( ) -> check ( ) ; Ivar . read proceed_with_shutdown ) ; fun d -> match shutting_down ( ) with | ` Yes _ -> ( ) | `... |
let whiteListSideEffects = [ " Pervasives . . " ; / " Pervasives . ref " ; " Int64 . mul " ; " Int64 . neg " ; " Int64 . sub " ; " Int64 . shift_left " ; " Int64 . one " ; " String . length " ; ] |
let whiteTableSideEffects = lazy ( let tbl = Hashtbl . create 11 in whiteListSideEffects |> List . iter ( fun s -> Hashtbl . add tbl s ( ) ) ; tbl ) |
let pathIsWhitelistedForSideEffects path = path |> Common . Path . onOkPath ~ whenContainsApply : false ~ f ( : fun s -> Hashtbl . mem ( Lazy . force whiteTableSideEffects ) s ) |
let rec exprNoSideEffects ( expr : CL . Typedtree . expression ) = match expr . exp_desc with | Texp_ident _ | Texp_constant _ -> true | Texp_construct ( _ , _ , el ) -> el |> List . for_all exprNoSideEffects | Texp_function _ -> true | Texp_apply ( { exp_desc = Texp_ident ( path , _ , _ ) } , args ) when path |> pathI... |
let checkExpr e = not ( exprNoSideEffects e ) |
Util . compile_and_run { | let i = ref 0 let log_success ( ) = print_endline " Success " ! let log_failure = Printf . printf " Failure ! % s " let side_effect yes label = if yes then ( Printf . printf " Side effect : % s \ n " %! label ; incr i ) ; 0 let _ = side_effect false " this is only to avoid inlining " let f = ... |
module Domain = struct type static_information = { global_static_information : Analyzer_headers . global_static_information ; domain_static_information : unit } type local_dynamic_information = Ckappa_sig . side_effects Ckappa_sig . Rule_nearly_Inf_Int_storage_Imperatif . t type dynamic_information = { local : local_dy... |
let bits ~ len n = List . init len ~ f ( : fun i -> ( n lsr i ) i land 1 = 1 ) 1 |
module Width : sig [ %% versioned : module Stable : sig module V1 : sig type t [ @@ deriving sexp , equal , compare , hash , yojson ] yojson end end ] end val of_int_exn : int -> t val to_int : t -> int val to_bits : t -> bool list val zero : t module Max = Nat . N2 module Max_vector : Vector . With_version ( With_vers... |
module Max_branches = struct include Nat . N8 module Log2 = Nat . N3 let % test " check max_branches " = Nat . to_int n = 1 lsl Nat . to_int Log2 . n end |
module Max_branches_vec = struct [ %% versioned module Stable = struct module V1 = struct type ' a t = ' a At_most . At_most_8 . Stable . V1 . t [ @@ deriving sexp , equal , compare , hash , yojson ] yojson end end ] end let ( ) = let _f : type a . unit -> ( a t , ( a , Max_branches . n ) n At_most . t ) t Type_equal .... |
module Domains = struct [ %% versioned module Stable = struct module V1 = struct type ' a t = { h : ' a } [ @@ deriving sexp , equal , compare , hash , yojson , hlist , fields ] fields end end ] end let iter { h } ~ f = f h let map { h } ~ f = { h = f h } end |
module Repr = struct [ %% versioned module Stable = struct module V2 = struct type ' g t = { step_data : ( Domain . Stable . V1 . t Domains . Stable . V1 . t * Width . Stable . V1 . t ) t Max_branches_vec . Stable . V1 . t ; max_width : Width . Stable . V1 . t ; wrap_index : ' g Plonk_verification_key_evals . Stable . ... |
module Poly = struct [ %% versioned module Stable = struct module V2 = struct type ( ' g , ' vk ) ' vk t = { step_data : ( Domain . Stable . V1 . t Domains . Stable . V1 . t * Width . Stable . V1 . t ) t Max_branches_vec . Stable . V1 . t ; max_width : Width . Stable . V1 . t ; wrap_index : ' g Plonk_verification_key_e... |
let dummy_domains = { Domains . h = Domain . Pow_2_roots_of_unity 0 } |
let index_to_field_elements ( k : ' a Plonk_verification_key_evals . t ) t ~ g = let [ v1 ; v2 ; g1 ; g2 ; g3 ; g4 ; g5 ; g6 ] = Plonk_verification_key_evals . to_hlist k in List . map ( Vector . to_list v1 @ Vector . to_list v2 @ [ g1 ; g2 ; g3 ; g4 ; g5 ; g6 ] ) ~ f : g |> Array . concat |
let wrap_index_to_input ( type gs f ) f ( g : gs -> f array ) array t = Random_oracle_input . Chunked . field_elements ( index_to_field_elements t ~ g ) g |
let width_size = Nat . to_int Width . Length . n |
let to_input ( type a ) a ( ~ field_of_int : int -> a ) a : ( a * a , _ ) _ Poly . t -> a Random_oracle_input . Chunked . t = let open Random_oracle_input . Chunked in let map_reduce t ~ f = Array . map t ~ f |> Array . reduce_exn ~ f : append in fun { step_data ; max_width ; wrap_index } : _ Random_oracle_input . Chun... |
let rec interval min max = if min > max then [ ] else min :: interval ( min + 1 ) max |
let rec filter p = function [ ] -> [ ] | a :: r -> if p a then a :: filter p r else filter p r |
let remove_multiples_of n = filter ( fun m -> m mod n <> 0 ) |
let sieve max = let rec filter_again = function [ ] -> [ ] | n :: r as l -> if n * n > max then l else n :: filter_again ( remove_multiples_of n r ) in filter_again ( interval 2 max ) |
let rec do_list f = function [ ] -> ( ) | a :: l -> f a ; do_list f l |
let _ = do_list ( fun n -> print_int n ; print_string " " ) ( sieve 50000 ) ; print_newline ( ) ; exit 0 |
type k = KModule | KModtype | KType | KTypext | KValue | KClass | KClasstype | KConstructor | KField | KMethod |
let string_of_k = function | KModule -> " module " | KModtype -> " module type " | KType -> " type " | KTypext -> " typext " | KValue -> " val " | KField -> " field " | KConstructor -> " constr " | KClass -> " class " | KClasstype -> " class type " | KMethod -> " method " |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.