package rune

  1. Overview
  2. Docs

Module Rune_metalSource

include Nx_core.Backend_intf.S
Sourcetype ('a, 'b) t

Opaque tensor handle.

'a is the OCaml element type; 'b tags the dtype.

Sourcetype context

Backend execution context. Carries any state required by the implementation (memory pools, command queues, ...).

Sourceval view : ('a, 'b) t -> Nx_core.View.t

Return the logical view metadata of t.

Sourceval dtype : ('a, 'b) t -> ('a, 'b) Nx_core.Dtype.t

Element type of t.

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

Execution context of t.

Sourceval data : ('a, 'b) t -> ('a, 'b, Bigarray.c_layout) Bigarray.Array1.t

Return the raw buffer of t.

Sourceval op_buffer : context -> ('a, 'b) Nx_core.Dtype.t -> int -> ('a, 'b) t

Allocate a buffer of size_in_elements elements of dtype.

Sourceval op_const_scalar : context -> 'a -> ('a, 'b) Nx_core.Dtype.t -> ('a, 'b) t

Tensor containing a single scalar value.

Sourceval op_const_array : context -> ('a, 'b, Bigarray.c_layout) Bigarray.Array1.t -> ('a, 'b) t

Tensor containing the elements of array. The array must be contiguous.

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

Element-wise addition.

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

Element-wise multiplication.

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

Integer division, truncating.

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

Floating-point division.

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

Element-wise maximum.

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

Integer modulus.

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

Raise base to exponent.

Sourceval op_cmplt : ('a, 'b) t -> ('a, 'b) t -> (int, Nx_core.Dtype.uint8_elt) t

Compare <. Returns 0 or 1 as uint8.

Sourceval op_cmpne : ('a, 'b) t -> ('a, 'b) t -> (int, Nx_core.Dtype.uint8_elt) t

Compare <>. Returns 0 or 1 as uint8.

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

Bitwise XOR.

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

Bitwise OR.

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

Bitwise AND.

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

Negation (logical not for bools).

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

Base-2 logarithm.

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

Exponential base 2.

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

Sine.

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

Square root.

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

Reciprocal.

Sourceval op_where : (int, Nx_core.Dtype.uint8_elt) t -> ('a, 'b) t -> ('a, 'b) t -> ('a, 'b) t

Select from if_true or if_false based on a boolean tensor.

Sourceval op_reduce_sum : axes:int array -> keepdims:bool -> ('a, 'b) t -> ('a, 'b) t

Sum over axes. Keeps reduced dimensions if keepdims is true.

Sourceval op_reduce_max : axes:int array -> keepdims:bool -> ('a, 'b) t -> ('a, 'b) t

Maximum over axes. Keeps reduced dimensions if keepdims is true.

Sourceval op_reduce_prod : axes:int array -> keepdims:bool -> ('a, 'b) t -> ('a, 'b) t

Product over axes. Keeps reduced dimensions if keepdims is true.

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

Broadcast dimensions of size 1 to a new shape.

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

Change the logical shape without moving data.

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

Reorder dimensions according to axes.

Sourceval op_pad : ('a, 'b) t -> (int * int) array -> 'a -> ('a, 'b) t

Pad with fill_value using the given configuration.

Sourceval op_shrink : ('a, 'b) t -> (int * int) array -> ('a, 'b) t

Slice according to the given start/stop pairs.

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

Flip dimensions where the boolean array is true.

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

Concatenate tensors along axis.

Sourceval op_cast : ('a, 'b) t -> ('c, 'd) Nx_core.Dtype.t -> ('c, 'd) t

Cast elements to target_dtype.

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

Return a C-contiguous tensor. May copy.

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

Duplicate t. Result has its own buffer.

Sourceval op_assign : ('a, 'b) t -> ('a, 'b) t -> unit

Store src into dst at the given logical indices.

Sourceval op_threefry : (int32, Nx_core.Dtype.int32_elt) t -> (int32, Nx_core.Dtype.int32_elt) t -> (int32, Nx_core.Dtype.int32_elt) t

Threefry random number generator.

Sourceval op_gather : ('a, 'b) t -> (int32, Nx_core.Dtype.int32_elt) t -> int -> ('a, 'b) t

Gather elements from data along axis using indices. Output shape matches indices. Ranks of data and indices must match. Sizes of indices dims != axis must be <= data corresponding dims.

Sourceval op_scatter : ?mode:[ `Set | `Add ] -> ?unique_indices:bool -> ('a, 'b) t -> (int32, Nx_core.Dtype.int32_elt) t -> ('a, 'b) t -> int -> ('a, 'b) t

Scatter updates into a new tensor shaped like data_template along axis using indices. Returns a new tensor.

  • mode specifies how to handle duplicate indices:
  • `Set (default): last update wins
  • `Add: accumulate updates at duplicate indices
  • unique_indices: hint that indices are unique (optimization)
Sourceval op_unfold : ('a, 'b) t -> kernel_size:int array -> stride:int array -> dilation:int array -> padding:(int * int) array -> ('a, 'b) t

Unfold (im2col) operation. Extracts sliding local blocks from a batched input tensor. For an input of shape (N, C, *spatial_dims), produces output of shape (N, C * prod(kernel_size), L) where L is the number of blocks. Works for any number of spatial dimensions.

Sourceval op_fold : ('a, 'b) t -> output_size:int array -> kernel_size:int array -> stride:int array -> dilation:int array -> padding:(int * int) array -> ('a, 'b) t

Fold (col2im) operation. Combines an array of sliding local blocks into a tensor. For an input of shape (N, C * prod(kernel_size), L), produces output of shape (N, C, *output_size). Inverse of unfold. Overlapping values are summed. Works for any number of spatial dimensions.

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

Matrix multiplication. For 2D tensors, computes standard matrix multiplication. For higher dimensions, performs batched matrix multiplication on the last two dimensions, broadcasting batch dimensions as needed. The last dimension of the first tensor must match the second-to-last dimension of the second tensor.

Sourceval is_available : bool
Sourceval create_context : unit -> context
OCaml

Innovation. Community. Security.