package nx

  1. Overview
  2. Docs

Module Nx_core.DtypeSource

Data types for tensor elements.

Element Types

Sourcetype float8_e4m3_elt = Bigarray_ext.float8_e4m3_elt
Sourcetype float8_e5m2_elt = Bigarray_ext.float8_e5m2_elt

Data Type

Sourcetype ('a, 'b) t =
  1. | Float16 : (float, float16_elt) t
  2. | Float32 : (float, float32_elt) t
  3. | Float64 : (float, float64_elt) t
  4. | Int8 : (int, int8_elt) t
  5. | UInt8 : (int, uint8_elt) t
  6. | Int16 : (int, int16_elt) t
  7. | UInt16 : (int, uint16_elt) t
  8. | Int32 : (int32, int32_elt) t
  9. | Int64 : (int64, int64_elt) t
  10. | Int : (int, int_elt) t
  11. | NativeInt : (nativeint, nativeint_elt) t
  12. | Complex32 : (Complex.t, complex32_elt) t
  13. | Complex64 : (Complex.t, complex64_elt) t
  14. | BFloat16 : (float, bfloat16_elt) t
  15. | Bool : (bool, bool_elt) t
  16. | Int4 : (int, int4_elt) t
  17. | UInt4 : (int, uint4_elt) t
  18. | Float8_e4m3 : (float, float8_e4m3_elt) t
  19. | Float8_e5m2 : (float, float8_e5m2_elt) t
  20. | Complex16 : (Complex.t, complex16_elt) t
  21. | QInt8 : (int, qint8_elt) t
  22. | QUInt8 : (int, quint8_elt) t

GADT representing tensor element types. First type parameter is the OCaml type, second is the Bigarray element type.

Constructors

Sourceval float16 : (float, float16_elt) t
Sourceval float32 : (float, float32_elt) t
Sourceval float64 : (float, float64_elt) t
Sourceval int8 : (int, int8_elt) t
Sourceval uint8 : (int, uint8_elt) t
Sourceval int16 : (int, int16_elt) t
Sourceval uint16 : (int, uint16_elt) t
Sourceval int32 : (int32, int32_elt) t
Sourceval int64 : (int64, int64_elt) t
Sourceval int : (int, int_elt) t
Sourceval nativeint : (nativeint, nativeint_elt) t
Sourceval complex32 : (Complex.t, complex32_elt) t
Sourceval complex64 : (Complex.t, complex64_elt) t
Sourceval bfloat16 : (float, bfloat16_elt) t
Sourceval bool : (bool, bool_elt) t
Sourceval int4 : (int, int4_elt) t
Sourceval uint4 : (int, uint4_elt) t
Sourceval float8_e4m3 : (float, float8_e4m3_elt) t
Sourceval float8_e5m2 : (float, float8_e5m2_elt) t
Sourceval complex16 : (Complex.t, complex16_elt) t
Sourceval qint8 : (int, qint8_elt) t
Sourceval quint8 : (int, quint8_elt) t

Properties

Sourceval to_string : ('a, 'b) t -> string

to_string dtype returns string representation.

Sourceval pp : Format.formatter -> ('a, 'b) t -> unit

pp fmt dtype pretty-prints the dtype.

Sourceval itemsize : ('a, 'b) t -> int

itemsize dtype returns size in bytes.

Type Classes

Sourceval is_float : ('a, 'b) t -> bool

is_float dtype returns true for floating-point types.

Sourceval is_complex : ('a, 'b) t -> bool

is_complex dtype returns true for complex types.

Sourceval is_int : ('a, 'b) t -> bool

is_int dtype returns true for signed integer types.

Sourceval is_uint : ('a, 'b) t -> bool

is_uint dtype returns true for unsigned integer types.

Constants

Sourceval zero : ('a, 'b) t -> 'a

zero dtype returns zero value.

Sourceval one : ('a, 'b) t -> 'a

one dtype returns one value.

Sourceval two : ('a, 'b) t -> 'a

two dtype returns two value.

Sourceval minus_one : ('a, 'b) t -> 'a

minus_one dtype returns negative one value.

Sourceval min_value : ('a, 'b) t -> 'a

min_value dtype returns minimum representable value.

Sourceval max_value : ('a, 'b) t -> 'a

max_value dtype returns maximum representable value.

Conversions

Sourceval of_float : ('a, 'b) t -> float -> 'a

of_float dtype f converts float to dtype value.

Sourceval of_bigarray_ext_kind : ('a, 'b) Bigarray_ext.kind -> ('a, 'b) t

of_bigarray_ext_kind kind returns corresponding dtype from Bigarray_ext kind.

Sourceval to_bigarray_kind : ('a, 'b) t -> ('a, 'b) Bigarray.kind

to_bigarray_kind dtype returns corresponding standard Bigarray kind.

  • raises Failure

    if dtype is an extended type not supported by standard Bigarray

Sourceval to_bigarray_ext_kind : ('a, 'b) t -> ('a, 'b) Bigarray_ext.kind

to_bigarray_ext_kind dtype returns corresponding Bigarray_ext kind. Works for all types including extended ones.

Sourceval of_bigarray_kind : ('a, 'b) Bigarray.kind -> ('a, 'b) t

of_bigarray_kind kind returns corresponding dtype from standard Bigarray kind.

Equality

Sourceval equal : ('a, 'b) t -> ('c, 'd) t -> bool

equal dtype2 dtype2 tests dtype equality.

Sourceval equal_witness : ('a, 'b) t -> ('c, 'd) t -> (('a, 'b) t, ('c, 'd) t) Type.eq option

equal_witness dtype2 dtype2 returns equality proof if dtypes match.

Packed Types

Sourcetype packed =
  1. | Pack : ('a, 'b) t -> packed
    (*

    Packed dtype that hides type parameters, allowing heterogeneous collections.

    *)
Sourceval pack : ('a, 'b) t -> packed

pack dtype wraps a dtype in a packed container.

Sourceval all_dtypes : packed list

all_dtypes is a list of all available dtypes.

Sourceval of_string : string -> packed option

of_string s returns the dtype with string representation s, if it exists.

Sourceval equal_packed : packed -> packed -> bool

equal_packed p1 p2 tests equality of packed dtypes.

Sourceval pp_packed : Format.formatter -> packed -> unit

pp_packed fmt packed pretty-prints a packed dtype.

Sourceval packed_to_string : packed -> string

packed_to_string packed returns string representation of packed dtype.

Operations

Sourceval add : ('a, 'b) t -> 'a -> 'a -> 'a
Sourceval sub : ('a, 'b) t -> 'a -> 'a -> 'a
Sourceval mul : ('a, 'b) t -> 'a -> 'a -> 'a
Sourceval div : ('a, 'b) t -> 'a -> 'a -> 'a