text
stringlengths
12
786k
let reshape win w h = Gl . viewport 0 0 w h
let pp_opengl_info ppf ( ) = let pp = Format . fprintf in let pp_opt ppf = function None -> pp ppf " error " | Some s -> pp ppf " % s " s in pp ppf " [ @< v , " ; >@ pp ppf " Renderer [ @< v [ >@% a ] , " @@ pp_opt ( Gl . get_string Gl . renderer ) ; pp ppf " ...
let create_window ~ gl ( : maj , min ) = let w_atts = Sdl . Window . ( opengl + resizable ) in let w_title = Printf . sprintf " OpenGL % d . % d ( core profile ) " maj min in let set a v = Sdl . gl_set_attribute a v in set Sdl . Gl . context_profile_mask Sdl . Gl . context_p...
let destroy_window win ctx = Sdl . gl_delete_context ctx ; Sdl . destroy_window win ; Ok ( )
let event_loop win draw = let e = Sdl . Event . create ( ) in let key_scancode e = Sdl . Scancode . enum Sdl . Event . ( get e keyboard_scancode ) in let event e = Sdl . Event . ( enum ( get e typ ) ) in let window_event e = Sdl . Event . ( window_event_enum ( get e window_e...
let tri ~ gl ( : maj , min as gl ) = Sdl . init Sdl . Init . video >>= fun ( ) -> create_window ~ gl >>= fun ( win , ctx ) -> create_geometry ( ) >>= fun bids -> create_program ( ) >>= fun pid -> event_loop win ( draw pid bids ) >>= fun ( ) -> delete_program pid >>= ...
let main ( ) = let exec = Filename . basename Sys . executable_name in let usage = str " Usage : % s [ OPTION ] \ n Tests Tgles2 . \ nOptions " : exec in let options = [ ] in let anon _ = raise ( Arg . Bad " no arguments are supported " ) in Arg . parse ( Arg . align opt...
let ( ) = main ( )
let ( >>= ) x f = match x with Ok v -> f v | Error _ as e -> e
let bigarray_create k len = Bigarray . ( Array1 . create k c_layout len )
let get_int = let a = bigarray_create Bigarray . int32 1 in fun f -> f a ; Int32 . to_int a . { 0 }
let set_int = let a = bigarray_create Bigarray . int32 1 in fun f i -> a . { 0 } <- Int32 . of_int i ; f a
let get_string len f = let a = bigarray_create Bigarray . char len in f a ; Gl . string_of_bigarray a
let vertex_shader = " # version 330 es in vec3 vertex ; in vec3 color ; out vec4 v_color ; void main ( ) { v_color = vec4 ( color , 1 . 0 ) ; gl_Position = vec4 ( vertex , 1 . 0 ) ; } "
let fragment_shader = " # version 330 es precision highp float ; in vec4 v_color ; out vec4 color ; void main ( ) { color = v_color ; } "
let set_3d ba i x y z = let start = i * 3 in ba . { start } <- x ; ba . { start + 1 } <- y ; ba . { start + 2 } <- z
let vertices = let vs = bigarray_create Bigarray . float32 ( 3 * 3 ) in set_3d vs 0 ( - 0 . 8 ) ( - 0 . 8 ) 0 . 0 ; set_3d vs 1 0 . 8 ( - 0 . 8 ) 0 . 0 ; set_3d vs 2 0 . 0 0 . 8 0 . 0 ; vs
let colors = let cs = bigarray_create Bigarray . float32 ( 3 * 3 ) in set_3d cs 0 1 . 0 0 . 0 0 . 0 ; set_3d cs 1 0 . 0 1 . 0 0 . 0 ; set_3d cs 2 0 . 0 0 . 0 1 . 0 ; cs
let indices = let is = bigarray_create Bigarray . int8_unsigned 3 in set_3d is 0 0 1 2 ; is
let create_buffer b = let id = get_int ( Gl . gen_buffers 1 ) in let bytes = Gl . bigarray_byte_size b in Gl . bind_buffer Gl . array_buffer id ; Gl . buffer_data Gl . array_buffer bytes ( Some b ) Gl . static_draw ; id
let delete_buffer bid = set_int ( Gl . delete_buffers 1 ) bid
let create_geometry ( ) = let gid = get_int ( Gl . gen_vertex_arrays 1 ) in let iid = create_buffer indices in let vid = create_buffer vertices in let cid = create_buffer colors in let bind_attrib id loc dim typ = Gl . bind_buffer Gl . array_buffer id ; Gl . enable_vertex_attrib_array loc ; G...
let delete_geometry gid bids = set_int ( Gl . delete_vertex_arrays 1 ) gid ; List . iter delete_buffer bids ; Ok ( )
let compile_shader src typ = let get_shader sid e = get_int ( Gl . get_shaderiv sid e ) in let sid = Gl . create_shader typ in Gl . shader_source sid src ; Gl . compile_shader sid ; if get_shader sid Gl . compile_status = Gl . true_ then Ok sid else let len = get_shader sid Gl . info_log_leng...
let create_program ( ) = compile_shader vertex_shader Gl . vertex_shader >>= fun vid -> compile_shader fragment_shader Gl . fragment_shader >>= fun fid -> let pid = Gl . create_program ( ) in let get_program pid e = get_int ( Gl . get_programiv pid e ) in Gl . attach_shader pid vid ; Gl ....
let delete_program pid = Gl . delete_program pid ; Ok ( )
let draw pid gid win = Gl . clear_color 0 . 0 . 0 . 1 . ; Gl . clear Gl . color_buffer_bit ; Gl . use_program pid ; Gl . bind_vertex_array gid ; Gl . draw_elements Gl . triangles 3 Gl . unsigned_byte ( ` Offset 0 ) ; Gl . bind_vertex_array 0 ; Sdl . gl_swap_window w...
let reshape win w h = Gl . viewport 0 0 w h
let pp_opengl_info ppf ( ) = let pp = Format . fprintf in let pp_opt ppf = function None -> pp ppf " error " | Some s -> pp ppf " % s " s in pp ppf " [ @< v , " ; >@ pp ppf " Renderer [ @< v [ >@% a ] , " @@ pp_opt ( Gl . get_string Gl . renderer ) ; pp ppf " ...
let create_window ~ gl ( : maj , min ) = let w_atts = Sdl . Window . ( opengl + resizable ) in let w_title = Printf . sprintf " OpenGL % d . % d ( core profile ) " maj min in let set a v = Sdl . gl_set_attribute a v in set Sdl . Gl . context_profile_mask Sdl . Gl . context_p...
let destroy_window win ctx = Sdl . gl_delete_context ctx ; Sdl . destroy_window win ; Ok ( )
let event_loop win draw = let e = Sdl . Event . create ( ) in let key_scancode e = Sdl . Scancode . enum Sdl . Event . ( get e keyboard_scancode ) in let event e = Sdl . Event . ( enum ( get e typ ) ) in let window_event e = Sdl . Event . ( window_event_enum ( get e window_e...
let tri ~ gl ( : maj , min as gl ) = Sdl . init Sdl . Init . video >>= fun ( ) -> create_window ~ gl >>= fun ( win , ctx ) -> create_geometry ( ) >>= fun ( gid , bids ) -> create_program ( ) >>= fun pid -> event_loop win ( draw pid gid ) >>= fun ( ) -> delete_pr...
let main ( ) = let exec = Filename . basename Sys . executable_name in let usage = str " Usage : % s [ OPTION ] \ n Tests Tgles3 . \ nOptions " : exec in let options = [ ] in let anon _ = raise ( Arg . Bad " no arguments are supported " ) in Arg . parse ( Arg . align opt...
let ( ) = main ( )
module Trimming_result = struct type t = { trimmed_bytes : int64 } let empty = { trimmed_bytes = 0L } let add t ( ~ bytes : int ) = { trimmed_bytes = Int64 . add t . trimmed_bytes ( Int64 . of_int bytes ) } end
let trim_broken_metadata_entries ~ trimmed_so_far = List . fold_left Version . Metadata . all ~ init : trimmed_so_far ~ f ( : fun trimmed_so_far version -> let metadata_entries = Layout . Versioned . list_metadata_entries version in let file_path = Layout . Versioned . file_path ( Version . ...
let garbage_collect ( ) = trim_broken_metadata_entries ~ trimmed_so_far : Trimming_result . empty
let files_in_cache_for_all_supported_versions ( ) = List . concat_map Version . File . all ~ f ( : fun file_version -> Layout . Versioned . list_file_entries file_version )
let file_exists_and_is_unused ~ stats = stats . Unix . st_nlink = 1
let trim ~ goal = let files = files_in_cache_for_all_supported_versions ( ) |> List . map ~ f : fst in let files = List . sort ~ compare ( : fun ( _ , _ , ctime1 ) ( _ , _ , ctime2 ) -> Poly . compare ctime1 ctime2 ) ( List . filter_map files ~ f ( : fun path -> matc...
let overhead_size ( ) = let files = files_in_cache_for_all_supported_versions ( ) |> List . map ~ f : fst in let stats = let f p = try let stats = Path . stat_exn p in if file_exists_and_is_unused ~ stats then Int64 . of_int stats . st_size else 0L with Unix . Unix_error ( Unix . ENOENT ...
let img = [ docker_image ~ account " : pveber " ~ name " : trinity " ~ tag " : 2 . 9 . 1 " ( ) ]
let fqs_option_template fastq_samples = let ( fqs , fq1s , fq2s ) , ( fq_gzs , fq1_gzs , fq2_gzs ) = Fastq_sample . explode fastq_samples in let arg_list plain_files compressed_files = let tokens = List . map plain_files ~ f : dep @ List . map compressed_files ~ f : Bistro_unix . Cmd ...
let ss_lib_type_option o = opt " -- SS_lib_type " string ( match o with | ` R -> " R " | ` F -> " F " | ` RF -> " RF " | ` FR -> " FR " )
let trinity ( ? mem = 128 ) ( ? threads = 4 ) ? no_normalize_reads ? run_as_paired ? min_kmer_cov ? ss_lib_type se_or_pe_fq = let tmp_dest = tmp // " trinity " in Workflow . shell ~ descr " : trinity " ~ img ~ np : threads ~ mem ( : Workflow . int ( mem * 1024 ) ) [ m...
let prepare_fastq n fq = Workflow . shell ~ descr " : trinity . prepare_fastq " [ pipe [ cmd " zcat " [ dep fq ] ; cmd " awk " ~ stdout : dest [ sprintf { ' { | if ( NR %% 4 == 1 && ( !$ 1 ~ . /*\/% d ) ) / { print $ 1 " /% d " } else { print } ...
let uniq_count_stats sam = let sorted_sam = sam |> Samtools . bam_of_sam |> Samtools . sort ~ on ` : name in Workflow . shell ~ descr " : trinity . uniq_count_stats . pl " ~ img [ cmd " $ TRINITY_HOME / util / SAM_nameSorted_to_uniq_count_stats . pl " ~ stdout : dest [ dep sorted...
let fq_option_template = function | SE_or_PE . Single_end fqs -> opt " -- single " dep fqs | Paired_end ( fqs1 , fqs2 ) -> seq ~ sep " : " [ opt " -- left " dep fqs1 ; opt " -- right " dep fqs2 ; ]
let bash_app f x = seq ~ sep " " : ( string " ( " $ :: string f :: string " " :: x @ [ string " ) " ] )
let insilico_read_normalization ( ? mem = 128 ) ? pairs_together ? parallel_stats ~ max_cov se_or_pe_fq = let trinity_cmd = cmd " $ TRINITY_HOME / util / insilico_read_normalization . pl " [ string " -- seqType fq " ; fq_option_template se_or_pe_fq ; opt " -- CPU " Fun . id np ; ...
let get_Trinity_gene_to_trans_map fa = Workflow . shell ~ descr " : get_Trinity_gene_to_trans_map " ~ img [ cmd " $ TRINITY_HOME / util / support_scripts / get_Trinity_gene_to_trans_map . pl " ~ stdout : dest [ dep fa ] ]
type cursor = O . t include ( struct type ' + a cell = { offset : int ; cursor : cursor ; value : ' a } let make_cell offset cursor value = assert ( offset >= 0 ) ; { offset ; cursor ; value } let shift_cell n c = if n = 0 then c else make_cell ( c . offset + n ) c . c...
module T = Mbt . Make ( struct type ' a measurable = ' a cell type measure = int let empty = 0 let cat a b c = a + b . offset + c end )
type ' a t = { root : O . t ; tree : ' a T . t ; }
let create ( ) = { root = O . root ( ) ; tree = T . leaf ; }
let validate t c msg = if not ( O . same_order t . root c ) then invalid_arg msg
let update t f = let tree , result = f t . tree in { t with tree } , result
let update ' t f = { t with tree = f t . tree }
let clear t = { t with tree = T . leaf }
let is_leaf = function | T . Leaf -> true | T . Node _ -> false
let is_empty t = is_leaf t . tree
let member t c = let rec aux = function | T . Leaf -> false | T . Node ( _ , l , cell , r , _ ) -> let o = compare c cell . cursor in if o = 0 then true else if o < 0 then aux l else aux r in aux t . tree
let find t c = let rec aux = function | T . Leaf -> raise Not_found | T . Node ( _ , l , cell , r , _ ) -> let o = compare c cell . cursor in if o = 0 then cell . value else if o < 0 then aux l else aux r in aux t . tree
let position t c0 = let rec traverse n = function | T . Leaf -> raise Not_found | T . Node ( _ , l , cell , r , _ ) -> let o = compare c0 cell . cursor in if o < 0 then traverse n l else let n = n + T . measure l + cell . offset in if o > 0 then traverse n r else n in traverse 0 t...
let rec shift_tree n = function | T . Leaf -> T . leaf | T . Node ( _ , T . Leaf , cell , r , _ ) -> T . node T . leaf ( shift_cell n cell ) r | T . Node ( _ , l , cell , r , _ ) -> T . node ( shift_tree n l ) cell r
let shift_tree n tree = if n = 0 then tree else shift_tree n tree
let rem_cursor t c0 = let rec traverse = function | T . Leaf -> raise Not_found | T . Node ( _ , l , cell , r , _ ) -> let o = compare c0 cell . cursor in if o < 0 then let l , shift = traverse l in T . node l ( shift_cell shift cell ) r , 0 else if o > 0 then let r , shift ...
let put_cursor t ~ at value = if at < 0 then invalid_arg " Trope . put_cursor : [ at ] must be >= 0 " ; let rec traverse before at = function | T . Leaf -> let cursor = O . after before in let cell = make_cell at cursor value in T . node T . leaf cell T . leaf , cursor | T . Node ...
let insert ? left_of t ~ at ~ len = if at < 0 then invalid_arg " Trope . insert : [ at ] must be >= 0 " ; if len < 0 then invalid_arg " Trope . insert : [ len ] must be >= 0 " ; let right = ( left_of : unit option ) = None in let rec aux n = function | T . Leaf -> T . ...
let remove ? left_of t ~ at ~ len = if at < 0 then invalid_arg " Trope . remove : [ at ] must be >= 0 " ; if len < 0 then invalid_arg " Trope . remove : [ len ] must be >= 0 " ; if len = 0 then t else let rec rem len = function | T . Leaf -> T . leaf | T . Node ( _ ,...
let cursor_at_origin t = O . after t . root
let remove_between t c1 c2 = validate t c1 " Trope . remove_between : cursor not in buffer " ; validate t c2 " Trope . remove_between : cursor not in buffer " ; if c1 == c2 then t else if compare c1 c2 > 0 then invalid_arg " Trope . remove_between : cursors must be in increaing order " else...
let remove_after t c len = validate t c " Trope . remove_after : cursor not in buffer " ; if len < 0 then invalid_arg " Trope . remove_after : len must be >= 0 " else if len = 0 then t else let rec rem n = function | T . Leaf -> T . leaf , n | T . Node ( _ , l , cell , r , ...
let remove_before t c len = validate t c " Trope . remove_before : cursor not in buffer " ; if len < 0 then invalid_arg " Trope . remove_before : len must be >= 0 " else if len = 0 then t else let rec rem n = function | T . Leaf -> T . leaf | T . Node ( _ , l , cell , r , _ ...
let insert_before t c len = validate t c " Trope . insert_before : cursor not in buffer " ; if len < 0 then invalid_arg " Trope . insert_before : len must be >= 0 " else if len = 0 then t else let rec aux = function | T . Leaf -> invalid_arg " Trope . insert_before : cursor not in buffe...
let insert_after t c len = validate t c " Trope . insert_after : cursor not in buffer " ; if len < 0 then invalid_arg " Trope . insert_after : len must be >= 0 " else if len = 0 then t else let rec aux = function | T . Leaf -> invalid_arg " Trope . insert_after : cursor not in buffer " ...
let _put_before t c0 value = validate t c0 " Trope . put_before : cursor not in buffer " ; let aux t = let c = O . before c0 in let rec aux = function | T . Leaf -> invalid_arg " Trope . put_before : cursor not in buffer " | T . Node ( _ , l , cell , r , _ ) -> let i = comp...
let _put_after t c0 value = validate t c0 " Trope . put_after : cursor not in buffer " ; let aux t = let c = O . after c0 in let rec aux = function | T . Leaf -> invalid_arg " Trope . put_after : cursor not in buffer " | T . Node ( _ , l , cell , r , _ ) -> let i = compare ...
let put_left t c v = validate t c " Trope . put_left : cursor from different buffer " ; let rec aux = function | T . Leaf -> T . node T . leaf ( make_cell 0 c v ) T . leaf | T . Node ( _ , l , cell , r , _ ) -> let i = compare c cell . cursor in if i = 0 then T . node ...
let put_right t c v = validate t c " Trope . put_right : cursor from different buffer " ; let rec aux pad = function | T . Leaf -> T . node T . leaf ( make_cell pad c v ) T . leaf , 0 | T . Node ( _ , l , cell , r , _ ) -> let i = compare c cell . cursor in if i = 0 th...
let find_before t n = let rec aux n = function | T . Leaf -> None | T . Node ( _ , l , cell , r , _ ) -> let n0 = T . measure l + cell . offset in if n < n0 then aux n l else match aux ( n - n0 ) r with | Some _ as result -> result | None -> Some ( cell . cursor , cell . ...
let find_after t n = let rec aux n = function | T . Leaf -> None | T . Node ( _ , l , cell , r , _ ) -> let n0 = T . measure l in if n <= n0 && not ( is_leaf l ) then aux n l else let n1 = n0 + cell . offset in if n <= n1 then Some ( cell . cursor , cell . value ) else au...
let seek_before t c = validate t c " Trope . seek_before : cursor not in buffer " ; let rec aux = function | T . Leaf -> None | T . Node ( _ , l , cell , r , _ ) -> let c = compare c cell . cursor in if c <= 0 then aux l else match aux r with | Some _ as result -> result | None...
let seek_after t c = validate t c " Trope . seek_after : cursor not in buffer " ; let rec aux = function | T . Leaf -> None | T . Node ( _ , l , cell , r , _ ) -> let c = compare c cell . cursor in if c >= 0 then aux r else match aux l with | Some _ as result -> result | None ...
let to_list t = let rec aux acc n = function | T . Leaf -> acc | T . Node ( _ , l , cell , r , _ ) -> let n ' = n + T . measure l + cell . offset in let acc = aux acc n ' r in aux ( ( n ' , cell . cursor , cell . value ) :: acc ) n l in aux [ ] 0 t . tree
module Actions = struct type action = | Incoming_connection_error | Outgoing_connection_error | Gossiped_old_transition of int64 * int | Gossiped_future_transition | Gossiped_invalid_transition | Disconnected_chain | Sent_bad_hash | Sent_invalid_signature | Sent_invalid_transaction | Sent_invalid_proof | ...
module Peer_trust = Peer_trust . Make ( Actions ) Actions
let record_envelope_sender : t -> Logger . t -> Network_peer . Envelope . Sender . t -> Actions . t -> unit Deferred . t = fun t logger sender action -> match sender with | Local -> let action_fmt , action_metadata = Actions . to_log action in [ % log debug ] debug ~ metadata ( ( " : action ...
let subject a = Alcotest . testable ( pp ( Alcotest . pp a ) ) ( equal ( Alcotest . equal a ) ) ; ;
let validate_name ( name , age ) = if String . length name > 1 then Ok ( name , age ) else Error ( Invalid_name name ) ; ;
let validate_age ( name , age ) = if age >= 18 then Ok ( name , age ) else Error ( Invalid_age age ) ; ;
let simple_validation_success ( ) = let open Monad . Infix in let computed = Monad . return ( " Xavier " , 30 ) >>= validate_name >>= validate_age and expected = Ok ( " Xavier " , 30 ) in Alcotest . ( check ( subject ( pair string int ) ) ) " should be valid " expect...
let simple_validation_failure_1 ( ) = let open Monad . Infix in let computed = Monad . return ( " X " , 30 ) >>= validate_name >>= validate_age and expected = Error ( Invalid_name " X " ) in Alcotest . ( check ( subject ( pair string int ) ) ) " should be invalid " expe...
let simple_validation_failure_2 ( ) = let open Monad . Infix in let computed = Monad . return ( " Xavier " , 17 ) >>= validate_name >>= validate_age and expected = Error ( Invalid_age 17 ) in Alcotest . ( check ( subject ( pair string int ) ) ) " should be invalid " expect...
let cases = [ ( " Try " , let open Alcotest in [ test_case " Simple validation with success " ` Quick simple_validation_success ; test_case " Simple validation failure ( for name ) " ` Quick simple_validation_failure_1 ; test_case " Simple validation failure ( for age ) " ` Qu...
let print_sexp sexp = Printf . printf " % s \ n " ( sexp |> Sexp . to_string_hum )
let ( ) = Int_conversions . sexp_of_int_style := ` Underscores ; let _info = Info . of_string " foo " in let ivars = ref [ ] in let num_iters = 1_000 in Gc . full_major ( ) ; let minor_before = Gc . minor_words ( ) in let promoted_before = Gc . promoted_words ( ) in for ...
let calibrator = force Time_stamp_counter . calibrator
let command = Bench . make_command [ Bench . Test . create ~ name " : Time . now " ( fun ( ) -> ignore ( Time . now ( ) ) ) ; Bench . Test . create ~ name " : Calibrator . calibrate " ( fun ( ) -> ignore ( Time_stamp_counter . Calibrator . calibrate calibra...