package pyml

  1. Overview
  2. Docs
OCaml bindings for Python

Install

Dune Dependency

Authors

Maintainers

Sources

pyml.20231101.tar.gz
sha512=711cbb8fb14317a04780c4d27edc1897d8a5dd783edfd471fe16b8edfd0820f876507383526fe3b57c0046575982735504ca101ab26d96ad13363f14a2469fa1

doc/pyml/Numpy/index.html

Module NumpySource

OCaml Interface for Numpy.

Arrays are passed in place (without copy): Python and OCaml programs can change the contents of the array and the changes are visible in the other language.

The following table gives the correspondence between bigarray kinds and Numpy element types.

  • float32 / NPY_FLOAT
  • float64 / NPY_DOUBLE
  • int8_signed / NPY_BYTE
  • int8_unsigned / NPY_UBYTE
  • int16_signed / NPY_SHORT
  • int16_unsigned / NPY_USHORT
  • int32 / NPY_INT
  • int64 / NPY_LONGLONG
  • nativeint / NPY_LONG
  • complex32 / NPY_CFLOAT
  • complex64 / NPY_CDOUBLE
  • char / NPY_CHAR

Other kinds/element types are not supported. In particular, OCaml integer kind, int, has no equivalent type in Numpy.

Sourceval of_bigarray : ('a, 'b, 'c) Bigarray.Genarray.t -> Py.Object.t

of_bigarray a returns a Numpy array that shares the same contents than the OCaml array a.

Sourceval to_bigarray : ('a, 'b) Bigarray.kind -> 'c Bigarray.layout -> Py.Object.t -> ('a, 'b, 'c) Bigarray.Genarray.t

to_bigarray kind layout a returns a bigarray that shares the same contents than the Numpy array a. If `kind` and/or `layout` are unknown, you may use to_bigarray_k.

Sourcetype ('a, 'b, 'c) to_bigarray = {
  1. kind : ('a, 'b) Bigarray.kind;
  2. layout : 'c Bigarray.layout;
  3. array : ('a, 'b, 'c) Bigarray.Genarray.t;
}
Sourcetype 'r to_bigarray_k = {
  1. f : 'a 'b 'c. ('a, 'b, 'c) to_bigarray -> 'r;
}
Sourceval to_bigarray_k : 'r to_bigarray_k -> Py.Object.t -> 'r

to_bigarray_k k a calls k.f with the contents of the Numpy array a. k.f has to be polymorphic in the kind and the layout of the bigarray: functions compare_kind, compare_layout and check_kind_and_layout can be used to introspect the bigarray polymorphically.

Sourceval compare_kind : ('a, 'b) Bigarray.kind -> ('c, 'd) Bigarray.kind -> int

compare_kind provides a total order on Bigarray.kind. As opposed to generic compare of OCaml standard libary, compare_kind is polymorphic in the kind of the bigarray.

Sourceval compare_layout : 'a Bigarray.layout -> 'b Bigarray.layout -> int

compare_layout provides a total order on Bigarray.layout. As opposed to generic compare of OCaml standard libary, compare_kind is polymorphic in the layout of the bigarray.

Sourceval check_kind_and_layout : ('a, 'b) Bigarray.kind -> 'c Bigarray.layout -> ('d, 'e, 'f) Bigarray.Genarray.t -> ('a, 'b, 'c) Bigarray.Genarray.t option

check_kind_and_layout kind layout a returns Some a if a has the given kind and layout (that is to say, if we have the following type equalities, 'a = 'd, 'b = 'e and 'c = 'f). This function allows the callback of to_bigarray_k to be polymorphic in the kind of the array.

OCaml

Innovation. Community. Security.