text
stringlengths
0
601k
let gauss a b x = let xb = Vec . sub x b in . ~- ( exp ( dot xb ( symv a xb ) . / 2 . 0 ) )
let dgauss a b x = symv ~ alpha ( : gauss a b x ) a ( Vec . sub x b )
let gnuplot f = let oc = Unix . open_process_out " gnuplot " in let ppf = formatter_of_out_channel oc in f ppf ; pp_print_flush ppf ( ) ; print_endline " Press Enter to exit gnuplot " ; ignore ( read_line ( ) ) ; ignore ( Unix . close_process_out oc )
let splot_fun ( ? option = " " ) ( ? n = 10 ) ( ? x1 = - 10 . 0 ) ( ? x2 = 10 . 0 ) ( ? y1 = - 10 . 0 ) ( ? y2 = 10 . 0 ) ppf f = let cx = ( x2 . - x1 ) . / float n in let cy = ( y2 . - y1 ) . / float n in fprintf ppf " splot ' ' - % s @\ n " option ; for i = 0 to n do for j = 0 to n do let x = cx . * float i . + x1 in...
let steepest_descent ppf ~ loops ~ eta df f x = fprintf ppf " splot ' ' - with linespoints linetype 2 title ' ' @\ n \ % a 0 @\ n " pp_rfvec x ; for i = 1 to loops do axpy ~ alpha ( . :~- eta ) ( df x ) x ; fprintf ppf " % a 0 @\ n " pp_rfvec x done ; fprintf ppf " end @\ n "
let ( ) = let a = [ % mat [ - 0 . 1 , 0 . 1 ; 0 . 1 , - 0 . 2 ] ] in let b = [ % vec [ 1 . 0 ; 3 . 0 ] ] in let ( x1 , x2 , y1 , y2 ) = ( - 2 . 0 , 3 . 0 , 0 . 0 , 5 . 0 ) in gnuplot ( fun ppf -> fprintf ppf " set multiplot @\ n \ set view 0 , 0 # Fix a view @\ n \ unset ztics # Don ' t show ztics @\ n \ unset clabel #...
module type core = sig type t val t : t Ctypes . typ val ctype : t Ctypes . typ val null : t val ctype_opt : t option Ctypes . typ val pp : Format . formatter -> t -> unit val array : t list -> t Ctypes . CArray . t val array_opt : t list -> t option Ctypes . CArray . t end
module type S = sig include core val to_ptr : t -> nativeint val unsafe_from_ptr : nativeint -> t end
module type S_non_dispatchable = sig include core val to_int64 : t -> int64 val unsafe_from_int64 : int64 -> t end
module Make ( ) : S = struct type self type t = self Ctypes . structure Ctypes . ptr let t : t Ctypes . typ = Ctypes . ptr ( Ctypes . structure " " ) let ctype = t let null = Ctypes . ( coerce @@ ptr void ) t Ctypes . null let ctype_opt = let read v = if v = null then None else Some v in let write = function | None -> ...
module Make_non_dispatchable ( ) : S_non_dispatchable = struct type self type t = int64 let t : t Ctypes . typ = Ctypes . int64_t let ctype = t let null = 0L let ctype_opt = let read v = if v = null then None else Some v in let write = function | None -> null | Some x -> x in Ctypes . view ~ read ~ write t let pp ppf (...
module type intlike = sig type t val zero : t val ctype : t Ctypes . typ end
let integer_opt ( type a ) ( module I : intlike with type t = a ) = let read x = if x = I . zero then None else Some x in let write = function None -> I . zero | Some x -> x in Ctypes . view ~ read ~ write I . ctype
let integer_opt ' zero ctype = let read x = if x = zero then None else Some x in let write = function None -> zero | Some x -> x in Ctypes . view ~ read ~ write ctype
let uint_32_t = Ctypes . view ~ read ( : U32 . to_int ) ~ write ( : U32 . of_int ) Ctypes . uint32_t
let uint_16_t = Ctypes . view ~ read ( : U16 . to_int ) ~ write ( : U16 . of_int ) Ctypes . uint16_t
module Int = struct type t = int let zero = 0 let pp = Format . pp_print_int let ctype = Ctypes . int end
module Uint_8_t = struct open U8 type t = U8 . t let ctype = Ctypes . uint8_t let zero = of_int 0 let of_int = of_int let to_int = to_int let to_string = to_string let pp ppf x = Format . pp_print_string ppf ( to_string x ) end
let bool_32 = let true ' = U32 . of_int Vk__Const . true ' and false ' = U32 . of_int Vk__Const . false ' in Ctypes . view ~ read ( : ( ) = true ' ) ~ write ( : fun x -> if x then true ' else false ' ) Ctypes . uint32_t
let bool_32_opt = let true ' = U32 . of_int Vk__Const . true ' and false ' = U32 . of_int Vk__Const . false ' in Ctypes . view ~ read ( : fun x -> if U32 . zero = x then None else if x = true ' then Some true else Some false ) ~ write ( : function None -> U32 . zero | Some x -> if x then true ' else false ' ) Ctypes . ...
module Size_t_0 = struct let of_int = S . of_int let to_int = S . to_int let zero = of_int 0 let to_string = S . to_string let pp ppf x = Format . fprintf ppf " % s " ( S . to_string x ) type t = S . t let ctype = Ctypes . size_t end
module Size_t = struct include Size_t_0 let ctype_opt = integer_opt ( module Size_t_0 ) end
let size_t_opt = integer_opt ( module Size_t )
module Uint_32_t_0 = struct let zero = 0 let of_int x = x let to_int x = x let to_string = string_of_int let pp ppf x = Format . fprintf ppf " % d " x type t = int let ctype = uint_32_t end
module Uint_32_t = struct include Uint_32_t_0 let ctype_opt = integer_opt ( module Uint_32_t_0 ) end
module Uint_16_t_0 = struct let zero = 0 let of_int x = x let to_int x = x let to_string = string_of_int let pp ppf x = Format . fprintf ppf " % d " x type t = int let ctype = uint_16_t end
module Uint_16_t = struct include Uint_16_t_0 let ctype_opt = integer_opt ( module Uint_16_t_0 ) end
module Bool_32 = struct type t = bool let t = bool let ctype = bool_32 let ctype_opt = bool_32_opt let zero = true let pp = Format . pp_print_bool end
module Int_32_t = struct let zero = 0 let of_int x = x let to_int x = x let to_string = string_of_int let pp ppf x = Format . fprintf ppf " % d " x type t = int let read = Int32 . to_int let write = Int32 . of_int let ctype = Ctypes . view ~ read ~ write Ctypes . int32_t let ctype_opt = integer_opt ' zero ctype end
module Int_64_t = struct let zero = 0 let of_int x = x let to_int x = x let to_string = string_of_int let pp ppf x = Format . fprintf ppf " % d " x type t = int let read = Int64 . to_int let write = Int64 . of_int let ctype = Ctypes . view ~ read ~ write Ctypes . int64_t let ctype_opt = integer_opt ' zero ctype end
module Uint_64_t = struct let of_int = U64 . of_int let to_int = U64 . to_int let zero = of_int 0 let to_string = U64 . to_string let pp ppf x = Format . fprintf ppf " % s " ( U64 . to_string x ) type t = U64 . t let ctype = Ctypes . uint64_t let ctype_opt = integer_opt ' zero ctype end
module type aliased = sig type t val zero : t val ctype : t Ctypes . typ val ctype_opt : t option Ctypes . typ val of_int : int -> t val to_int : t -> int val to_string : t -> string end
module type alias = sig type x type t = private x val make : x -> t val ctype : t Ctypes . typ val ctype_opt : t option Ctypes . typ val of_int : int -> t val zero : t val to_int : t -> int val pp : Format . formatter -> t -> unit end
module Alias ( X : aliased ) : alias with type x := X . t = struct type t = X . t let make x = x let zero = X . zero let ctype = X . ctype let ctype_opt = X . ctype_opt let of_int = X . of_int let to_int = X . to_int let pp ppf x = Format . fprintf ppf " % s " ( X . to_string x ) end
module Float = struct type t = float let pp = Format . pp_print_float let ctype = Ctypes . float end
module Double = struct type t = float let pp = Format . pp_print_float let ctype = Ctypes . double end
module Void = struct type t = void let ctype = Ctypes . void let pp = Vk__helpers . Pp . abstract end
module Cametallayer = struct type m type t = m Ctypes . structure let ctype : t Ctypes . typ = Ctypes . structure " CAmetallayer " let pp = Vk__helpers . Pp . abstract end
type cametallayer = Cametallayer . t Ctypes . structure
module type Config = sig val shift : int val char_of_digit : int -> char val digit_of_char : char -> int end
module type S = sig val encode : Buffer . t -> int -> unit val decode : char Stream . t -> int end
module Make ( C : Config ) = struct let vlq_base = 1 lsl C . shift let vlq_base_mask = vlq_base - 1 let vlq_continuation_bit = vlq_base let vlq_signed_of_int value = if value < 0 then ( ( - value ) lsl 1 ) + 1 else ( value lsl 1 ) + 0 let rec encode_vlq buf vlq = let digit = vlq land vlq_base_mask in let vlq = vlq lsr ...
module Base64 = Make ( struct let shift = 5 let base64 = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 " +/ let char_of_digit digit = if 0 <= digit && digit < String . length base64 then base64 . [ digit ] else failwith ( Printf . sprintf " Must be between 0 and 63 : % d " digit ) let digit_of_char c...
let code_rev = let a = Array . make 255 ( - 1 ) in for i = 0 to String . length code - 1 do a . ( Char . code code . [ i ] ) <- i done ; a
let vlq_base = 1 lsl vlq_base_shift
let vlq_base_mask = vlq_base - 1
let toVLQSigned v = if v < 0 then ( - v lsl 1 ) + 1 else v lsl 1
let fromVLQSigned v = let is_neg = v land 1 = 1 in let shift = v lsr 1 in if is_neg then - shift else shift
let add_char buf x = Buffer . add_char buf code . [ x ]
let rec encode ' buf x = let digit = x land vlq_base_mask in let rest = x lsr vlq_base_shift in if rest = 0 then add_char buf digit else ( add_char buf ( digit lor vlq_continuation_bit ) ; encode ' buf rest )
let encode b x = let vql = toVLQSigned x in encode ' b vql
let encode_l b l = List . iter ~ f ( : encode b ) l
let rec decode ' acc s start pos = let digit = code_rev . ( Char . code s . [ pos ] ) in if digit = - 1 then invalid_arg " Vql64 . decode ' " ; let cont = digit land vlq_continuation_bit = vlq_continuation_bit in let digit = digit land vlq_base_mask in let acc = acc + ( digit lsl ( ( pos - start ) * vlq_base_shift ) ) ...
let decode s p = let d , i = decode ' 0 s p p in fromVLQSigned d , i
let decode_l s ~ pos ~ len = let rec aux pos acc len = if len = 0 then List . rev acc else if len < 0 then invalid_arg " Vlq64 . decode_l " else let d , i = decode s pos in let len = len - ( i - pos ) in aux i ( d :: acc ) len in aux pos [ ] len
module Make ( V : HashCmp ) ( L : Lattice ) ( R : Result ) = struct type v = V . t * L . t type r = R . t type d = Leaf of r | Branch of V . t * L . t * t * t and t = { id : int ; d : d } let equal x y = x . id = y . id let rec to_string t = match t . d with | Leaf r -> R . to_string r | Branch ( v , l , t , f ) -> Pri...
let network = [ " host " ]
let download_cache = Obuilder_spec . Cache . v " opam - archives " ~ target " :/ home / opam . / opam / download - cache "
let dune_cache = Obuilder_spec . Cache . v " opam - dune - cache " ~ target " :/ home / opam . / cache / dune "
let cache = [ download_cache ; dune_cache ]
type t0 = { voodoo_do : Git . Commit_id . t ; voodoo_prep : Git . Commit_id . t ; voodoo_gen : Git . Commit_id . t ; }
module Op = struct type voodoo = t0 type t = No_context let id = " voodoo - repository " let pp f _ = Fmt . pf f " voodoo - repository " let auto_cancel = false module Key = struct type t = Git . Commit . t let digest = Git . Commit . hash end module Value = struct type t = voodoo let to_yojson commit = let hash = Git ...
module VoodooCache = Current_cache . Make ( Op )
let v ( ) = let daily = Current_cache . Schedule . v ~ valid_for ( : Duration . of_day 1 ) ( ) in let git = Git . clone ~ schedule : daily ~ gref " : main " " https :// github . com / ocaml - doc / voodoo . git " in let open Current . Syntax in Current . component " voodoo " |> let > git = git in VoodooCache . get No_c...
type t = { voodoo_do : Git . Commit_id . t ; voodoo_prep : Git . Commit_id . t ; voodoo_gen : Git . Commit_id . t ; config : Config . t ; }
let v config = let open Current . Syntax in let + { voodoo_do ; voodoo_prep ; voodoo_gen } = v ( ) in { voodoo_do ; voodoo_prep ; voodoo_gen ; config }
let remote_uri commit = let repo = Git . Commit_id . repo commit in let commit = Git . Commit_id . hash commit in repo ^ " " # ^ commit
let digest t = let key = Fmt . str " % s \ n % s \ n % s \ n % s \ n " ( Git . Commit_id . hash t . voodoo_prep ) ( Git . Commit_id . hash t . voodoo_do ) ( Git . Commit_id . hash t . voodoo_gen ) ( Config . odoc t . config ) in Digest . ( string key |> to_hex )
module Prep = struct type voodoo = t type t = Git . Commit_id . t let v { voodoo_prep ; _ } = voodoo_prep let spec ~ base t = let open Obuilder_spec in base |> Spec . add [ run ~ network " sudo apt - get update && sudo apt - get install - yy m4 pkg - config " ; run ~ network ~ cache " opam pin - ny % s && opam depext -...
module Do = struct type voodoo = t type t = { commit : Git . Commit_id . t ; config : Config . t } let v { voodoo_do ; config ; _ } = { commit = voodoo_do ; config } let spec ~ base t = let open Obuilder_spec in base |> Spec . add [ run ~ network " sudo apt - get update && sudo apt - get install - yy m4 " ; run ~ netwo...
module Gen = struct type voodoo = t type t = { commit : Git . Commit_id . t ; config : Config . t } let v { voodoo_gen ; config ; _ } = { commit = voodoo_gen ; config } let spec ~ base t = let open Obuilder_spec in base |> Spec . add [ run ~ network " sudo apt - get update && sudo apt - get install - yy m4 && opam repo...
type ballot = Yay | Nay | Pass
let ballot_encoding = let of_int8 = function | 0 -> Yay | 1 -> Nay | 2 -> Pass | _ -> invalid_arg " ballot_of_int8 " in let to_int8 = function | Yay -> 0 | Nay -> 1 | Pass -> 2 in let open Data_encoding in splitted ~ binary : ( conv to_int8 of_int8 int8 ) ~ json : ( string_enum [ " yay " , Yay ; " nay " , Nay ; " pass ...
let recorded_proposal_count_for_delegate ctxt proposer = Storage . Vote . Proposals_count . find ctxt proposer >|=? Option . value ~ default : 0
let record_proposal ctxt proposal proposer = recorded_proposal_count_for_delegate ctxt proposer >>=? fun count -> Storage . Vote . Proposals_count . add ctxt proposer ( count + 1 ) >>= fun ctxt -> Storage . Vote . Proposals . add ctxt ( proposal , proposer ) >|= ok
let get_proposals ctxt = Storage . Vote . Proposals . fold ctxt ~ order ` : Sorted ~ init ( : ok Protocol_hash . Map . empty ) ~ f ( : fun ( proposal , delegate ) acc -> Storage . Vote . Listings . get ctxt delegate >>=? fun weight -> Lwt . return ( acc >|? fun acc -> let previous = match Protocol_hash . Map . find pro...
let clear_proposals ctxt = Storage . Vote . Proposals_count . clear ctxt >>= fun ctxt -> Storage . Vote . Proposals . clear ctxt
type ballots = { yay : int64 ; nay : int64 ; pass : int64 }
let ballots_encoding = let open Data_encoding in conv ( fun { yay ; nay ; pass } -> ( yay , nay , pass ) ) ( fun ( yay , nay , pass ) -> { yay ; nay ; pass } ) @@ obj3 ( req " yay " int64 ) ( req " nay " int64 ) ( req " pass " int64 )
let get_ballots ctxt = Storage . Vote . Ballots . fold ctxt ~ order ` : Sorted ~ f ( : fun delegate ballot ( ballots : ballots tzresult ) -> Storage . Vote . Listings . get ctxt delegate >>=? fun weight -> let count = Int64 . add weight in Lwt . return ( ballots >|? fun ballots -> match ballot with | Yay -> { ballots w...
let listings_encoding = Data_encoding . ( list ( obj2 ( req " pkh " Signature . Public_key_hash . encoding ) ( req " voting_power " int64 ) ) )
let update_listings ctxt = Storage . Vote . Listings . clear ctxt >>= fun ctxt -> Stake_storage . fold ctxt ( ctxt , 0L ) ~ order ` : Sorted ~ f ( : fun ( delegate , stake ) ( ctxt , total ) -> let weight = Tez_repr . to_mutez stake in Storage . Vote . Listings . init ctxt delegate weight >>=? fun ctxt -> return ( ctxt...
let get_voting_power_free ctxt owner = Storage . Vote . Listings . find ctxt owner >|=? Option . value ~ default : 0L
let get_voting_power ctxt owner = let open Raw_context in consume_gas ctxt ( Storage_costs . read_access ~ path_length : 4 ~ read_bytes : 8 ) >>?= fun ctxt -> Storage . Vote . Listings . find ctxt owner >|=? function | None -> ( ctxt , 0L ) | Some power -> ( ctxt , power )
let get_total_voting_power ctxt = let open Raw_context in consume_gas ctxt ( Storage_costs . read_access ~ path_length : 2 ~ read_bytes : 8 ) >>?= fun ctxt -> get_total_voting_power_free ctxt >|=? fun total_voting_power -> ( ctxt , total_voting_power )
let get_current_quorum ctxt = Storage . Vote . Participation_ema . get ctxt >|=? fun participation_ema -> let quorum_min = Constants_storage . quorum_min ctxt in let quorum_max = Constants_storage . quorum_max ctxt in let quorum_diff = Int32 . sub quorum_max quorum_min in Int32 . ( add quorum_min ( div ( mul participat...
let init ctxt ~ start_position = let participation_ema = Constants_storage . quorum_max ctxt in Storage . Vote . Participation_ema . init ctxt participation_ema >>=? fun ctxt -> Voting_period_storage . init_first_period ctxt ~ start_position
let test_proto_files = [ " main . ml " ; " main . mli " ]
let test_proto_TEZOS_PROTOCOL = { { | " modules " : [ " Main " ] , " expected_env_version " : 3 } } |
type period = { index : int ; kind : string ; start_position : int ; position : int ; remaining : int ; }
let period_type : period Check . typ = Check . convert ( fun { index ; kind ; start_position ; position ; remaining } -> ( index , kind , start_position , position , remaining ) ) Check . ( tuple5 int string int int int )
let decode_period json = let index = JSON . ( json |-> " voting_period " |-> " index " |> as_int ) in let kind = JSON . ( json |-> " voting_period " |-> " kind " |> as_string ) in let start_position = JSON . ( json |-> " voting_period " |-> " start_position " |> as_int ) in let position = JSON . ( json |-> " position "...
let get_current_period client = let * json = RPC . Votes . get_current_period client in return ( decode_period json )
let get_successor_period client = let * json = RPC . Votes . get_successor_period client in return ( decode_period json )
let check_current_period client expected_period = let * period = get_current_period client in Check . ( ( period = expected_period ) period_type ) ~ error_msg " : expected current_period = % R , got % L " ; unit
let check_successor_period client expected_period = let * period = get_successor_period client in Check . ( ( period = expected_period ) period_type ) ~ error_msg " : expected successor_period = % R , got % L " ; unit
type level = { level : int ; level_position : int ; cycle : int ; cycle_position : int ; expected_commitment : bool ; }
let level_type : level Check . typ = Check . convert ( fun { level ; level_position ; cycle ; cycle_position ; expected_commitment } -> ( level , level_position , cycle , cycle_position , expected_commitment ) ) Check . ( tuple5 int int int int bool )
let decode_level json = let level = JSON . ( json |-> " level " |> as_int ) in let level_position = JSON . ( json |-> " level_position " |> as_int ) in let cycle = JSON . ( json |-> " cycle " |> as_int ) in let cycle_position = JSON . ( json |-> " cycle_position " |> as_int ) in let expected_commitment = JSON . ( json ...
let get_current_level client = let * json = RPC . get_current_level client in return ( decode_level json )