package pyml

  1. Overview
  2. Docs

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.

val 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.

val 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.