Module Dtype.Ptr
Pointer dtype: a base Val.t plus address space, buffer element count (size), pointer vector width (v), and optional image metadata.
Invariant: v >= 1. size = -1 indicates an unbounded buffer. Image pointers additionally have base Val.float32, address space Global, size equal to the product of their image shape, and priority 100. Construct image pointers with Image.imageh or Image.imagef.
Accessors
val count : t -> intcount p is the vector width of the base value dtype.
val addrspace : t -> addr_spaceaddrspace p is the memory address space of p.
val v : t -> intv p is the pointer vector width of p (number of independent pointer lanes packed together). Always >= 1.
val size : t -> intsize p is the number of elements in the pointed-to buffer, or -1 for unbounded.
value p is the dtype produced by reading through p. It preserves the pointer vector width: reading through float.ptr(...).vec(4) produces float.vec(4).
val image_kind : t -> image_kind optionimage_kind p is Some kind if p is an image pointer dtype and None otherwise.
val image_shape : t -> int list optionimage_shape p is Some shape if p is an image pointer dtype and None otherwise.
val is_image : t -> boolis_image p is true iff p carries image metadata.
Constructors
val create : Val.t -> addrspace:addr_space -> size:int -> tcreate base ~addrspace ~size is a pointer to base in addrspace with size elements (-1 for unbounded). Pointer vector width defaults to 1.
val create_v : Val.t -> addrspace:addr_space -> size:int -> v:int -> tcreate_v base ~addrspace ~size ~v is like create with explicit pointer vector width v.
Raises Invalid_argument if v < 1.
Transformers
scalarize p is p with pointer vector width 1 and base count = 1. The address space and size are preserved.
vec n p is p with pointer vector width set to n.
Raises Invalid_argument if n < 1 or if p is already vectorized.
with_base dt p is p with base value dtype replaced by dt. The address space, v, and size are preserved. Image metadata is removed because image dtypes have a fixed Val.float32 base.
with_size n p is p with buffer element count set to n. Image metadata is removed if n differs from the current image size, because image dtype size is derived from shape.
Properties
val bitsize : t -> intval nbytes : t -> intnbytes p is size p * itemsize p.
Raises Invalid_argument if size p = -1.
val priority : t -> intpriority p is the promotion priority. Image pointers have priority 100, matching tinygrad image dtypes.
Comparison
equal a b is true iff all fields of a and b are structurally equal (base scalar, base count, addrspace, v, size).
Note. IR validators may use partial field comparisons (e.g., index validation ignores size); those checks are intentionally distinct from this structural equality.
compare a b is a total order over pointer types. Orders by priority, base scalar priority, base count, addrspace, v, size, and image metadata.
Formatting
val to_string : t -> stringto_string p is a human-readable representation of p in the form {base}*[.vec(v)] [addrspace] (e.g., "f32* [global]", "i32*.vec(4) [local]").
val repr : t -> stringrepr p is the tinygrad-style pointer or image dtype representation, such as "dtypes.float.ptr(-1)", "dtypes.int.ptr(4, AddrSpace.LOCAL).vec(2)", or "dtypes.imageh((8, 16, 4))".