text stringlengths 12 786k |
|---|
let license = " \ notice , this list of conditions and the following disclaimer . notice , this list of conditions and the following disclaimer in the documentation and / or other materials provided with the distribution . derived from this software without specific prior written permission . " |
let polycat write_one streaming in_file out_file = let ic , fname = match in_file with | ` File s -> open_in s , s in let oc = match out_file with | ` File s -> open_out s in let finally ( ) = if oc != stdout then close_out_noerr oc ; if ic != stdin then close_in_noerr ic in try if streaming the... |
let cat sort output_biniou std compact streaming in_file out_file = if not output_biniou then let write_one oc x = let x = if sort then Yojson . Safe . sort x else x in if compact then else output_char oc ' \ n ' in polycat write_one streaming in_file out_file else let write_one oc x = output_string oc ( ... |
let parse_cmdline ( ) = let out = ref None in let std = ref false in let compact = ref false in let streaming = ref true in let sort = ref false in let output_biniou = ref false in let options = [ " - o " , Arg . String ( fun s -> out := Some s ) , " < file > Output file " ; " ... |
let ( ) = let sort , output_biniou , std , compact , streaming , in_file , out_file = parse_cmdline ( ) in let success = let rec aux cpt b = if cpt = 100 then b else let b = ( b && cat sort output_biniou std compact streaming in_file out_file ) in aux ( cpt + 1 ) b in aux 0 true i... |
let populate_wallet yes_wallet_dir alias_pkh_pk_list = let pkh_filename = " public_key_hashs " in let pk_filename = " public_keys " in let sk_filename = " secret_keys " in if not ( Sys . file_exists yes_wallet_dir ) then Unix . mkdir yes_wallet_dir 0o750 ; Unix . chdir yes_wallet_dir ; if... |
let usage ( ) = Format . printf " > create minimal in < yes_wallet_dir . " >@ ; Format . printf " creates a yes - wallet with the foundation baker keys in \ < yes_wallet_dir . " >@ ; Format . printf " > create from context < base_dir > in < yes_wallet_dir > [ % s ] . " ... |
let ( ) = let argv = Array . to_list Sys . argv in let ( options , argv ) = List . partition ( fun arg -> String . length arg > 0 && String . get arg 0 = ' ' ) - argv in let active_bakers_only = List . exists ( fun opt -> opt = active_bakers_only_opt_name ) options in let ... |
type protocol = Florence | Granada | Hangzhou | Ithaca | Alpha |
let string_of_protocol = function | Florence -> " Florence " | Granada -> " Granada " | Hangzhou -> " Hangzhou " | Ithaca -> " Ithaca " | Alpha -> " Alpha " |
let pp_protocol ppf protocol = Format . fprintf ppf " % s " ( string_of_protocol protocol ) |
let pkh_json ( alias , pkh , _pk ) = Ezjsonm . ( dict [ ( " name " , string alias ) ; ( " value " , string pkh ) ] ) |
let pk_json ( alias , _pkh , pk ) = Ezjsonm . ( dict [ ( " name " , string alias ) ; ( " value " , dict [ ( " locator " , string @@ " unencrypted " : ^ pk ) ; ( " key " , string pk ) ] ) ; ] ) |
let sk_of_pk ( pk_s : string ) : string = let open Tezos_crypto . Signature in let pk = Public_key . of_b58check_exn pk_s in let pk_b = Data_encoding . Binary . to_bytes_exn Public_key . encoding pk in let sk_b = Bytes . sub pk_b 0 33 in let sk = Data_encoding . Binary . of_bytes_exn Secret... |
let sk_json ( alias , _pkh , pk ) = Ezjsonm . ( dict [ ( " name " , string alias ) ; ( " value " , string @@ " unencrypted " : ^ sk_of_pk pk ) ; ] ) |
let map_bind_to_json f list = Ezjsonm . list f list |
let pkh_list_json list = map_bind_to_json pkh_json list |
let pk_list_json list = map_bind_to_json pk_json list |
let sk_list_json list = map_bind_to_json sk_json list |
let json_to_file json file = let chan = open_out file in Ezjsonm . to_channel ~ minify : false chan json ; close_out chan |
let alias_pkh_pk_list = [ ( " foundation1 " , " tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9 " , " p2pk67wVncLFS1DQDm2gVR45sYCzQSXTtqn3bviNYXVCq6WRoqtxHXL " ) ; ( " foundation2 " , " tz3bvNMQ95vfAYtG8193ymshqjSvmxiCUuR5 " , " p2pk66n1NmhPDEkcf9sXEKe9kBoTwBoTYxke1hx16aTRVq8MoXuwNqo " )... |
let get_delegates ( proto : protocol ) context ( header : Block_header . shell_header ) active_bakers_only = let open Lwt_tzresult_syntax in let level = header . Block_header . level in let predecessor_timestamp = header . timestamp in let timestamp = Time . Protocol . add predecessor_timestam... |
let protocol_of_hash protocol_hash = if Protocol_hash . equal protocol_hash Tezos_protocol_009_PsFLoren . Protocol . hash then Some Florence else if Protocol_hash . equal protocol_hash Tezos_protocol_010_PtGRANAD . Protocol . hash then Some Granada else if Protocol_hash . equal protocol_hash Tezos_protoc... |
let load_mainnet_bakers_public_keys base_dir active_bakers_only = let open Lwt_tzresult_syntax in let open Tezos_store in let mainnet_genesis = { Genesis . time = Time . Protocol . of_notation_exn " 2018 - 06 - 30T16 : 07 : 32Z " ; block = Block_hash . of_b58check_exn " BLockGenesisGenesi... |
let load_mainnet_bakers_public_keys base_dir active_bakers_only = match Lwt_main . run ( load_mainnet_bakers_public_keys base_dir active_bakers_only ) with | Ok alias_pkh_pk_list -> alias_pkh_pk_list | Error trace -> Format . eprintf " error . :@% a . " @ Error_monad . pp_print_trace trace ; ... |
type t = { month_count : int } |
let equal ( x : t ) ( y : t ) = x . month_count = y . month_count |
let lt ( x : t ) ( y : t ) = x . month_count < y . month_count |
let le ( x : t ) ( y : t ) = x . month_count <= y . month_count |
let gt ( x : t ) ( y : t ) = x . month_count > y . month_count |
let ge ( x : t ) ( y : t ) = x . month_count >= y . month_count |
let compare ( x : t ) ( y : t ) = compare x . month_count y . month_count |
let month_count_of_ym ~ year ~ month = ( year * 12 ) + ( month - 1 ) |
let ym_of_month_count month_count = if month_count >= 0 then ( month_count / 12 , ( month_count mod 12 ) + 1 ) else ( ( month_count - 11 ) / 12 , ( ( ( month_count mod 12 ) + 12 ) mod 12 ) + 1 ) |
type error = [ ` Does_not_exist | ` Invalid_year of int | ` Invalid_month of int ] |
let make ~ year ~ month : ( t , error ) result = if year < Constants . min_year || Constants . max_year < year then Error ( ` Invalid_year year ) else if month < 1 || 12 < month then Error ( ` Invalid_month month ) else Ok { month_count = month_count_of_ym ~ year ~ month } |
let make_exn ~ year ~ month : t = match make ~ year ~ month with Error e -> raise ( Error_exn e ) | Ok x -> x |
let sub_month_count ( t : t ) n : t = { month_count = t . month_count - n } |
let sub ( ? years = 0 ) ( ? months = 0 ) t : t = sub_month_count t ( ( years * 12 ) + months ) |
let add_month_count ( t : t ) n : t = { month_count = t . month_count + n } |
let add ( ? years = 0 ) ( ? months = 0 ) t : t = add_month_count t ( ( years * 12 ) + months ) |
let diff_months t1 t2 = t1 . month_count - t2 . month_count |
let year_month ( t : t ) : int * int = ym_of_month_count t . month_count |
let year ( t : t ) : int = fst @@ year_month t |
let month ( t : t ) : int = snd @@ year_month t |
module Alco = struct let lt_case0 ( ) = Alcotest . ( check bool ) " less than " true Timedesc . Ym . ( lt ( make_exn ~ year : 2000 ~ month : 1 ) ( make_exn ~ year : 2000 ~ month : 2 ) ) let lt_case1 ( ) = Alcotest . ( check bool ) " less than " false Timedesc .... |
module Qc = struct let to_iso8601_of_iso8601 = QCheck . Test . make ~ count : 100_000 ~ name " : to_iso8601_of_iso8601 " ym ( fun ( year , month ) -> let d = Timedesc . Ym . make_exn ~ year ~ month in let d ' = d |> Timedesc . Ym . to_iso8601 |> Timedesc . Ym . of_iso8601 |>... |
module Pretty = struct end |
module Util = struct # include " util . ml " end end |
module Util = struct # include " util . ml " end end |
module Raw = struct end |
let rec biniou_of_json = function ` Null -> ` Unit | ` Bool b -> ` Bool b | ` Int i -> ` Svint i | ` Intlit i -> failwith " Cannot convert big int to biniou " | ` Float f -> ` Float64 f | ` String s -> ` String s | ` Assoc l -> let a = Array . map ( fun ( s , x ) ->... |
let rec json_of_biniou ( x : Bi_io . tree ) = match x with ` Unit -> ` Null | ` Bool b -> ` Bool b | ` Int8 _ -> failwith " Cannot convert int8 to JSON " | ` Int16 _ -> failwith " Cannot convert int16 to JSON " | ` Int32 _ -> failwith " Cannot convert int32 to JSON " | ` ... |
let test = let open Yojson_unittest_types in let all_basic_types = { field01 = 1 . 2000001 ; field02 = 1 . 2 ; field03 = 0xEFFFFFFFl ; field04 = 0xEBABABABABABABABL ; field05 = 0x7FFFFFFFl ; field06 = 0x7BABABABABABABABL ; field07 = 0xEFFFFFFFl ; field08 = 0xEBABABABABABABABL ; ... |
let ( ) = let json_str = Yojson_unittest_yojson . encode_test test |> Yojson . Basic . to_string in print_endline json_str ; let test ' = json_str |> Yojson . Basic . from_string |> Yojson_unittest_yojson . decode_test in assert ( asserttest = test ' ) test ' ; ( ) |
let ( ) = print_endline " \ nConsistency tests . . . Ok " |
let ( ) = let ic = let filename = " yojson . data " in open_in filename in let buffer_len = 1024 * 1024 in let buffer = Bytes . create buffer_len in let buffer_len = match input ic buffer 0 buffer_len with | i when i < buffer_len -> i | _ -> assert ( assertfalse ) assertfalse in let test ... |
type bbox = { xmin : float ; ymin : float ; xmax : float ; ymax : float ; confidence : float ; class_index : int ; class_confidence : float } |
let iou b1 b2 = let b1_area = ( b1 . xmax . - b1 . xmin . + 1 . ) . * ( b1 . ymax . - b1 . ymin . + 1 . ) in let b2_area = ( b2 . xmax . - b2 . xmin . + 1 . ) . * ( b2 . ymax . - b2 . ymin . + 1 . ) in let i_xmin = Float . max b1 . xmin b... |
let colors = [ | [ | 0 . 5 ; 0 . 0 ; 0 . 5 ] | ; [ | 0 . 0 ; 0 . 5 ; 0 . 5 ] | ; [ | 0 . 5 ; 0 . 5 ; 0 . 0 ] | ; [ | 0 . 7 ; 0 . 3 ; 0 . 0 ] | ; [ | 0 . 7 ; 0 . 0 ; 0 . 3 ] | ; [ | 0 . 0 ; ... |
let report predictions ~ image ~ width ~ height = Tensor . print_shape ~ name " : predictions " predictions ; let bboxes = List . init ( Tensor . shape2_exn predictions |> fst ) ~ f ( : fun index -> let predictions = Tensor . get predictions index |> Tensor . to_float1_exn in let conf... |
let ( ) = let module Sys = Caml . Sys in if Array . length Sys . argv <> 3 then Printf . failwithf " usage : % s yolo - v3 . ot input . png " Sys . argv . ( 0 ) ( ) ; let vs = Var_store . create ~ name " : rn " ~ device : Cpu ( ) in let darknet = Darknet . par... |
type ( ' a , ' b ) ' b exec = ( ' a , unit , string , ' b ) ' b format4 -> ' a |
let env = Hashtbl . create 8 |
let shell_set = ref " " |
let suppress_failure = ref false |
let last_status = ref 0 |
let export k v = Hashtbl . replace env k ( Some v ) v |
let set opts = shell_set := opts |
let unset k = Hashtbl . replace env k None |
let getenv_default var default = try Sys . getenv var with Not_found -> default |
let q = Printf . sprintf " " \% s " " \ |
let ql = map q |
let split_char_bounded str ~ on ~ max = let open String in if str = " " then [ ] else if max = 1 then [ str ] str else let rec loop offset tokens = if tokens = max - 1 then [ sub str offset ( length str - offset ) offset ] offset else try let index = index_from str offset on in if index =... |
let split_char_unbounded_no_trailer str ~ on = let open String in if str = " " then [ ] else let rec loop acc offset = try begin let index = rindex_from str offset on in if index = offset then loop acc ( index - 1 ) 1 else let token = sub str ( index + 1 ) 1 ( offset - index ) index in l... |
let some = function " " -> None | x -> Some x |
let list = split_char_unbounded_no_trailer ~ on : ' ' |
let lines = let rm_trailing_CR s = let len = String . length s in if len > 0 && s [ . len - 1 ] 1 = ' \ r ' then String . sub s 0 ( len - 1 ) 1 else s in fun str -> let l = split_char_unbounded_no_trailer ~ on : ' \ n ' str in List . map rm_trailing_CR l |
let pair s = match split_char_bounded s ~ on : ' : ' ~ max : 2 with | [ ] -> ( " " , None ) None | [ x ] x -> ( x , None ) None | x :: y :: _ -> ( x , Some y ) y |
let fuzzy_bool_of_string s = match String . lowercase s with | " false " | " 0 " -> false | _ -> true |
let echo fmt = Printf . ksprintf print_endline fmt |
let is_space = function ' ' | ' \ 012 ' | ' \ n ' | ' \ r ' | ' \ t ' -> true | _ -> false |
let trim s = let open String in let len = length s in let i = ref 0 in while ! i < len && is_space ( unsafe_get s ! i ) i do incr i done ; let j = ref ( len - 1 ) 1 in while ! j >= ! i && is_space ( unsafe_get s ! j ) j do decr j done ; if ! j >= ! i then sub s ! i ( ! j - ! i ... |
let escape_unprintable s = let must_not_escape = ref true in let i = ref 0 in while ! i < String . length s && ! must_not_escape do if s [ . ! i ] i < ' ' then must_not_escape := false ; incr i done ; if ! must_not_escape then s else ( let b = Buffer . create ( String . length s + 8 )... |
let same_fds f = Unix ( . f ~ stdin ~ stdout ~ stderr ) stderr |
let shell command ~ stdin ~ stdout ~ stderr = Unix . create_process " sh " [ " | sh " ; " - c " ; command ] | stdin stdout stderr |
let after pid = Unix ( . match waitpid [ ] pid with | ( _ , WEXITED k ) k -> last_status := k ; k | ( _ , WSIGNALED _ ) _ -> failwith " child unexpectedly signaled " | ( _ , WSTOPPED _ ) _ -> failwith " child unexpectedly stopped " ) |
let after_shell command ~ stdin ~ stdout ~ stderr = match after ( shell command ~ stdin ~ stdout ~ stderr ) stderr with | 0 -> ( ) | x -> if not ! suppress_failure then begin Printf . eprintf " ' % s ' exited % d . Terminating with % d \ n " ( escape_unprintable command ) command... |
module Quips = struct let ( *~ ) list sep = String . concat sep list let ( ) ~~ = format_of_string let apply_env command = let set = match ! shell_set with | " " -> " " | opts -> " set " ^ opts " ; ^ " in ( ( Hashtbl . fold ( fun k v list -> match v with | Some v -> ( k " "... |
let zero = Num . num_of_int 0 |
let of_int64 x = Num . num_of_big_int ( Big_int . big_int_of_int64 x ) |
let to_int64 x = Big_int . int64_of_big_int ( Num . big_int_of_num x ) |
let div_rem a b = Num . quo_num a b , Num . mod_num a b |
let of_bits b = let n = ref ( Num . num_of_int 0 ) in let p = ref ( Num . num_of_int 1 ) in let f = Num . num_of_int 256 in for i = 0 to String . length b - 1 do let c = Char . code ( String . get b i ) in n := Num . add_num ! n ( Num . mult_num ! p ( Num . num_of_int c ... |
let to_bits n = let n = ref ( Num . abs_num n ) in let l = ref [ ] in let f = Num . num_of_int 256 in while Num . gt_num ! n zero do let d , r = div_rem ! n f in l := Char . unsafe_chr ( to_int r ) :: ! l ; n := d ; done ; let b = Bytes . create ( List . length ! l ) in... |
let numbits x = assert false |
let extract _ _ _ = assert false |
let div x y = fst ( div_rem x y ) |
let sub x y = Num . sub_num x y |
let desc e = e . desc |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.