Module Ir.Ndarray

module Lazy = Utils.Lazy

N-dimensional arrays: a precision-handling wrapper for Bigarray.Genarray and its utilities.

val bfloat16_to_float : Base.int -> Base.float
val float_to_bfloat16 : Base.float -> Base.int
val fp8_to_float : Base.int -> Base.float
val float_to_fp8 : Base.float -> Base.int
val _get_local_debug_runtime : unit -> (module Minidebug_runtime.Debug_runtime)
module A = Stdlib.Bigarray.Genarray

*** Handling of precisions ***

type ('ocaml, 'elt_t) bigarray = ('ocaml, 'elt_t, Stdlib.Bigarray.c_layout) A.t
val bigarray_start_not_managed : ('ocaml, 'elt_t) bigarray -> Ctypes_ptr.voidp
val big_ptr_to_string : ('a, 'b) bigarray -> Base.String.t
val sexp_of_bigarray : ('a, 'b) bigarray -> Base.Sexp.t
type byte_nd = (Base.char, Ops.uint8_elt) bigarray
type uint16_nd = (Base.int, Ops.uint16_elt) bigarray
type int32_nd = (Base.int32, Ops.int32_elt) bigarray
type half_nd = (Base.float, Ops.float16_elt) bigarray
type bfloat16_nd = (Base.int, Ops.uint16_elt) bigarray
type fp8_nd = (Base.char, Ops.uint8_elt) bigarray
type single_nd = (Base.float, Ops.float32_elt) bigarray
type double_nd = (Base.float, Ops.float64_elt) bigarray
val sexp_of_byte_nd : byte_nd -> Base.Sexp.t
val sexp_of_uint16_nd : uint16_nd -> Base.Sexp.t
val sexp_of_int32_nd : int32_nd -> Base.Sexp.t
val sexp_of_half_nd : half_nd -> Base.Sexp.t
val sexp_of_bfloat16_nd : bfloat16_nd -> Base.Sexp.t
val sexp_of_fp8_nd : fp8_nd -> Base.Sexp.t
val sexp_of_single_nd : single_nd -> Base.Sexp.t
val sexp_of_double_nd : double_nd -> Base.Sexp.t
type t =
  1. | Byte_nd of byte_nd
  2. | Uint16_nd of uint16_nd
  3. | Int32_nd of int32_nd
  4. | Half_nd of half_nd
  5. | Bfloat16_nd of bfloat16_nd
  6. | Fp8_nd of fp8_nd
  7. | Single_nd of single_nd
  8. | Double_nd of double_nd
