text
stringlengths
0
601k
module M8 = struct type r1 = { x : int ; y : string } type r2 = { a : int ; b : string ; c : char } type _ repr = R1 : r1 repr | R2 : r2 repr let f ( type a ) ( r1 : a repr ) ( r2 : a repr ) ( a : a ) = match r1 , r2 , a with | R1 , _ , { x = 3 ; y = " " } -> ( ) | _ , R2 , { a = 1 ; b = " coucou " ; c = ' a ' } -> ( )...
module M9 = struct type _ repr = R1 : ( int * string ) repr | R2 : int repr let f ( type a ) ( r1 : a repr ) ( r2 : a repr ) ( a : a ) = match r1 , r2 , a with | R1 , _ , ( 3 , " " ) -> ( ) | _ , R2 , 1 -> ( ) end
module M10 = struct type r = { x : int ; y : string } type _ repr = R1 : r repr | R2 : int repr let f ( type a ) ( r1 : a repr ) ( r2 : a repr ) ( a : a ) = match r1 , r2 , a with | R1 , _ , { x = 3 ; y = " " } -> ( ) | _ , R2 , 1 -> ( ) end
module M11 = struct type _ repr = R1 : int lazy_t repr | R2 : int repr let f ( type a ) ( r1 : a repr ) ( r2 : a repr ) ( a : a ) = match r1 , r2 , a with | R1 , _ , lazy 1 -> ( ) | _ , R2 , 1 -> ( ) end
module M12 = struct type _ repr = R1 : unit repr | R2 : string repr let f ( type a ) ( r1 : a repr ) ( r2 : a repr ) ( a : a ) = match r1 , r2 , a with | R1 , _ , ( ) -> ( ) | _ , R2 , " coucou " -> ( ) | _ , R2 , " foo " -> ( ) end
module WriteBatch = struct module C = CreateConstructors_ ( CreateConstructors_struct let name = " writebatch " end ) end include C let clear = foreign " rocksdb_writebatch_clear " ( t @-> returning void ) void let count = foreign " rocksdb_writebatch_count " ( t @-> returning int ) int let put_raw = foreign " rocksdb_...
let returning_error typ = ptr string_opt @-> returning typ
let with_err_pointer f = let err_pointer = allocate string_opt None in let res = f err_pointer in match !@ err_pointer with | None -> res | Some err -> failwith err
module rec Iterator : Rocks_intf . ITERATOR with type db := RocksDb . t = struct module ReadOptions = Rocks_options . ReadOptions type nonrec t = t let t = t type db let db = t let get_pointer = get_pointer exception InvalidIterator let create_no_gc = foreign " rocksdb_create_iterator " ( db @-> ReadOptions . t @-> ret...
type error = [ ` Msg of string ]
let msg s = Error ( ` Msg s )
type db = { config : Options . config ; db : Rocksdb . db ; }
module Desc = struct let kind = " rocksdb_db " type t = db end
let close_db t = match unwrap t ( fun { db ; _ } -> Ok ( Rocksdb . close db ) ) with | Ok ( ) -> t . valid <- false ; Ok ( ) | Error _ -> msg " trying to close a database handle already closed "
let with_error_buffer fn = let errb = allocate string_opt None in let result = fn errb in match !@ errb with | None -> Ok result | Some err -> msg err
let open_db ~ config ~ name = let options = Options . of_config config in match with_error_buffer @@ Rocksdb . open_ options name with | Ok db -> let t = wrap { db ; config ; } in Gc . finalise ( fun t -> on_finalise t ( fun { db ; _ } -> Rocksdb . close db ) ) t ; Ok t | Error e -> Error e
let open_db_read_only ? fail_on_wal ( : fail = false ) ~ config ~ name = let options = Options . of_config config in match with_error_buffer @@ Rocksdb . open_read_only options name fail with | Ok db -> let t = wrap { db ; config ; } in Gc . finalise ( fun t -> on_finalise t ( fun { db ; _ } -> Rocksdb . close db ) ) t...
let open_db_with_ttl ~ config ~ name ~ ttl = let options = Options . of_config config in match with_error_buffer @@ Rocksdb . open_with_ttl options name ttl with | Ok db -> let t = wrap { db ; config ; } in Gc . finalise ( fun t -> on_finalise t ( fun { db ; _ } -> Rocksdb . close db ) ) t ; Ok t | Error err -> Error e...
let put db write_options ~ key ~ value = let key_len = String . length key in let value_len = String . length value in unwrap db @@ fun { db ; _ } -> Rocksdb . put db write_options ( ocaml_string_start key ) key_len ( ocaml_string_start value ) value_len |> with_error_buffer
let delete db write_options key = let key_len = String . length key in unwrap db @@ fun { db ; _ } -> Rocksdb . delete db write_options ( ocaml_string_start key ) key_len |> with_error_buffer
let get db read_options key = let key_len = String . length key in let result_len = allocate Ffi . V . int_to_size_t 0 in let result = unwrap db @@ fun { db ; _ } -> with_error_buffer @@ Rocksdb . get db read_options ( ocaml_string_start key ) key_len result_len in match result with | Error err -> Error err | Ok result...
let flush db flush_options = unwrap db @@ fun { db ; _ } -> Rocksdb . flush db flush_options |> with_error_buffer
let compact_now db = unwrap db @@ fun { db ; _ } -> Ok ( Rocksdb . compact_range db None 0 None 0 )
let stats db = unwrap db @@ fun { db ; _ } -> match Rocksdb . property_value db " rocksdb . stats " with | None -> Ok None | Some stats -> let string = coerce ( ptr char ) string stats in Gc . finalise ( fun stats -> Rocksdb . free ( to_voidp stats ) ) stats ; Ok ( Some string )
let get_cache_usage db = unwrap db @@ fun { config ; _ } -> match config . block_cache with | Some cache -> Ok ( Options . Cache . LRU . get_usage cache ) | None -> msg " get_cache_usage : no cache was set for this database "
module Batch = struct open Rocksdb type batch = Batch . t let create ( ) = let t = Batch . create ( ) in Gc . finalise Batch . destroy t ; t let count = Batch . count let clear = Batch . clear let put batch ~ key ~ value = let key_len = String . length key in let value_len = String . length value in Batch . put batch (...
module Iterator = struct open Rocksdb type iterator = Iterator . t let create db read_options = unwrap db @@ fun { db ; _ } -> let t = Iterator . create db read_options in Gc . finalise Iterator . destroy t ; Ok t let seek t key = let len = String . length key in Iterator . seek t ( ocaml_string_start key ) len let nex...
module Perf_context = struct type perf_context = Ffi . PerfContext . t type counter = Ffi . PerfContext . Counters . t module Counters = Ffi . PerfContext . Counters let create ( ) = let t = Ffi . PerfContext . create ( ) in Gc . finalise Ffi . PerfContext . destroy t ; t let reset = Ffi . PerfContext . reset let metri...
module M ( F : Cstubs . FOREIGN ) = struct module V = Views open V let foreign = F . foreign module C = struct include Ctypes let ( ) @-> = F . ( ) @-> let returning = F . returning end type t = unit C . ptr module Options = struct type options = unit C . ptr let options : options C . typ = C . ptr C . void module Filt...
module Filter_policy = struct type t = FilterPolicy . t let create_bloom ~ bits_per_key = FilterPolicy . create_bloom bits_per_key let create_bloom_full ~ bits_per_key = FilterPolicy . create_bloom_full bits_per_key end
module Cache = struct type t = Cache . t module LRU = struct let create ~ size = Cache . create size let get_usage t = Cache . get_usage t end end
module Tables = struct open Tables type format = Block_based of BlockBased . t module Block_based = struct let create ~ block_size = let t = BlockBased . create ( ) in BlockBased . set_block_size t block_size ; Gc . finalise BlockBased . destroy t ; Block_based t let set_filter_policy t filter_policy = BlockBased . set...
let create ( ) = let t = create ( ) in Gc . finalise destroy t ; t
type config = { parallelism_level : int option ; base_compression : [ ` Bz2 | ` Lz4 | ` Lz4hc | ` No_compression | ` Snappy | ` Zlib ] ; compression_by_level : [ ` Bz2 | ` Lz4 | ` Lz4hc | ` No_compression | ` Snappy | ` Zlib ] list ; optimize_filters_for_hits : bool option ; disable_compaction : bool ; max_flush_proces...
let of_config { parallelism_level ; base_compression ; compression_by_level ; optimize_filters_for_hits ; disable_compaction ; max_flush_processes ; compaction_trigger ; slowdown_writes_trigger ; stop_writes_trigger ; memtable_representation ; num_levels ; target_base_file_size ; max_bytes_for_level_base ; max_bytes_fo...
let default = { parallelism_level = None ; base_compression = ` No_compression ; compression_by_level = [ ] ; optimize_filters_for_hits = None ; disable_compaction = false ; max_flush_processes = None ; compaction_trigger = None ; slowdown_writes_trigger = None ; stop_writes_trigger = None ; memtable_representation = N...
module Write_options = struct open Ffi . Rocksdb type t = Write_options . t let create ? disable_wal ? sync ( ) = let open Misc . Opt in let t = Write_options . create ( ) in disable_wal >>= Write_options . disable_WAL t ; sync >>= Write_options . set_sync t ; Gc . finalise Write_options . destroy t ; t end
module Flush_options = struct open Ffi . Rocksdb type t = Flush_options . t let create ? wait ( ) = let open Misc . Opt in let t = Flush_options . create ( ) in wait >>= Flush_options . wait t ; Gc . finalise Flush_options . destroy t ; t end
module Read_options = struct open Ffi . Rocksdb type t = Read_options . t let create ? verify_checksums ? fill_cache ? tailing ( ) = let open Misc . Opt in let t = Read_options . create ( ) in verify_checksums >>= Read_options . set_verify_checksums t ; fill_cache >>= Read_options . set_fill_cache t ; tailing >>= Read_...
module Struct_stubs ( S : Ctypes . TYPE ) = struct open S let user_key_comparison_count = constant " rocksdb_user_key_comparison_count " int64_t let block_cache_hit_count = constant " rocksdb_block_cache_hit_count " int64_t let block_read_count = constant " rocksdb_block_read_count " int64_t let block_read_byte = const...
module Views = struct open Unsigned let bool_to_int = view ~ read ( : fun i -> i <> 0 ) 0 ~ write ( : function true -> 1 | false -> 0 ) 0 int let bool_to_uchar = view ~ read ( : fun u -> u <> UChar . zero ) zero ~ write ( : function true -> UChar . one | false -> UChar . zero ) zero uchar let int_to_size_t = view ~ rea...
let free = foreign " free " ( ptr void @-> returning void ) void
module type RocksType = sig val name : string val constructor : string val destructor : string val setter_prefix : string end
module type RocksType ' = sig val name : string end
type t = { ptr : unit ptr ; mutable valid : bool ; }
let get_pointer t = t . ptr
let t : t typ = view ~ read ( : fun ptr -> { ptr ; valid = true ; } ) ~ write ( : fun { ptr ; valid ; } -> if valid then ptr else raise OperationOnInvalidObject ) OperationOnInvalidObject ( ptr void ) void
let make_destroy t destructor = let inner = foreign destructor ( t @-> returning void ) void in fun t -> inner t ; t . valid <- false
let finalize f finalizer = match f ( ) with | a -> finalizer ( ) ; a | exception exn -> finalizer ( ) ; raise exn
module type S = sig type t val t : t Ctypes . typ val get_pointer : t -> unit Ctypes . ptr val type_name : string val create : unit -> t val create_no_gc : unit -> t val destroy : t -> unit val with_t : ( t -> ' a ) ' a -> ' a val create_setter : string -> ' a Ctypes . typ -> t -> ' a -> unit end
module CreateConstructors ( CreateConstructorsT : RocksType ) RocksType = struct type nonrec t = t let t = t let get_pointer = get_pointer let type_name = T . name let create_no_gc = foreign T . constructor ( void @-> returning t ) t let destroy = make_destroy t T . destructor let create ( ) = let t = create_no_gc ( ) ...
module CreateConstructors_ ( CreateConstructors_T : RocksType ' ) RocksType ' = struct include CreateConstructors ( CreateConstructorsstruct let name = T . name let constructor = " rocksdb_ " ^ T . name ^ " _create " let destructor = " rocksdb_ " ^ T . name ^ " _destroy " let setter_prefix = " rocksdb_ " ^ T . name ^ "...
type bigarray = ( char , Bigarray . int8_unsigned_elt , Bigarray . c_layout ) c_layout Bigarray . Array1 . t
module type ITERATOR = sig module ReadOptions : module type of ReadOptions exception InvalidIterator type db type t val get_pointer : t -> unit Ctypes . ptr val create : ? opts : ReadOptions . t -> db -> t val with_t : ? opts : ReadOptions . t -> db -> f ( : t -> ' a ) ' a -> ' a val is_valid : t -> bool val seek_to_fi...
module type TRANSACTION = sig type t type db type iter module ReadOptions : module type of ReadOptions module WriteOptions : module type of WriteOptions module TransactionOptions : module type of TransactionOptions module Snapshot : module type of Snapshot val txnbegin : ? wopts : WriteOptions . t -> ? txnopts : Transa...
module type ROCKS = sig module Options : module type of Options module ReadOptions : module type of ReadOptions module WriteOptions : module type of WriteOptions module FlushOptions : module type of FlushOptions module Cache : module type of Cache module BlockBasedTableOptions : module type of BlockBasedTableOptions mo...
module Cache = struct type nonrec t = t let t = t let get_pointer = get_pointer let create_no_gc = foreign " rocksdb_cache_create_lru " ( Views . int_to_size_t @-> returning t ) t let destroy = make_destroy t " rocksdb_cache_destroy " let create capacity = let t = create_no_gc capacity in Gc . finalise destroy t ; t le...
module Snapshot = struct type nonrec t = t let t = t end
module BlockBasedTableOptions = struct include CreateConstructors ( CreateConstructorsstruct let name = " block_based_table_options " let constructor = " rocksdb_block_based_options_create " let destructor = " rocksdb_block_based_options_destroy " let setter_prefix = " rocksdb_block_based_options_ " end ) end let set_b...
module Options = struct module C = CreateConstructors_ ( CreateConstructors_struct let name = " options " end ) end include C let increase_parallelism = create_setter " increase_parallelism " int let optimize_for_point_lookup = create_setter " optimize_for_point_lookup " Views . int_to_uint64_t let optimize_level_style...
module WriteOptions = struct module C = CreateConstructors_ ( CreateConstructors_struct let name = " writeoptions " end ) end include C let set_disable_WAL = create_setter " disable_WAL " Views . bool_to_int let set_sync = create_setter " set_sync " Views . bool_to_uchar end
module ReadOptions = struct module C = CreateConstructors_ ( CreateConstructors_struct let name = " readoptions " end ) end include C let set_snapshot = create_setter " set_snapshot " Snapshot . t end
module FlushOptions = struct module C = CreateConstructors_ ( CreateConstructors_struct let name = " flushoptions " end ) end include C let set_wait = create_setter " set_wait " Views . bool_to_uchar end
module TransactionOptions = struct module C = CreateConstructors_ ( CreateConstructors_struct let name = " transaction_options " end ) end include C let set_set_snapshot = create_setter " set_set_snapshot " Views . bool_to_uchar end
module TransactionDbOptions = struct module C = CreateConstructors_ ( CreateConstructors_struct let name = " transactiondb_options " end ) end include C end
module Frame_stack : sig type t val create : num_procs : int -> num_stack : int -> t val update : t -> ? masks : Tensor . t -> Tensor . t -> Tensor . t type t = { data : Tensor . t ; num_procs : int ; num_stack : int } let create ~ num_procs ~ num_stack = { data = Tensor . zeros [ num_procs ; num_stack ; 84 ; 84 ] ~ ki...
type actor_critic = { actor : Tensor . t ; critic : Tensor . t }
type totals = { rewards : float ; episodes : float }
type rollout = { states : Tensor . t ; returns : Tensor . t ; actions : Tensor . t ; values : Tensor . t }
type t = { envs : E . t ; num_steps : int ; num_procs : int ; frame_stack : Frame_stack . t ; s_states : Tensor . t ; sum_rewards : Tensor . t ; mutable total_rewards : float ; mutable total_episodes : float }
let create ~ atari_game ~ num_steps ~ num_stack ~ num_procs = let frame_stack = Frame_stack . create ~ num_procs ~ num_stack in let envs = E . create atari_game ~ num_processes : num_procs in let obs = E . reset envs in Tensor . print_shape obs ~ name " : obs " ; ignore ( Frame_stack . update frame_stack obs : Tensor ....
let set tensor i src = Tensor . copy_ ( Tensor . get tensor i ) ~ src
let action_space t = E . action_space t . envs
let run t ~ model = set t . s_states 0 ( Tensor . get t . s_states ( - 1 ) ) ; let s_values = Tensor . zeros [ t . num_steps ; t . num_procs ] in let s_rewards = Tensor . zeros [ t . num_steps ; t . num_procs ] in let s_actions = Tensor . zeros [ t . num_steps ; t . num_procs ] ~ kind ( : T Int64 ) in let s_masks = Ten...
let get_and_reset_totals t = let res = { rewards = t . total_rewards ; episodes = t . total_episodes } in t . total_rewards <- 0 . ; t . total_episodes <- 0 . ; res
let succ i = Int32 . succ i
let random sequence ~ bound = Seed_repr . take_int32 sequence bound
let rpc_arg = RPC_arg . like RPC_arg . int32 " roll "
let to_int32 v = v
module Index = struct type t = roll let path_length = 1 let to_path roll l = Int32 . to_string roll :: l let of_path = function s :: _ -> Int32 . of_string_opt s | _ -> None let rpc_arg = rpc_arg let encoding = encoding let compare = compare end
let encoding = Data_encoding . ( with_decoding_guard ( fun t -> if t >= 0l then Ok ( ) else Error " Positive int32 required " ) int32 )
let succ i = Int32 . succ i
let random sequence ~ bound = Seed_repr . take_int32 sequence bound
let rpc_arg = RPC_arg . like RPC_arg . uint31 " roll "
let to_int32 v = v
module Index = struct type t = roll let path_length = 1 let to_path roll l = Int32 . to_string roll :: l let of_path = function s :: _ -> Int32 . of_string_opt s | _ -> None let rpc_arg = rpc_arg let encoding = encoding let compare = compare end
module Die = struct type t = { num_faces : int } [ @@ deriving bin_io , compare , equal , sexp ] let of_int num_faces = { num_faces } let to_string_hum { num_faces } = " d " ^ Int . to_string num_faces let roll ( ? random_state = Random . State . default ) { num_faces } = { Roll_result . Die . num_faces ; result = Rand...
type t = | Const of int | Prim of { count : int ; die : Die . t } | Add of t list
let add ts = match ts with | [ ] -> Const 0 | [ t ] -> t | _ :: _ :: _ as ts -> Add ts ; ;
let of_dice_and_const dice const = add ( ( if const <> 0 then [ Const const ] else [ ] ) @ List . filter_map dice ~ f ( : fun ( count , die ) -> if count > 0 then Some ( Prim { count ; die } ) else None ) ) ; ;
let rec to_string_hum t = match t with | Const n -> Int . to_string n | Prim { count ; die } -> ( if count = 1 then " " else Int . to_string count ) ^ Die . to_string_hum die | Add ts -> String . concat ~ sep " : + " ( List . map ts ~ f : to_string_hum ) ; ;
let parser = let open Angstrom in let ws = skip_while Char . is_whitespace in let one = lift2 ( fun count die -> Prim { count ; die } ) ( take_while Char . is_digit >>| function | " " -> 1 | s -> Int . of_string s ) Die . parser in one |> sep_by1 ( ws *> char ' ' + *> ws ) >>| add <?> " Dice_set . Spec " ; ;
let of_string string = Angstrom . ( parse_string ~ consume : All parser ) string |> Result . map_error ~ f ( : Error . of_string >> Error . tag ~ tag " : Roll_spec . of_string " ) |> ok_exn ; ;
let rec roll ( ? random_state = Random . State . default ) t = match t with | Const n -> { Roll_result . dice = [ ] ; const = n } | Prim { count ; die } -> { Roll_result . dice = List . init count ~ f ( : fun _ -> Die . roll die ~ random_state ) ; const = 0 } | Add ts -> List . fold ts ~ init { : Roll_result . dice = [...
type error += | Consume_roll_change | No_roll_for_delegate | No_roll_snapshot_for_cycle of Cycle_repr . t | Unregistered_delegate of Signature . Public_key_hash . t
let ( ) = let open Data_encoding in register_error_kind ` Permanent ~ id " : contract . manager . consume_roll_change " ~ title " : Consume roll change " ~ description " : Change is not enough to consume a roll . " ~ pp ( : fun ppf ( ) -> Format . fprintf ppf " Not enough change to consume a roll . " ) empty ( function...
let get_contract_delegate ctxt contract = Storage . Contract . Delegate . find ctxt contract
let delegate_pubkey ctxt delegate = Storage . Contract . Manager . find ctxt ( Contract_repr . implicit_contract delegate ) >>=? function | None | Some ( Manager_repr . Hash _ ) -> fail ( Unregistered_delegate delegate ) | Some ( Manager_repr . Public_key pk ) -> return pk
let clear_cycle ctxt cycle = Storage . Roll . Snapshot_for_cycle . get ctxt cycle >>=? fun index -> Storage . Roll . Snapshot_for_cycle . remove_existing ctxt cycle >>=? fun ctxt -> Storage . Roll . Last_for_snapshot . remove_existing ( ctxt , cycle ) index >>=? fun ctxt -> Storage . Roll . Owner . delete_snapshot ctxt...
let fold ctxt ~ f init = Storage . Roll . Next . get ctxt >>=? fun last -> let [ @ coq_struct " roll " ] rec loop ctxt roll acc = if Roll_repr . ( roll = last ) then return acc else Storage . Roll . Owner . find ctxt roll >>=? function | None -> loop ctxt ( Roll_repr . succ roll ) acc | Some delegate -> f roll delegate...