text
stringlengths
0
601k
let write_sample to_coords chan { value = v ; like_prior = { log_likelihood = ll ; log_prior = lp } } = Array . iter ( fun x -> Printf . fprintf chan " % g " x ) ( to_coords v ) ; Printf . fprintf chan " % g % g \ n " ll lp
let write to_coords chan mcmcs = Array . iter ( fun samp -> write_sample to_coords chan samp ) mcmcs
let read_one_line from_coords string = let ea = Earray . make 0 0 . 0 in let buf = Scanf . Scanning . from_string string in ( try while true do Scanf . bscanf buf " % g " ( fun x -> Earray . append ea x ) done with | End_of_file -> ( ) ) ; let pts = Earray . to_array ea in let n = Array . length pts in { value = from_c...
let read_sample from_coords chan = let line = input_line chan in read_one_line from_coords line
let read from_coords chan = let ea = Earray . of_array [ ] || in try while true do Earray . append ea ( read_sample from_coords chan ) done ; Earray . to_array ea with | End_of_file -> Earray . to_array ea
let write_nested to_coords chan ( log_ev , log_dev , all_pts , wts ) = Printf . fprintf chan " % g % g \ n " log_ev log_dev ; Array . iteri ( fun i sample -> let wt = wts . ( i ) in Array . iter ( fun x -> Printf . fprintf chan " % g " x ) ( to_coords sample . value ) ; Printf . fprintf chan " % g % g " sample . like_p...
let read_nested_log_ev_dev string = let buf = Scanf . Scanning . from_string string in Scanf . bscanf buf " % g % g " ( fun x y -> ( x , y ) )
let read_nested_sample from_coord string = let buf = Scanf . Scanning . from_string string in let ea = Earray . of_array [ ] || in ( try while true do Earray . append ea ( Scanf . bscanf buf " % g " ( fun x -> x ) ) done ; ( ) with | End_of_file -> ( ) ) ; let pt = Earray . to_array ea in let n = Array . length pt in (...
let read_nested from_coord chan = let ( log_ev , log_dev ) = read_nested_log_ev_dev ( input_line chan ) in let ea = Earray . of_array [ ] || in ( try while true do Earray . append ea ( read_nested_sample from_coord ( input_line chan ) ) done ; ( ) with | End_of_file -> ( ) ) ; let pts_and_wts = Earray . to_array ea in ...
let _ANAME = " Float attribute "
let _ANAMES = " Character attribute "
let array1_to_string ( a : ( char , int8_unsigned_elt , c_layout ) Array1 . t ) = let len = Array1 . dim a in let s = Bytes . create len in for i = 0 to len - 1 do Bytes . unsafe_set s i ( Array1 . unsafe_get a i ) done ; s
let attr_info loc_id name _ ( ) = let attr = H5a . open_name loc_id name in Printf . printf " \ n " ; Printf . printf " Name : " ; print_endline name ; let atype = H5a . get_type attr in let aspace = H5a . get_space attr in let sdim , _ = H5s . get_simple_extent_dims aspace in let rank = Array . length sdim in if rank ...
let ( ) = let matrix = Array2 . create float32 c_layout _ADIM1 _ADIM2 in let string_out = Array1 . create char c_layout 80 in let point_out = Array1 . of_array int32 c_layout [ | 1l ] | in let vector = Array1 . of_array int32 c_layout [ | 1l ; 2l ; 3l ; 4l ; 5l ; 6l ; 7l ] | in let point = Array1 . of_array int32 c_lay...
let mcmc_samples_close a b = let n = Array . length a in assert_equal ~ printer : string_of_int ~ msg " : lengths differ " n ( Array . length b ) ; for i = 0 to n - 1 do let { Mcmc . value = va ; like_prior = { Mcmc . log_likelihood = lla ; log_prior = lpa } } = a . ( i ) and { Mcmc . value = vb ; like_prior = { Mcmc ....
let test_read_write_inverses ( ) = let samples = Mcmc . mcmc_array 1000 ( fun x -> Stats . log_gaussian 0 . 0 1 . 0 x ) ( fun _ -> 0 . 0 ) ( fun x -> x . + Random . float 1 . 0 . - 0 . 5 ) ( fun x y -> 0 . 0 ) 0 . 0 in let ( fname , ofile ) = Filename . open_temp_file " mcmc_test " " . dat " in ( try Read_write . write...
let test_nested_read_write ( ) = let ( log_ev , log_dev , arr_samples , log_wts ) as result = Nested . nested_evidence ( fun x -> x ) ( fun x -> x ) ( fun ( ) -> [ | Random . float 1 . 0 ] ) | ( fun x -> Stats . log_gaussian 0 . 5 0 . 1 x . ( 0 ) ) ( fun x -> 0 . 0 ) in let samples = Array . map ( fun x -> { x with Mcm...
let tests = " read_write . ml tests " >::: [ " read and write are inverses " >:: test_read_write_inverses ; " read and write nested samples " >:: test_nested_read_write ]
let rec read_char term = LTerm . read_event term >>= function | LTerm_event . Key { LTerm_key . code = LTerm_key . Char ch ; LTerm_key . control = true ; _ } when ch = CamomileLibraryDefault . Camomile . UChar . of_char ' c ' -> Lwt . fail ( Failure " interrupted " ) | LTerm_event . Key { LTerm_key . code = LTerm_key ....
let rec read_yes_no term = LTerm . fprint term " Do you accept ( y / n ) ? " >>= fun ( ) -> read_char term >|= Zed_utf8 . singleton >>= fun ch -> LTerm . fprintl term ch >>= fun ( ) -> match ch with | " y " -> return true | " n " -> return false | _ -> LTerm . fprintl term " Please enter ' y ' or ' n ' " ! >>= fun ( ) ...
let main ( ) = Lazy . force LTerm . stdout >>= fun term -> LTerm . enter_raw_mode term >>= fun mode -> Lwt . finalize ( fun ( ) -> read_yes_no term >>= function | true -> LTerm . fprintl term " You accepted . " | false -> LTerm . fprintl term " You did not accept . " ) ( fun ( ) -> LTerm . leave_raw_mode term mode )
let ( ) = Lwt_main . run ( main ( ) )
module type Scheduler = sig type ' a cont val suspend : ( ' a cont -> ' a option ) -> ' a val resume : ' a cont -> ' a -> unit val get_tid : unit -> int end
module type S = sig type ( ' a , ' b ) t val never : ( ' a , ' b ) t val constant : ' a -> ( ' b , ' a ) t val post_commit : ( ' a -> unit ) -> ( ' a , ' a ) t val lift : ( ' a -> ' b ) -> ( ' a , ' b ) t val lift_blocking : ( ' a -> ' b option ) -> ( ' a , ' b ) t val return : ( ' a -> ( unit , ' b ) t ) -> ( ' a , ' ...
module Make ( Sched : Scheduler ) : S = struct module B = struct include Core . Make ( Sched ) module Ref = Ref . Make ( Sched ) module Channel = Channel . Make ( Sched ) end include B module Data = struct module Counter = Counter . Make ( B ) module Treiber_stack = Treiber_stack . Make ( B ) module Elimination_stack =...
let print_usage_and_exit ( ) = print_endline @@ " Usage : " ^ Sys . argv . ( 0 ) ^ " < num_domains > < num_items " ; > exit ( 0 )
let ( num_doms , num_items ) = if Array . length Sys . argv < 3 then print_usage_and_exit ( ) else try let a = int_of_string ( Sys . argv . ( 1 ) ) in let b = int_of_string ( Sys . argv . ( 2 ) ) in ( a , b ) with | Failure _ -> print_usage_and_exit ( )
let items_per_dom = num_items / num_doms
module M = struct let num_domains = num_doms let is_affine = false end
module S = Sched_ws . Make ( M )
let ( ) = Printf . printf " [ % d ] items_per_domain = % d \ n " %! ( S . get_qid ( ) ) items_per_dom
let id_str ( ) = Printf . sprintf " % d :% d " ( S . get_qid ( ) ) ( S . get_tid ( ) )
module type BARRIER = sig type t val create : int -> t val finish : t -> unit end
module Reagents = Reagents . Make ( S )
module type QUEUE = sig type ' a t val create : unit -> ' a t val push : ' a t -> ' a -> unit val pop : ' a t -> ' a option end
module type RQUEUE = sig type ' a t val create : unit -> ' a t val push : ' a t -> ( ' a , unit ) Reagents . t val try_pop : ' a t -> ( unit , ' a option ) Reagents . t end
module MakeQ ( RQ : RQUEUE ) : QUEUE = struct type ' a t = ' a RQ . t let create = RQ . create let push q v = Reagents . run ( RQ . push q ) v let pop q = Reagents . run ( RQ . try_pop q ) ( ) end
module Benchmark = struct let get_mean_sd l = let get_mean l = ( List . fold_right ( fun a v -> a . + v ) l 0 . ) . / ( float_of_int @@ List . length l ) in let mean = get_mean l in let sd = get_mean @@ List . map ( fun v -> abs_float ( v . - mean ) ** 2 . ) l in ( mean , sd ) let benchmark f n = let rec run acc = func...
module Test ( Q : QUEUE ) = struct let run num_doms items_per_domain = let q : int Q . t = Q . create ( ) in let b = CDL . create num_doms in let rec produce = function | 0 -> ( ) | i -> Q . push q i ; produce ( i - 1 ) in let rec consume i = match Q . pop q with | None -> ( ) | Some _ -> consume ( i + 1 ) in for i = 1...
let main ( ) = let module M = Test ( MakeQ ( Data . MichaelScott_queue ) ) in let ( m , sd ) = Benchmark . benchmark ( fun ( ) -> M . run num_doms items_per_dom ) 5 in printf " Reagent Lockfree . MSQueue : mean = % f , sd = % f tp =% f \ n " %! m sd ( float_of_int num_items . / m )
let ( ) = S . run main
let ( ) = Unix . sleep 1
let loadCmtFile cmtFilePath = let cmt_infos = CL . Cmt_format . read_cmt cmtFilePath in let excludePath sourceFile = ! Cli . excludePaths |> List . exists ( fun prefix_ -> let prefix = match Filename . is_relative sourceFile with | true -> prefix_ | false -> Filename . concat ( Sys . getcwd ( ) ) prefix_ in String . le...
let processCmtFiles ~ cmtRoot = let ( +++ ) = Filename . concat in match cmtRoot with | Some root -> Cli . cmtCommand := true ; let rec walkSubDirs dir = let absDir = match dir = " " with true -> root | false -> root +++ dir in let skipDir = let base = Filename . basename dir in base = " node_modules " || base = " _esy...
let runAnalysis ~ cmtRoot ~ ppf = Log_ . Color . setup ( ) ; if ! Common . Cli . json then EmitJson . start ( ) ; processCmtFiles ~ cmtRoot ; if runConfig . dce then ( DeadException . forceDelayedItems ( ) ; DeadOptionalArgs . forceDelayedItems ( ) ; DeadCommon . reportDead ~ checkOptionalArg : DeadOptionalArgs . check...
let cli ( ) = let analysisKindSet = ref false in let cmtRootRef = ref None in let usage = " reanalyze version " ^ Version . version in let versionAndExit ( ) = print_endline usage ; exit 0 [ @@ raises exit ] in let rec setAll cmtRoot = RunConfig . all ( ) ; cmtRootRef := cmtRoot ; analysisKindSet := true and setConfig ...
module Reason = Generator . Make ( struct module Obj = struct let close_tag_closed = " } " let close_tag_extendable = " } " let field_separator = " , " let open_tag_closed = " { . " let open_tag_extendable = " { . . " end module Type = struct let annotation_separator = " : " let handle_constructor_params name args = na...
let lint = ref false
let fname = ref None
let usage = Printf . sprintf " % s [ - lint ] file " ( Filename . basename Sys . executable_name )
let anon s = match ! fname with | None -> fname := Some s | Some _ -> raise ( Arg . Bad " file must only be given once " )
let is_ascii s = try for i = 0 to String . length s - 1 do if Char . code ( s . [ i ] ) > 127 then raise Exit done ; true with Exit -> false
let ( ) = Arg . parse [ " - lint " , Arg . Set lint , " lint instead of preprocessing " ] anon usage ; let fname = match ! fname with | None -> raise ( Arg . Bad " file must be provided " ) | Some f -> f in if Filename . check_suffix fname " . re " || Filename . check_suffix fname " . rei " then ( if ! lint && ( Filena...
type attributesPartition = { arityAttrs : attributes ; docAttrs : attributes ; stdAttrs : attributes ; jsxAttrs : attributes ; stylisticAttrs : attributes ; uncurried : bool }
let rec partitionAttributes ( ? partDoc = false ) ( ? allowUncurry = true ) attrs : attributesPartition = match attrs with | [ ] -> { arityAttrs [ ] ; = docAttrs [ ] ; = stdAttrs [ ] ; = jsxAttrs [ ] ; = stylisticAttrs [ ] ; = uncurried = false } | ( ( { txt = " bs " } , PStr [ ] ) as attr ) :: atTl -> let partition = ...
let extractStdAttrs attrs = ( partitionAttributes attrs ) . stdAttrs
let extract_raw_literal attrs = let rec loop acc = function | ( { txt " = reason . raw_literal " } , PStr [ { pstr_desc = Pstr_eval ( { pexp_desc = Pexp_constant ( Pconst_string ( text , None ) ) } , _ ) } ] ) :: rest -> ( Some text , List . rev_append acc rest ) | [ ] -> ( None , List . rev acc ) | attr :: rest -> loo...
let without_stylistic_attrs attrs = let rec loop acc = function | attr :: rest when ( partitionAttributes [ attr ] ) . stylisticAttrs != [ ] -> loop acc rest | [ ] -> List . rev acc | attr :: rest -> loop ( attr :: acc ) rest in loop [ ] attrs
let is_preserve_braces_attr ( { txt } , _ ) = txt = " reason . preserve_braces "
let has_preserve_braces_attrs stylisticAttrs = ( List . filter is_preserve_braces_attr stylisticAttrs ) != [ ]
let maybe_remove_stylistic_attrs attrs should_preserve = if should_preserve then attrs else List . filter ( function | ( { txt " = reason . raw_literal " } , _ ) -> true | _ -> false ) attrs
type category = | EndOfLine | SingleLine | Regular
let string_of_category = function | Regular -> " Regular " | EndOfLine -> " End of Line " | SingleLine -> " SingleLine "
type t = { location : Location . t ; category : category ; text : string ; }
let category t = t . category
let location t = t . location
let dump ppf t = Format . fprintf ppf " % d ( % d :% d ) -% d ( % d :% d ) -- % s :||% s " || t . location . loc_start . pos_cnum t . location . loc_start . pos_lnum ( t . location . loc_start . pos_cnum - t . location . loc_start . pos_bol ) t . location . loc_end . pos_cnum t . location . loc_end . pos_lnum ( t . loc...
let dump_list ppf list = List . iter ( Format . fprintf ppf " % a \ n " dump ) list
let wrap t = match t . text with | " " | " " * -> " " /***/ | txt when Reason_syntax_util . isLineComment txt -> " " // ^ ( String . sub txt 0 ( String . length txt - 1 ) ) ^ Reason_syntax_util . EOLMarker . string | txt when txt . [ 0 ] = ' ' * && txt . [ 1 ] <> ' ' * -> " " /** ^ txt ^ " " */ | txt -> " " /* ^ txt ^ ...
let is_doc t = String . length t . text > 0 && t . text . [ 0 ] == ' ' *
let make ~ location category text = { text ; category ; location }
let isLineComment { category ; text } = match category with | SingleLine -> Reason_syntax_util . isLineComment text | EndOfLine | Regular -> false
type lexing_error = | Illegal_character of char | Illegal_escape of string | Unterminated_comment of Location . t | Unterminated_string | Unterminated_string_in_comment of Location . t * Location . t | Keyword_as_label of string | Literal_overflow of string | Invalid_literal of string
type ast_error = | Not_expecting of Location . t * string | Other_syntax_error of string | Variable_in_scope of Location . t * string | Applicative_path of Location . t
type reason_error = | Lexing_error of lexing_error | Parsing_error of parsing_error | Ast_error of ast_error
let catch_errors : ( reason_error * Location . t ) list ref option ref = ref None
let raise_error error loc = match ! catch_errors with | None -> raise ( Reason_error ( error , loc ) ) | Some caught -> caught := ( error , loc ) :: ! caught
let raise_fatal_error error loc = raise ( Reason_error ( error , loc ) )
let recover_non_fatal_errors f = let catch_errors0 = ! catch_errors in let errors = ref [ ] in catch_errors := Some errors ; let result = match f ( ) with | x -> Result . Ok x | exception exn -> Result . Error exn in catch_errors := catch_errors0 ; ( result , List . rev ! errors )
let format_lexing_error ppf = function | Illegal_character c -> fprintf ppf " Illegal character ( % s ) " ( Char . escaped c ) | Illegal_escape s -> fprintf ppf " Illegal backslash escape in string or character ( % s ) " s | Unterminated_comment _ -> fprintf ppf " Comment not terminated " | Unterminated_string -> fprin...
let format_parsing_error ppf msg = fprintf ppf " % s " msg
let format_ast_error ppf = function | Not_expecting ( loc , nonterm ) -> fprintf ppf " Syntax error : % a % s not expected . " Ocaml_util . print_loc loc nonterm | Applicative_path loc -> fprintf ppf " Syntax error : % aapplicative paths of the form F ( X ) . t \ are not supported when the option - no - app - func is s...
let format_error ppf = function | Lexing_error err -> format_lexing_error ppf err | Parsing_error err -> format_parsing_error ppf err | Ast_error err -> format_ast_error ppf err
let report_error ppf ~ loc err = Format . fprintf ppf " [ @% a ] . " @@ ( Ocaml_util . print_error loc format_error ) err
let recover_parser_error f loc msg = if ! Reason_config . recoverable then f loc msg else raise_fatal_error ( Parsing_error msg ) loc
let ( ) = Printexc . register_printer ( function | Reason_error ( err , loc ) -> let _ = Format . flush_str_formatter ( ) in report_error Format . str_formatter ~ loc err ; Some ( Format . flush_str_formatter ( ) ) | _ -> None )
let str_eval_message text = { Parsetree . pstr_loc = Location . none ; pstr_desc = Pstr_eval ( { pexp_loc = Location . none ; pexp_desc = Pexp_constant ( Parsetree . Pconst_string ( text , Location . none , None ) ) ; pexp_attributes = [ ] ; pexp_loc_stack = [ ] ; } , [ ] ) ; }
let error_extension_node_from_recovery loc msg = recover_parser_error ( fun loc msg -> let str = { Location . loc ; txt = " merlin . syntax - error " } in let payload = [ str_eval_message msg ] in ( str , Parsetree . PStr payload ) ) loc msg
let error_extension_node loc msg = recover_parser_error ( fun loc msg -> let str = { Location . loc ; txt = " ocaml . error " } in let payload = [ str_eval_message msg ; str_eval_message msg ; ] in ( str , Parsetree . PStr payload ) ) loc msg
let is_punned_labelled_expression e lbl = let open Ast_404 . Parsetree in match e . pexp_desc with | Pexp_ident { txt } | Pexp_constraint ( { pexp_desc = Pexp_ident { txt } } , _ ) | Pexp_coerce ( { pexp_desc = Pexp_ident { txt } } , _ , _ ) -> txt = Longident . parse lbl | _ -> false
let funAppCallbackExceedsWidth ~ printWidth ~ args ~ funExpr ( ) = let open Ast_404 . Parsetree in let open Ast_404 . Asttypes in let funLen = begin match funExpr . pexp_desc with | Pexp_ident ident -> let identList = Longident . flatten ident . txt in let lengthOfDots = List . length identList - 1 in let len = List . ...
let singleTokenPatternOmmitTrail txt = String . length txt < 4 * setTimeout ( [ @ bs ] ( ) => Js . log ( " hola " ) , 1000 ) ; * -> setTimeout ( ( . ) => Js . log ( " hola " ) , 1000 ) ; ) *
let bsExprCanBeUncurried expr = match Ast_404 . Parsetree . ( expr . pexp_desc ) with | Pexp_fun _ | Pexp_apply _ -> true | _ -> false
let isUnderscoreIdent expr = match Ast_404 . Parsetree . ( expr . pexp_desc ) with | Pexp_ident ( { txt = Lident " _ " } ) -> true | _ -> false
let isPipeFirst e = match Ast_404 . Parsetree . ( e . pexp_desc ) with | Pexp_ident ( { txt = Longident . Lident ( " . " ) } ) | -> true | Pexp_apply ( { pexp_desc = Pexp_ident ( { txt = Longident . Lident ( " . " ) } ) } , | _ ) -> true | _ -> false
let isUnderscoreApplication expr = let open Ast_404 . Parsetree in match expr with | { pexp_attributes = [ ] ; pexp_desc = Pexp_fun ( Nolabel , None , { ppat_desc = Ppat_var ( { txt = " __x " } ) ; ppat_attributes = [ ] } , _ ) } -> true | _ -> false
let isPipeFirstWithNonSimpleJSXChild e = match Ast_404 . Parsetree . ( e . pexp_desc ) with | Pexp_apply ( { pexp_desc = Pexp_ident ( { txt = Longident . Lident ( " . " ) } ) } , | [ Nolabel , { pexp_desc = Pexp_apply ( _ ) } ; _ ] ) -> true | Pexp_apply ( { pexp_desc = Pexp_ident ( { txt = Longident . Lident ( " . " )...
let defaultImplementationParserFor use_stdin filename = let open Reason_toolchain in let ( theParser , parsedAsML ) = if Filename . check_suffix filename " . re " then ( RE . implementation_with_comments , false ) else if Filename . check_suffix filename " . ml " then ( ML . implementation_with_comments , true ) else e...
let parse ~ use_stdin filetype filename = let ( ( ast , comments ) , parsedAsML , parsedAsInterface ) = ( match filetype with | ` Auto -> defaultImplementationParserFor use_stdin filename | ` BinaryReason -> Printer_maker . reasonBinaryParser use_stdin filename | ` Binary -> Printer_maker . ocamlBinaryParser use_stdin ...
let print printtype filename parsedAsML output_chan output_formatter = match printtype with | ` BinaryReason -> fun ( ast , comments ) -> ( output_value output_chan ( Config . ast_impl_magic_number , filename , ast , comments , parsedAsML , false ) ; ) | ` Binary -> fun ( ast , _ ) -> let ast = Reason_syntax_util . ( a...