package fehu

  1. Overview
  2. Docs
Reinforcement learning for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

raven-1.0.0.alpha3.tbz
sha256=96d35ce03dfbebd2313657273e24c2e2d20f9e6c7825b8518b69bd1d6ed5870f
sha512=90c5053731d4108f37c19430e45456063e872b04b8a1bbad064c356e1b18e69222de8bfcf4ec14757e71f18164ec6e4630ba770dbcb1291665de5418827d1465

doc/src/fehu/info.ml.html

Source file info.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module String_map = Map.Make (String)

type t = Value.t String_map.t

let empty = String_map.empty
let is_empty = String_map.is_empty
let set key value info = String_map.add key value info
let find key info = String_map.find_opt key info

let find_exn key info =
  match String_map.find_opt key info with
  | Some v -> v
  | None -> invalid_arg (Printf.sprintf "Info.find_exn: key %S not present" key)

let remove key info = String_map.remove key info
let merge a b = String_map.union (fun _key _left right -> Some right) a b
let to_list info = String_map.bindings info

let of_list kvs =
  List.fold_left (fun acc (k, v) -> String_map.add k v acc) String_map.empty kvs

let to_value info = Value.Dict (String_map.bindings info)

let pp ppf t =
  let bindings = String_map.bindings t in
  Format.fprintf ppf "{";
  List.iteri
    (fun i (k, v) ->
      if i > 0 then Format.fprintf ppf "; ";
      Format.fprintf ppf "%s: %a" k Value.pp v)
    bindings;
  Format.fprintf ppf "}"

(* Convenience constructors *)

let null = Value.Null
let bool b = Value.Bool b
let int i = Value.Int i
let float f = Value.Float f
let string s = Value.String s
let int_array arr = Value.Int_array (Array.copy arr)
let float_array arr = Value.Float_array (Array.copy arr)
let bool_array arr = Value.Bool_array (Array.copy arr)