text stringlengths 0 601k |
|---|
let make ? bufsize len default = let buf = Array . make ( match bufsize with None -> len | Some n -> n ) n default in { len = len ; buf = buf ; default = default } default |
let clear x = x . len <- 0 |
let reset x = x . len <- 0 ; x . buf <- Array . make 0 x . default |
let copy x = { len = x . len ; buf = Array . copy x . buf ; default = x . default } default |
let sub x pos len = { len = len ; buf = Array . sub x . buf pos len ; default = x . default } default |
let add_element x e = expand x ( x . len + 1 ) 1 ; x . buf ( . x . len ) len <- e ; x . len <- x . len + 1 |
let add_array x a = expand x ( x . len + Array . length a ) a ; Array . blit a 0 x . buf x . len ( Array . length a ) a ; x . len <- x . len + Array . length a |
let add_xarray x1 x2 = expand x1 ( x1 . len + x2 . len ) len ; Array . blit x2 . buf 0 x1 . buf x1 . len x2 . len ; x1 . len <- x1 . len + x2 . len |
let shrink x len = x . len <- min x . len ( max 0 len ) len |
let append x1 x2 = let buf = Array . make ( x1 . len + x2 . len ) len x1 . default in Array . blit x1 . buf 0 buf 0 x1 . len ; Array . blit x2 . buf 0 buf x1 . len x2 . len ; { len = x1 . len + x2 . len ; buf = buf ; default = x1 . default } default |
let array_of x = Array . sub x . buf 0 x . len |
let iter proc x = for i = 0 to x . len - 1 do proc x . buf ( . i ) i done |
type ' a expr = ( ' a , Biniou . biniou_repr ) Mapping . mapping |
type ' a def = ( ' a , Biniou . biniou_repr ) Mapping . def |
type ' a grouped_defs = ( bool * ' a def list ) list |
type name = ( loc * string ) |
type names = { field_names : name list list ; variant_names : name list list ; } |
let rec extract_names_from_expr acc ( x : ' a expr ) = match x with Unit _ | Bool _ | Int _ | Float _ | String _ -> acc | Sum ( _ , va , _ , _ ) -> let l , ( fn , vn ) = Array . fold_left extract_names_from_variant ( [ ] , acc ) va in ( fn , List . rev l :: vn ) | Record ( _ , fa , _ , _ ) -> let l , ( fn , vn ) = Arra... |
let extract_ocaml_names_from_defs l = let fn , vn = List . fold_left ( fun acc def -> match def . def_value with None -> acc | Some x -> extract_names_from_expr acc x ) ( [ ] , [ ] ) l in { field_names = List . rev fn ; variant_names = List . rev vn ; } |
let check_duplicate_hashes kind l = let tbl = Hashtbl . create 100 in List . iter ( fun ( loc , s ) -> let h = Bi_io . hash_name s in try let loc0 , s0 = Hashtbl . find tbl h in Error . error2 loc0 ( sprintf " Definition of % s % s . " kind s0 ) loc ( sprintf " \ kind s s0 s h ) with Not_found -> Hashtbl . add tbl h ( ... |
let check_hashes x = List . iter ( check_duplicate_hashes " record field name " ) x . field_names ; List . iter ( check_duplicate_hashes " variant name " ) x . variant_names |
let check ( l : ' a grouped_defs ) = extract_ocaml_names_from_defs ( List . concat_map snd l ) |> check_hashes let tbl = Hashtbl . create ( 2 * List . length l ) in List . iter ( fun s -> let h = Bi_io . hash_name s in let r = try Hashtbl . find tbl h with Not_found -> let r = ref [ ] in Hashtbl . add tbl h r ; r in r ... |
type auth = [ | ` Fingerprint of string | ` Trust_anchor of string |
type t = { version : int ; jid : Xjid . full_jid ; priority : int option ; hostname : string option ; port : int option ; password : string option ; authenticator : auth ; otr_config : Otr . State . config ; dsa : Mirage_crypto_pk . Dsa . priv ; certificate_hostname : string option ; notification_callback : string opti... |
let dsa_of_cfg_sexp t = match t with | Sexp . List l -> ( List . fold_left ( fun ( dsa , cfg ) cfg -> function | Sexp . List [ Sexp . Atom " otr_config " ; Sexp . List data ] -> List . fold_left ( fun ( dsa , cfg ) cfg -> function | Sexp . List [ Sexp . Atom " policies " ; _ ] as p -> ( dsa , p :: cfg ) cfg | Sexp . Li... |
let t_of_sexp dsa t = let dsa , otr_cfg = match dsa , dsa_of_cfg_sexp t with | None , ( Some dsa , cfg ) cfg -> dsa , cfg | Some x , ( _ , cfg ) cfg -> x , cfg | _ -> raise ( Invalid_argument " broken config ) " in let otr_config = Otr . State . config_of_sexp ( Sexp . List otr_cfg ) otr_cfg in match t with | Sexp . Li... |
let record kvs = Sexp . List List ( . map ( fun ( k , v ) v -> ( Sexp . List [ Sexp . Atom k ; v ] v ) v ) v kvs ) kvs |
let sexp_of_t t = record [ " version " , sexp_of_int t . version ; " jid " , sexp_of_string ( Xjid . full_jid_to_string t . jid ) jid ; " hostname " , sexp_of_option sexp_of_string t . hostname ; " port " , sexp_of_option sexp_of_int t . port ; " priority " , sexp_of_option sexp_of_int t . priority ; " authenticator " ... |
let load_config dsa bytes = t_of_sexp dsa ( Sexp . of_string bytes ) bytes |
let store_config t = Bytes . of_string ( Sexp . to_string_hum ( sexp_of_t t ) t ) t |
let create kind n = FFT . Array1 . create kind fortran_layout n |
let log2 = log 2 . |
let minpow2 l = truncate ( 2 . ( ** ceil ( log ( float l ) . / log2 ) ) ) |
let copy0 ? n ? ofsx ( x : D . vec ) ( ? ofsy = 1 ) ( y : D . vec ) = let n = match n with None -> Array1 . dim x | Some n -> n in for i = 1 to ofsy - 1 do y . { i } <- 0 . done ; ignore ( D . copy ~ n ? ofsx x ~ ofsy ~ y ) ; for i = ofsy + n to Array1 . dim y do y . { i } <- 0 . done |
type scale = Biased | Unbiased | Coeff |
let xcorr ? maxlag ? scale ( a : D . vec ) ( b : D . vec ) = let dima = Array1 . dim a and dimb = Array1 . dim b in if dima < 1 || dimb < 1 then invalid_arg " xcorr : array size < 1 " ; let m = max dima dimb in let maxlag = match maxlag with Some i -> i | None -> m - 1 in let ilag0 = maxlag + 1 in let dim_xcorr = 2 * m... |
let ( ) = Lacaml . Io . pp_float_el_default := ( fun ppf el -> fprintf ppf " . % 4g " el ) |
let pp_fvec ( ? nl = true ) xname x = printf " [ @< 2 >% s = [ " xname ; Lacaml . Io . pp_rfvec std_formatter x ; printf " ] ] " ; @ if nl then printf " @\ n " |
let pp_cvec xname x = printf " [ @< 2 > % s = [ " xname ; Lacaml . Io . pp_rcvec std_formatter x ; printf " ] ] " @ |
let approx_eq ( ? eps = 1e - 10 ) a b = if Vec . dim a <> Vec . dim b then false else begin let eq x y = ( ( y = 0 . && abs_float x <= eps ) || abs_float ( x . - y ) <= eps . * abs_float y ) in let is_eq = ref true in for i = 1 to Vec . dim a do is_eq := ! is_eq && eq a . { i } b . { i } done ; ! is_eq end |
let test text a rep = printf " % s [ @= [ " text ; Lacaml . Io . pp_rfvec std_formatter a ; if approx_eq a rep then printf " ] ] @ ( ok ) @\ n " else ( printf " ] @\ n [ " ; <> Lacaml . Io . pp_rfvec std_formatter rep ; printf " ] ] @@\ n " ) |
let ( ) = let x = Vec . of_array [ | 1 . ; 2 . ; 3 . ; 4 . ] | and y = Vec . of_array [ | 1 . ; 2 . ] | in pp_fvec " x " x ; pp_fvec " y " y ; test " xcorr x x " ( xcorr x x ) ( Vec . of_array [ | 4 . ; 11 . ; 20 . ; 30 . ; 20 . ; 11 . ; 4 . ] ) ; | test " xcorr x x ~ scale : Biased " ( xcorr x x ~ scale : Biased ) ( V... |
type t = { env : string -> string option ; win32 : bool ; home_dir : string ; mutable cache_dir : string ; mutable config_dir : string ; mutable data_dir : string ; mutable runtime_dir : string option } |
let ( / ) = Filename . concat |
let make t env_var unix_default win32_default = let default = if t . win32 then win32_default else unix_default in match t . env env_var with | None -> default | Some s when Filename . is_relative s -> default | Some s -> s |
let cache_dir t = let home = t . home_dir in make t " XDG_CACHE_HOME " ( home / " . cache " ) ( home / " Local Settings " / " Cache " ) |
let config_dir t = let home = t . home_dir in make t " XDG_CONFIG_HOME " ( home / " . config " ) ( home / " Local Settings " ) |
let data_dir t = let home = t . home_dir in make t " XDG_DATA_HOME " ( home / " . local " / " share " ) ( match t . env " AppData " with | Some s -> s | None -> " " ) |
let create ? win32 ~ env ( ) = let win32 = match win32 with | None -> Sys . win32 | Some s -> s in let home_dir = match env " HOME " with | Some s -> s | None -> if win32 then match env " AppData " with | None -> " " | Some s -> s else " " in let t = { env ; win32 ; home_dir ; cache_dir = " " ; config_dir = " " ; data_... |
let home_dir t = t . home_dir |
let config_dir t = t . config_dir |
let data_dir t = t . data_dir |
let cache_dir t = t . cache_dir |
let runtime_dir t = t . runtime_dir |
type pos = float * float |
type bounding_box = pos * pos |
type node_layout = { n_name : string ; n_pos : pos ; n_bbox : bounding_box ; n_draw : XDotDraw . operation list ; n_ldraw : XDotDraw . operation list ; } |
type cluster_layout = { c_pos : pos ; c_bbox : bounding_box ; c_draw : XDotDraw . operation list ; c_ldraw : XDotDraw . operation list ; } |
type edge_layout = { e_draw : XDotDraw . operation list ; e_ldraw : XDotDraw . operation list ; e_hdraw : XDotDraw . operation list ; e_tdraw : XDotDraw . operation list ; e_hldraw : XDotDraw . operation list ; e_tldraw : XDotDraw . operation list ; } |
let mk_node_layout ~ name ~ pos ~ bbox ~ draw ~ ldraw = { n_name = name ; n_pos = pos ; n_bbox = bbox ; n_draw = draw ; n_ldraw = ldraw } |
let mk_cluster_layout ~ pos ~ bbox ~ draw ~ ldraw = { c_pos = pos ; c_bbox = bbox ; c_draw = draw ; c_ldraw = ldraw } |
let mk_edge_layout ~ draw ~ ldraw ~ hdraw ~ tdraw ~ hldraw ~ tldraw = { e_draw = draw ; e_ldraw = ldraw ; e_hdraw = hdraw ; e_tdraw = tdraw ; e_hldraw = hldraw ; e_tldraw = tldraw ; } |
let read_pos s = Scanf . sscanf s " % f , % f " ( fun x y -> x , . - y ) |
let bounding_box ( x , y ) w h = let lower_left = x . - w , y . - h in let upper_right = x . + w , y . + h in lower_left , upper_right |
let get_dot_string = function | Dot_ast . String s -> s | Dot_ast . Ident s -> s | Dot_ast . Number s -> s | Dot_ast . Html s -> s |
let read_common_layout mk_layout attr_list = let fold ( ( p , w , h , draw , ldraw ) as attrs ) = function | ( Dot_ast . Ident " pos " ) , Some ( Dot_ast . String s ) -> ( Some s ) , w , h , draw , ldraw | ( Dot_ast . Ident " width " ) , Some ( Dot_ast . String s ) -> p , ( Some s ) , h , draw , ldraw | ( Dot_ast . Ide... |
let read_node_layout ( id , _ ) attrs = let f = read_common_layout ( fun ~ pos ~ bbox ~ draw ~ ldraw -> mk_node_layout ~ pos ~ bbox ~ draw ~ ldraw ) attrs in f ~ name ( : get_dot_string id ) |
let read_cluster_layout = read_common_layout mk_cluster_layout |
let read_edge_layout attr_list = let draw = ref [ ] in let ldraw = ref [ ] in let hdraw = ref [ ] in let tdraw = ref [ ] in let hldraw = ref [ ] in let tldraw = ref [ ] in let fill_draw_ops = function | ( Dot_ast . Ident " _draw_ " ) , Some ( Dot_ast . String s ) -> draw := XDotDraw . parse s | ( Dot_ast . Ident " _ldr... |
let read_bounding_box str = let x1 , y1 , x2 , y2 = Scanf . sscanf str " % f , % f , % f , % f " ( fun a b c d -> a , b , c , d ) in let lower_left = ( x1 , . - y2 ) and upper_right = x2 , . - y1 in lower_left , upper_right |
module Make ( G : Graphviz . GraphWithDotAttrs ) = struct module HV = Hashtbl . Make ( G . V ) module HE = Map . Make ( struct type t = G . E . t let compare = G . E . compare end ) module HT = Hashtbl . Make ( Util . HTProduct ( Util . HTProduct ( G . V ) ( G . V ) ) ( struct type t = string let equal = ( ) = let hash... |
type pos = float * float |
type align = Left | Center | Right |
type style_attr = | Filled | Invisible | Diagonals | Rounded | Dashed | Dotted | Solid | Bold | StyleString of string |
type operation = | Filled_ellipse of pos * width * height | Unfilled_ellipse of pos * width * height | Filled_polygon of pos array | Unfilled_polygon of pos array | Polyline of pos array | Bspline of pos array | Filled_bspline of pos array | Text of pos * align * width * string | Fill_color of string | Pen_color of str... |
type draw_state = { mutable fill_color : string ; mutable pen_color : string ; mutable font : float * string ; mutable style : style_attr list } |
let default_draw_state ( ) = { fill_color = " # FFFFFF " ; pen_color = " # 000000 " ; font = 0 . , " " ; style = [ ] } |
let set_fill_color st c = st . fill_color <- c |
let set_pen_color st c = st . pen_color <- c |
let set_font st c = st . font <- c |
let set_style st s = st . style <- s |
let suffix s i = try String . sub s i ( String . length s - i ) with Invalid_argument _ -> " " |
let split c s = let rec split_from n = try let p = String . index_from s n c in ( String . sub s n ( p - n ) ) :: ( split_from ( p + 1 ) ) with Not_found -> [ suffix s n ] in if s " " = then [ ] else split_from 0 ; ; |
let string_scale_size ( ~ fontMeasure : fontName : string -> fontSize : int -> string -> ( int * int ) ) font size s = let width , height = fontMeasure ~ fontName : font ~ fontSize ( : int_of_float size ) s in let width = float width in let linear_width = size . * ( float ( String . length s ) ) in size . * width . / l... |
let normalize_color s = try let h , s , v = Scanf . sscanf s " % f % f % f " ( fun a b c -> ( a , b , c ) ) in let h ' = 360 . . * h . / 60 . in let hi = truncate h ' mod 6 in let f = h ' . - floor h ' in let p = v . * ( 1 . . - s ) in let q = v . * ( 1 . . - f . * s ) in let t = v . * ( 1 . . - ( 1 . . - f ) . * s ) i... |
type state = { mutable operations : operation list ; mutable cur : int ; str : string ; } |
let mk_state s = { operations = [ ] ; cur = 0 ; str = s } |
let char state = state . str . [ state . cur ] |
let incr state = state . cur <- state . cur + 1 |
let over state = state . cur >= String . length state . str |
let add_operation i state = state . operations <- i :: state . operations |
let get_n n st = let s = String . sub st . str st . cur n in st . cur <- st . cur + n ; s |
let is_space = function | ' ' | ' \ t ' | ' \ n ' -> true | _ -> false |
let is_token = function | " E " | " e " | " P " | " p " | " L " | " B " | " b " | " T " | " C " | " c " | " F " | " S " -> true | _ -> false |
let skip_spaces state = let rec loop ( ) = if not ( over state ) then if is_space ( char state ) then begin incr state ; loop ( ) end in loop ( ) |
let get_word state = skip_spaces state ; let start = state . cur in let rec get ' ( ) = if over state then if start = String . length state . str then None else Some ( String . sub state . str start ( state . cur - start ) ) else if not ( is_space ( char state ) ) then begin incr state ; get ' ( ) end else Some ( Strin... |
let get_op_id state = let tok = get_word state in match tok with | None -> raise NoOperationId | Some tok ' -> if is_token tok ' then tok ' else raise NoOperationId |
let get_int state = match get_word state with | Some w -> begin try int_of_string w with Failure _ -> raise ( ParseError " Cannot parse int " ) end | None -> raise ( ParseError " Cannot parse int " ) |
let get_float state = match get_word state with | Some w -> begin try float_of_string w with Failure _ -> raise ( ParseError " Cannot parse float " ) end | None -> raise ( ParseError " Cannot parse float " ) |
let get_pos state = try let x0 = get_float state in let y0 = get_float state in ( x0 , y0 ) with ParseError _ -> raise ( ParseError " Cannot parse point in position " ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.