val sexp_of_t : t -> Sexplib0.Sexp.t
val as_array : ('ocaml, 'elt_t) Ops.precision -> ('ocaml, 'elt_t) bigarray -> t
val precision_to_bigarray_kind : ('ocaml, 'elt_t) Ops.precision -> ('ocaml, 'elt_t) Stdlib.Bigarray.kind
val precision_string : t -> string
val default_kind : (Base.float, Ops.float32_elt) Ops.precision
val get_prec : t -> Ops.prec
type 'r map_with_prec = {
  1. f : 'ocaml 'elt_t. ('ocaml, 'elt_t) Ops.precision -> ('ocaml, 'elt_t) bigarray -> 'r;
}
val map_with_prec : 'a map_with_prec -> t -> 'a
val create_bigarray_of_prec : ('ocaml, 'elt_t) Ops.precision -> int array -> ('ocaml, 'elt_t) bigarray
val init_bigarray_of_prec : ('ocaml, 'elt_t) Ops.precision -> int array -> f:(Base.int Base.array -> 'ocaml) -> ('ocaml, 'elt_t) bigarray
val indices_to_offset : dims:Base__Int.t Base.Array.t -> idcs:Base__Int.t Base.Array.t -> Base__Int.t

*** Initialization ***

type axis_padding = {
  1. left : Base.int;
  2. right : Base.int;
}
val axis_padding_of_sexp : Sexplib0.Sexp.t -> axis_padding
val sexp_of_axis_padding : axis_padding -> Sexplib0.Sexp.t
val equal_axis_padding : axis_padding -> axis_padding -> Base.bool
val create_bigarray : ('ocaml, 'elt_t) Ops.precision -> dims:Base__Int.t Base.Array.t -> padding:(axis_padding Base.Array.t * float) Base.Option.t -> Ops.init_op -> ('ocaml, 'elt_t) bigarray

*** Accessing ***

type 'r map_as_bigarray = {
  1. f : 'ocaml 'elt_t. ('ocaml, 'elt_t) bigarray -> 'r;
}
val map : 'a map_as_bigarray -> t -> 'a
type 'r map2_as_bigarray = {
  1. f2 : 'ocaml 'elt_t. ('ocaml, 'elt_t) bigarray -> ('ocaml, 'elt_t) bigarray -> 'r;
}
val map2 : 'a map2_as_bigarray -> t -> t -> 'a
val dims : t -> int array
val get_fatptr_not_managed : t -> ('a option, unit Ctypes_static.typ) Ctypes_memory.Fat.t
val get_voidptr_not_managed : t -> Base.unit Ctypes.ptr
val set_from_float : t -> int array -> Base.float -> unit
val fill_from_float : t -> Base.float -> unit
val set_bigarray : ('a, 'b, 'c) A.t -> f:(int Base.Array.t -> 'a) -> unit
val reset_bigarray : Ops.init_op -> ('o, 'b) Ops.precision -> ('o, 'b) bigarray -> unit
val reset : Ops.init_op -> t -> unit
val fold_bigarray : ('a, 'b, 'c) A.t -> init:'d -> f:('d -> int Base.Array.t -> 'a -> 'd) -> 'd
val fold_as_float : init:'a -> f:('a -> int Base.Array.t -> Base.float -> 'a) -> t -> 'a
val size_in_bytes : t -> int
val get_as_float : t -> int array -> Base.Float.t
val retrieve_2d_points : ?from_axis:Base__Int.t -> xdim:int -> ydim:int -> t -> (Base.Float.t * Base.Float.t) Base.Array.t
val retrieve_1d_points : ?from_axis:Base__Int.t -> xdim:int -> t -> Base.Float.t Base.Array.t
val retrieve_flat_values : t -> Base.Float.t Base.Array.t
val c_ptr_to_string : t -> Base.String.t
val ptr_to_string_hum : t -> Base.String.t
val to_native : t -> Ctypes_ptr.voidp
val equal : t -> t -> Base.bool
val compare : t -> t -> Base.int
val hash : t -> Base__Ppx_hash_lib.Std.Hash.hash_value
val hash_fold_t : Base__.Ppx_hash_lib.Std.Hash.state -> t -> Base__.Ppx_hash_lib.Std.Hash.state
val hash_t : t -> Base__Ppx_hash_lib.Std.Hash.hash_value

*** Creating ***

val used_memory : int Stdlib.Atomic.t
val create_array : debug:Base.string -> Ops.prec -> dims:Base.int Base.array -> padding:(axis_padding Base.Array.t * float) Base.Option.t -> Ops.init_op -> t
val empty_array : Ops.prec -> debug:Base.string -> t
val get_used_memory : unit -> int

*** Printing ***

val int_dims_to_string : ?with_axis_numbers:bool -> Base.Int.t Base.Array.t -> Base.String.t

Dimensions to string, "x"-separated, e.g. 1x2x3 for batch dims 1, input dims 3, output dims 2. Outputs "-" for empty dimensions.

val log_debug_info : from_log_level:int -> t -> unit

Logs information about the array on the default ppx_minidebug runtime, if from_log_level > Utlis.settings.with_log_level.

val concise_float : prec:Base__Int.t -> float -> string
val render_array : ?brief:Base.bool -> ?prefix:Base.String.t -> ?entries_per_axis:Base__Int.t -> ?labels:Base.String.t Base.Array.t -> indices:Base__Int.t Base.Array.t -> t -> PrintBox.t

Prints 0-based indices entries out of arr, where a number between -5 and -1 in an axis means to print out the axis, and a non-negative number means to print out only the indexed dimension of the axis. Prints up to entries_per_axis or entries_per_axis+1 entries per axis, possibly with ellipsis in the middle. labels provides the axis labels for all axes (use "" or "_" for no label). The last label corresponds to axis -1 etc. The printed out axes are arranged as:

  • -1: a horizontal segment in an inner rectangle (i.e. column numbers of the inner rectangle),
  • -2: a sequence of segments in a line of text (i.e. column numbers of an outer rectangle),
  • -3: a vertical segment in an inner rectangle (i.e. row numbers of the inner rectangle),
  • -4: a vertical sequence of segments (i.e. column numbers of an outer rectangle),
  • -5: a sequence of screens of text (i.e. stack numbers of outer rectangles).
val to_doc : ?prefix:Base.String.t -> ?entries_per_axis:Base__Int.t -> ?labels:Base.String.t Base.Array.t -> indices:Base__Int.t Base.Array.t -> t -> PPrint.document
val to_doc_inline : num_batch_axes:Base__Int.t -> num_output_axes:Base__Int.t -> num_input_axes:Base__Int.t -> ?axes_spec:string -> t -> PPrint.document

Prints the whole array in an inline syntax.