package np

  1. Overview
  2. Docs
Fundamental scientific computing with Numpy for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

sklearn-v0.3.1.tbz
sha256=48809d88893a3f17d79f8e5acbd28126de919b8ced6d1f6856a61fd6bfae571d
sha512=9e1d01c42aed436163b1ce50bee141f40cb5bc943d5dd16d6eb21f1b53d613933533c70f28675e418a550cf44e0cd66d47496e462132769b05dec64bf3db560c

doc/src/np/PyList.ml.html

Source file PyList.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
44
module type ELEMENT = sig
  type t
  val of_pyobject : Py.Object.t -> t
  val to_pyobject : t -> Py.Object.t
end

module type S = sig
  type t
  type elt

  val of_pyobject : Py.Object.t -> t
  val to_pyobject : t -> Py.Object.t

  val create : unit -> t
  val of_list : elt list -> t

  val of_list_map : ('a -> elt) -> 'a list -> t

  val append : t -> elt -> unit

  val show : t -> string
  val pp : Format.formatter -> t -> unit
end

module Make(X : ELEMENT) = struct
  type t = Py.Object.t

  let of_pyobject x = x
  let to_pyobject x = x

  let create () = Py.List.create 0
  
  let of_list : X.t list -> t = fun l ->
    Py.List.of_list_map X.to_pyobject l

  let of_list_map : ('a -> X.t) -> 'a list -> t = fun f l ->
    Py.List.of_list_map (fun e -> X.to_pyobject @@ f e) l
    
  let append : t -> X.t -> unit = fun l x ->
    let _ = Py.Object.call_method l "append" [| X.to_pyobject x |] in ()

  let show x = Py.Object.to_string x
  let pp fmt x = Format.fprintf fmt "%s" (show x)
end
OCaml

Innovation. Community. Security.