text
stringlengths
0
601k
let test_geq_zero = QCheck . Test . make ~ name " : t >= 0 " t_arb ( fun t -> zero <= t )
let tests_add = [ test_add_commutes ; test_add_zero ; test_add_neq ]
let tests_mul = [ test_mul_commutes ; test_mul_one ; test_mul_zero ]
let tests_sub = [ test_sub_zero ; test_sub_itself ; test_sub_neq ]
let tests_add_sub = [ test_add_sub ; test_sub_add ]
let tests_boundaries = [ test_leq_saturated ; test_geq_zero ]
let ( ) = Alcotest . run " Saturation " [ ( " add " , qcheck_wrap tests_add ) ; ( " mul " , qcheck_wrap tests_mul ) ; ( " sub " , qcheck_wrap tests_sub ) ; ( " add and sub " , qcheck_wrap tests_add_sub ) ; ( " <= and " , >= qcheck_wrap tests_boundaries ) ; ]
type _ t = int
let may_saturate : _ t -> may_saturate t = fun x -> x
let to_int x = x
let ( < ) : _ t -> _ t -> bool = Compare . Int . ( < )
let ( <= ) : _ t -> _ t -> bool = Compare . Int . ( <= )
let ( > ) : _ t -> _ t -> bool = Compare . Int . ( > )
let ( >= ) : _ t -> _ t -> bool = Compare . Int . ( >= )
let ( = ) : _ t -> _ t -> bool = Compare . Int . ( = )
let equal = ( = )
let ( <> ) : _ t -> _ t -> bool = Compare . Int . ( <> )
let max : _ t -> _ t -> _ t = fun x y -> if x >= y then x else y
let min : _ t -> _ t -> _ t = fun x y -> if x >= y then y else x
let compare : _ t -> _ t -> _ t = Compare . Int . compare
let of_int_opt t = if t >= 0 && t < saturated then Some t else None
let of_z_opt z = match Z . to_int z with int -> of_int_opt int | exception Z . Overflow -> None
let to_z x = Z . of_int x
let saturate_if_undef = function None -> saturated | Some x -> x
let safe_int x = of_int_opt x |> saturate_if_undef
let numbits x = let x = ref x and n = ref 0 in ( let y = ! x lsr 32 in if y <> 0 then ( n := ! n + 32 ; x := y ) ) ; ( let y = ! x lsr 16 in if y <> 0 then ( n := ! n + 16 ; x := y ) ) ; ( let y = ! x lsr 8 in if y <> 0 then ( n := ! n + 8 ; x := y ) ) ; ( let y = ! x lsr 4 in if y <> 0 then ( n := ! n + 4 ; x := y ) )...
let small_enough z = z land 0x7fffffff80000000 = 0
let mul_safe x = if small_enough x then Some x else None
let mul_safe_exn x = if small_enough x then x else failwith ( Format . sprintf " mul_safe_exn : % d must be below 2147483648 " x )
let mul_safe_of_int_exn x = Option . bind ( of_int_opt x ) mul_safe |> function | None -> failwith ( Format . sprintf " mul_safe_of_int_exn : % d must be below 2147483648 " x ) | Some x -> x
let shift_right x y = ( x :> int ) lsr y
let shift_left x y = if shift_right saturated y < x then saturated else ( x :> int ) lsl y
let mul x y = match x with | 0 -> 0 | x -> if small_enough x && small_enough y then x * y else if Compare . Int . ( y > saturated / x ) then saturated else x * y
let mul_fast x y = x * y
let scale_fast x y = if x = 0 then 0 else if small_enough y then x * y else if Compare . Int . ( y > saturated / x ) then saturated else x * y
let add x y = let z = x + y in if Compare . Int . ( z >= 0 ) then z else saturated
let succ x = add one x
let sub x y = Compare . Int . max ( x - y ) 0
let sub_opt x y = let s = x - y in if Compare . Int . ( s >= 0 ) then Some s else None
let erem x y = x mod y
let ediv x y = x / y
let t_to_z_exn z = match of_z_opt z with | None -> assert false | Some x -> x
let z_encoding = Data_encoding . ( check_size 9 ( conv to_z t_to_z_exn z ) )
let n_encoding = Data_encoding . ( check_size 9 ( conv to_z t_to_z_exn n ) )
let pp fmt x = Format . pp_print_int fmt x
module Queried = struct type t = { bucket : string ; path : string ; target : PyrePath . t ; changed_files : PyrePath . t list ; commit_id : string option ; } [ @@ deriving sexp , compare ] end
module Fetched = struct type t = { path : PyrePath . t ; changed_files : PyrePath . t list ; } [ @@ deriving sexp , compare ] end
module Setting = struct type t = { watchman_root : PyrePath . t ; watchman_filter : Watchman . Filter . t ; watchman_connection : Watchman . Raw . Connection . t ; project_name : string ; project_metadata : string option ; critical_files : CriticalFile . t list ; target : PyrePath . t ; } end
let query_exn { Setting . watchman_root ; watchman_filter ; watchman_connection ; project_name ; project_metadata ; critical_files ; target ; } = let process_watchman_response { Watchman . SinceQuery . Response . relative_paths ; saved_state } = match saved_state with | None -> raise ( SavedStateQueryFailure " Watchman...
let query setting = let on_exception exn = let message = Format . sprintf " Saved state query failed : % s " ( Exn . to_string exn ) in Lwt . return ( Result . Error message ) in Lwt . catch ( fun ( ) -> query_exn setting >>= fun queried -> Lwt . return ( Result . Ok queried ) ) on_exception
let fetch_exn { Queried . bucket ; path ; target ; changed_files ; commit_id } = let ( ) = match commit_id with | None -> Log . info " Downloading saved state . . . " | Some commit_id -> Log . info " Downloading saved state at commit % s . . . " commit_id in FetchSavedState . fetch ~ bucket ~ path ~ target ( ) >>= fun ...
let fetch queried = Lwt . catch ( fun ( ) -> fetch_exn queried >>= fun fetched -> Lwt . return ( Result . Ok fetched ) ) ( fun exn -> let message = Format . sprintf " Saved state fetching failed : % s " ( Exn . to_string exn ) in Lwt . return ( Result . Error message ) )
let query_and_fetch_exn setting = query_exn setting >>= fetch_exn
let query_and_fetch setting = Lwt . catch ( fun ( ) -> query_and_fetch_exn setting >>= fun fetched -> Lwt . return ( Result . Ok fetched ) ) ( fun exn -> let message = Format . sprintf " Saved state query & fetching failed : % s " ( Exn . to_string exn ) in Lwt . return ( Result . Error message ) )
type t = | LoadFromFile of { shared_memory_path : PyrePath . t ; changed_files_path : PyrePath . t option ; } | LoadFromProject of { project_name : string ; project_metadata : string option ; } | SaveToFile of { shared_memory_path : PyrePath . t }
let of_yojson json = let open Yojson . Safe . Util in let parsing_failed ( ) = let message = Format . sprintf " Malformed saved state action JSON : % s " ( Yojson . Safe . to_string json ) in Result . Error message in match json with | ` List [ ` String " load_from_file " ; load_from_file_options ] -> ( match ( member ...
let to_yojson = function | LoadFromFile { shared_memory_path ; changed_files_path } -> let load_from_file_options = let shared_memory_path_option = " shared_memory_path " , ` String ( PyrePath . absolute shared_memory_path ) in match changed_files_path with | None -> [ shared_memory_path_option ] | Some changed_files_p...
let test_configuration_parsing context = let assert_parsed ~ expected json_string = let json = Yojson . Safe . from_string json_string in match SavedStateAction . of_yojson json with | Result . Error message -> let message = Format . sprintf " Unexpected JSON parsing failure : % s " message in assert_failure message | ...
let test_query context = let watchman_root = PyrePath . create_absolute " / fake / root " in let target = PyrePath . create_absolute " / fake / target " in let critical_files = [ CriticalFile . BaseName " . pyre_configuration " ] in let watchman_filter = { Watchman . Filter . base_names = [ " . pyre_configuration " ] ;...
let ( ) = " savedstate_test " >::: [ " configuration_parsing " >:: test_configuration_parsing ; " query " >:: OUnitLwt . lwt_wrapper test_query ; ] |> Test . run
module GP = Fitc_gp . Make_deriv ( Cov_se_iso . Deriv )
let main ( ) = Random . self_init ( ) ; begin try Unix . mkdir " test / data " ~ perm : 0o755 with _ -> ( ) end ; write_mat " inputs " training_inputs ; write_vec " targets " training_targets ; let trained = let params = Cov_se_iso . Eval . Inputs . create_default_kernel_params ~ n_inducing training_inputs in let kerne...
let ( ) = main ( )
module Q = struct include Q let save_current_buffer = " save - current - buffer " |> Symbol . intern let save_excursion = " save - excursion " |> Symbol . intern let save_mark_and_excursion = " save - mark - and - excursion " |> Symbol . intern let save_match_data = " save - match - data " |> Symbol . intern let save_r...
let save_sync save_function args f = let r = ref None in let f = Defun . lambda_nullary_nil [ % here ] ( fun ( ) -> r := Some ( f ( ) ) ) in ignore ( Form . Blocking . eval ( Form . list ( List . concat [ [ save_function |> Form . symbol ] ; args |> List . map ~ f : Form . of_value_exn ; [ Form . list [ Q . funcall |> ...
let save_ ( type a b ) ( sync_or_async : ( a , b ) Sync_or_async . t ) save_function args ( f : unit -> b ) : b = match sync_or_async with | Sync -> save_sync save_function args f | Async -> Background . assert_foreground [ % here ] ~ message : [ % sexp ( sprintf " % s called asynchronously in background job " ( Symbol...
let save_current_buffer sync_or_async f = save_ sync_or_async Q . save_current_buffer [ ] f
let save_excursion sync_or_async f = save_ sync_or_async Q . save_excursion [ ] f
let save_mark_and_excursion sync_or_async f = save_ sync_or_async Q . save_mark_and_excursion [ ] f ; ;
let save_match_data sync_or_async f = save_ sync_or_async Q . save_match_data [ ] f
let save_restriction sync_or_async f = save_ sync_or_async Q . save_restriction [ ] f
let save_window_excursion sync_or_async f = save_ sync_or_async Q . save_window_excursion [ ] f ; ;
let save_selected_window sync_or_async f = save_ sync_or_async Q . save_selected_window [ ] f
let with_selected_frame sync_or_async frame f = save_ sync_or_async Q . with_selected_frame [ frame ] f ; ;
let with_selected_window sync_or_async window f = save_ sync_or_async Q . with_selected_window [ window ] f ; ;
let sbwin = ref None ; ;
let dbwin = ref None ; ;
let angle = ref 0 ; ;
let win = function None -> invalid_arg " window id " | Some id -> id ; ;
let myinit ( ) = glLight ( GL_LIGHT 0 ) ( Light . GL_AMBIENT ( 0 . 3 , 0 . 3 , 0 . 3 , 1 . 0 ) ) ; glLight ( GL_LIGHT 0 ) ( Light . GL_DIFFUSE ( 6 . 0 , 6 . 0 , 6 . 0 , 1 . 0 ) ) ; glLight ( GL_LIGHT 0 ) ( Light . GL_SPECULAR ( 1 . 0 , 1 . 0 , 1 . 0 , 1 . 0 ) ) ; glLight ( GL_LIGHT 0 ) ( Light . GL_POSITION ( - 1 . 0 ,...
let display ( ) = let red = ( 0 . 8 , 0 . 0 , 0 . 0 , 1 . 0 ) and yellow = ( 0 . 8 , 0 . 8 , 0 . 0 , 1 . 0 ) and green = ( 0 . 0 , 0 . 8 , 0 . 0 , 1 . 0 ) in glClear [ GL_COLOR_BUFFER_BIT ; GL_DEPTH_BUFFER_BIT ] ; glPushMatrix ( ) ; glRotate ( float ! angle ) 1 . 0 0 . 0 0 . 0 ; glScale 1 . 3 1 . 3 1 . 3 ; glRotate 20 ...
let reshapeOpenGLState ~ w ~ h = glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; if w <= h then glOrtho ( - 2 . 5 ) ( 2 . 5 ) ( ( - 2 . 5 ) . * ( float h ) . / ( float w ) ) ( 2 . 5 . * ( float h ) . / ( float w ) ) ( - 10 . 0 ) ( 10 . 0 ) else glOrtho ( ( - 2 . 5 ) . * ( float w ) . / ( float h ) ) ( 2 . 5 . * ( flo...
let sb_reshape ~ width : w ~ height : h = glutSetWindow ( win ! sbwin ) ; glViewport 0 0 w h ; reshapeOpenGLState w h ; glutSetWindow ( win ! dbwin ) ; glutReshapeWindow w h ; ; ;
let db_reshape ~ width : w ~ height : h = glViewport 0 0 w h ; reshapeOpenGLState w h ; ; ;
let rotation ( ) = angle := ! angle + 2 ; angle := ! angle mod 360 ; glutPostRedisplay ( ) ; ; ;
let animation = ref false ; ;
let main_menu ~ value = match value with | 1 -> animation := not ! animation ; if ! animation then begin glutIdleFunc ( rotation ) ; glutSetWindow ( win ! sbwin ) ; glutSetWindowTitle ( " sb2db - double buffer mode " ) ; glutSetWindow ( win ! dbwin ) ; glutShowWindow ( ) ; end else begin glutRemoveIdleFunc ( ) ; glutSe...
let sbvis = ref GLUT_NOT_VISIBLE ; ;
let dbvis = ref GLUT_NOT_VISIBLE ; ;
let visibility ~ state = if glutGetWindow ( ) = ( win ! sbwin ) then sbvis := state else dbvis := state ; let eithervis = ( ! sbvis = GLUT_VISIBLE ) || ( ! dbvis = GLUT_VISIBLE ) in if eithervis then if ! animation then glutIdleFunc rotation else glutRemoveIdleFunc ( ) ; ; ;
let ( ) = glutInitWindowSize 500 500 ; ignore ( glutInit Sys . argv ) ; glutInitDisplayMode [ GLUT_RGB ; GLUT_DEPTH ; GLUT_SINGLE ] ; sbwin := Some ( glutCreateWindow Sys . argv . ( 0 ) ) ; glutReshapeFunc ~ reshape : sb_reshape ; glutDisplayFunc ~ display ; glutVisibilityFunc ~ visibility ; myinit ( ) ; glutInitDispla...
let raise_bad msg = raise ( Bad msg ) msg
type sb_math_operator = | MPlus | MMinus | MTimes | MDivide | MPower | MRoot | MAbs | MExp | MLn | MLog | MFloor | MCeiling | MFactorial | MEq | MNeq | MGt | MLt | MGeq | MLeq | MAnd | MOr | MXor | MNot | MSin | MCos | MTan | MArcsin | MArccos | MArctan | MDelay | MFundef of string
type sb_math = | MApply of sb_math_operator * ( sb_math list ) list | MLambda of ( string list ) list * sb_math | MPiecewise of ( ( string * sb_math ) sb_math list ) list * string | MFloatNumber of float | MIntNumber of int | MIdentifier of string | MTime | MTrue | MFalse | MNAN | MPi | MExponent | MInfinity | MNoMath
type sb_unit = { unit_kind : string ; unit_exponent : int ; unit_scale : int ; unit_multiplier : float ; }
type sb_function_definition = { fundef_id : string ; fundef_name : string ; fundef_math : sb_math ; }
type sb_unit_definition = { unitdef_id : string ; unitdef_name : string ; unitdef_unitlist : sb_unit list ; }
type sb_compartment = { compart_id : string ; compart_name : string ; compart_spatialDimensions : int ; compart_size : float ; compart_units : string ; compart_outside : string ; compart_constant : bool ; }
type sb_species_ref = { specref_species : string ; specref_id : string ; specref_name : string ; specref_stoichiometry : int ; }
type sb_species = { species_id : string ; species_name : string ; species_type : string ; species_compartment : string ; species_initialAmount : float ; species_initialConcentration : float ; species_substanceUnits : string ; species_hasOnlySubstanceUnits : bool ; species_boundaryCondition : bool ; species_constant : b...