text
stringlengths
0
601k
let create len = make len ( UChar . chr 0 )
let copy s = s # copy
let sub s start len = s # sub start len
let fill s start len u = for i = start to start + len - 1 do s # set i u done
let blit src srcoff dst dstoff len = for i = 0 to len - 1 do let u = src # get ( srcoff + i ) in dst # set ( dstoff + i ) u done
let concat s1 s2 = s1 # concat ( s2 :> uchar storage )
let iter proc s = s # iter proc end
let ( >>= ) = Result . bind
let scalar ? anchor ? tag ( ? plain_implicit = true ) true ( ? quoted_implicit = false ) false ( ? style = ` Plain ) Plain value = { anchor ; tag ; plain_implicit ; quoted_implicit ; style ; value }
let yaml_scalar_to_json t = match t with | " null " | " NULL " | " " | " Null " | " " ~ -> ` Null | " y " | " Y " | " yes " | " Yes " | " YES " | " true " | " True " | " TRUE " | " on " | " On " | " ON " -> ` Bool true | " n " | " N " | " no " | " No " | " NO " | " false " | " False " | " FALSE " | " off " | " Off " | ...
let to_json v = let rec fn = function | ` Scalar { value ; quoted_implicit = true } -> ` String value | ` Scalar { value } -> yaml_scalar_to_json value | ` Alias _ -> failwith " Anchors are not supported when serialising to JSON " | ` A { s_members } -> ` A ( List . map fn s_members ) s_members | ` O { m_members } -> l...
let of_json ( v : value ) value = let rec fn = function | ` Null -> ` Scalar ( scalar ) " " | ` Bool b -> ` Scalar ( scalar ( string_of_bool b ) b ) b | ` Float f -> ` Scalar ( scalar ( string_of_float f ) f ) f | ` String value -> ` Scalar ( scalar value ) value | ` A l -> ` A { s_anchor = None ; s_tag = None ; s_impl...
let to_string ? len ( ? encoding = ` Utf8 ) Utf8 ? scalar_style ? layout_style ( v : value ) value = emitter ? len ( ) >>= fun t -> stream_start t encoding >>= fun ( ) -> document_start t >>= fun ( ) -> let rec iter = function | ` Null -> Stream . scalar ( scalar ) " " t | ` String s -> let style = match yaml_scalar_to...
let to_string_exn ? len ? encoding ? scalar_style ? layout_style s = match to_string ? len ? encoding ? scalar_style ? layout_style s with | Ok s -> s | Error ( ` Msg m ) m -> raise ( Invalid_argument m ) m
let yaml_to_string ( ? encoding = ` Utf8 ) Utf8 ? scalar_style ? layout_style v = emitter ( ) >>= fun t -> stream_start t encoding >>= fun ( ) -> document_start t >>= fun ( ) -> let rec iter = function | ` Scalar s -> Stream . scalar s t | ` Alias anchor -> alias t anchor | ` A { s_anchor = anchor ; s_tag = tag ; s_imp...
let yaml_of_string s = let open Event in parser s >>= fun t -> let next ( ) = do_parse t >>= fun ( e , pos ) pos -> Ok ( e , pos ) pos in next ( ) >>= fun ( e , pos ) pos -> match e with | Stream_start _ -> ( next ( ) >>= fun ( e , pos ) pos -> match e with | Document_start _ -> let rec parse_v ( e , pos ) pos = match ...
let of_string s = yaml_of_string s >>= to_json
let of_string_exn s = match of_string s with | Ok s -> s | Error ( ` Msg m ) m -> raise ( Invalid_argument m ) m
let pp ppf s = match to_string s with | Ok s -> Format . pp_print_string ppf s | Error ( ` Msg m ) m -> Format . pp_print_string ppf ( Printf . sprintf ( " error ( % s ) s ) s " m ) m
let rec equal v1 v2 = match ( v1 , v2 ) v2 with | ` Null , ` Null -> true | ` Bool x1 , ` Bool x2 -> ( ( = ) : bool -> bool -> bool ) bool x1 x2 | ` Float x1 , ` Float x2 -> ( ( = ) : float -> float -> bool ) bool x1 x2 | ` String x1 , ` String x2 -> String . equal x1 x2 | ` A xs1 , ` A xs2 -> List . for_all2 equal xs1...
let uuid_random_state = Random . State . make_self_init ( )
module Make ( File : WitnessUtil . File ) ( Cfg : MyCFG . CfgBidir ) ( Spec : Spec ) ( EQSys : GlobConstrSys with module LVar = VarF ( Spec . C ) and module GVar = GVarF ( Spec . V ) and module D = Spec . D and module G = Spec . G ) ( LHT : BatHashtbl . S with type key = EQSys . LVar . t ) ( GHT : BatHashtbl . S with t...
module M ( F : Ctypes . FOREIGN ) FOREIGN = struct let foreign = F . foreign module C = struct include Ctypes let ( @-> ) = F ( . @-> ) let returning = F . returning end let version = foreign " yaml_get_version_string " C ( . void @-> returning string ) string let get_version = foreign " yaml_get_version " C ( . ptr in...
module Encoding = struct type t = [ ` Any | ` E of int64 | ` Utf16be | ` Utf16le | ` Utf8 ] end
module Error = struct type t = [ ` None | ` Memory | ` Reader | ` Scanner | ` Parser | ` Composer | ` Writer | ` Emitter | ` E of int64 ] end
module Scalar_style = struct type t = [ ` Any | ` Plain | ` Single_quoted | ` Double_quoted | ` Literal | ` Folded | ` E of int64 ] end
module Sequence_style = struct type t = [ ` Any | ` Block | ` Flow | ` E of int64 ] end
module Mapping_style = struct type t = [ ` Any | ` Block | ` Flow | ` E of int64 ] end
module Token_type = struct type t = [ ` None | ` Stream_start | ` Stream_end | ` Version_directive | ` Tag_directive | ` Document_start | ` Document_end | ` Block_sequence_start | ` Block_mapping_start | ` Block_end | ` Flow_sequence_start | ` Flow_sequence_end | ` Flow_mapping_start | ` Flow_mapping_end | ` Block_entr...
module Event_type = struct type t = [ ` None | ` Stream_start | ` Stream_end | ` Document_start | ` Document_end | ` Alias | ` Scalar | ` Sequence_start | ` Sequence_end | ` Mapping_start | ` Mapping_end | ` E of int64 ] end
module M ( F : Ctypes . TYPE ) TYPE = struct let yaml_char_t = F . uchar let enum label typedef vals = F . enum ~ typedef : true ~ unexpected ( : fun i -> ` E i ) i typedef ( List . map ( fun ( a , b ) b -> ( a , F . constant ( " YAML_ " ^ b ^ " _ " ^ label ) label F . int64_t ) int64_t ) int64_t vals ) vals let encodi...
type value = [ ` Null | ` Bool of bool | ` Float of float | ` String of string | ` A of value list | ` O of ( string * value ) value list ]
type yaml = [ ` Scalar of scalar | ` Alias of string | ` A of sequence | ` O of mapping ] s_anchor : string option ; s_tag : string option ; s_implicit : bool ; s_members : yaml list ; } m_anchor : string option ; m_tag : string option ; m_implicit : bool ; m_members : ( yaml * yaml ) yaml list ; } anchor : string opti...
type version = [ ` V1_1 | ` V1_2 ] [ @@ deriving sexp ] sexp
type encoding = [ ` Any | ` Utf16be | ` Utf16le | ` Utf8 ] [ @@ deriving sexp ] sexp
type layout_style = [ ` Any | ` Block | ` Flow ] [ @@ deriving sexp ] sexp
module Stream = struct module Mark = struct type t = Yaml . Stream . Mark . t = { index : int ; line : int ; column : int } [ @@ deriving sexp ] sexp end module Event = struct type pos = Yaml . Stream . Event . pos = { start_mark : Mark . t ; end_mark : Mark . t ; } [ @@ deriving sexp ] sexp type t = Yaml . Stream . Ev...
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 then Stream . iter ( write_...
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 ( Bi_io . string...
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 " ; " - std " , Arg . Set std , " Convert tuples...
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 in if success then exit 0 else exit 1
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 Sys . file_exists pkh_filename...
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 ] . " @ active_bakers_only_opt_name ; Format . printf " ...
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 unknonw_options = List . filter ( fun opt -> op...
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_key . encoding sk_b in let s...
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 " ) ; ( " foundation3 " , " tz3RB4aoyjov4KEVRb...
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_timestamp 10000L in let fitness = ...
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_protocol_011_PtHangz2...
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 " BLockGenesisGenesisGenesisGenesisGenesisf79b5d1Co...
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 ; exit 1
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 . Ym . ( lt ( make_exn ~ year : 2000 ~ month : 1 ) ( make_ex...
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 |> CCResult . get_exn in Timedesc . Ym . equal ...
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 ) -> ( Some s , Bi_io . hash_name s , biniou_of_json 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 " | ` Int64 _ -> failwith " Cannot convert int64 to JS...
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 ; field09 = 0xEFFFFFFFl ; field10 = 0xEBABA...
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 ' = Bytes . sub_string buffer 0...
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 b2 . xmin in let i_xmax = Float . min b1 . xmax b2 . xmax in let i_ymin = Float . m...
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 ; 0 . 7 ; 0 . 3 ] | ; [ | 0 . 3 ; 0 . 7 ; 0 . 0 ] | ; [ | 0 . 3 ; 0 . 0 ; 0 . 7 ] | ; [ | 0 . 0 ; 0 . 3 ; 0 . 7 ] | ] |
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 confidence = predictions . ( 4 ) in if ...
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 . parse_config config_filename in let model = Darknet . build_mod...
type ( ' a , ' b ) ' b exec = ( ' a , unit , string , ' b ) ' b format4 -> ' a