Properties
dataThe same tensor (in-place fills through.data update it, as in PyTorch).
deviceThe tensor's device: always cpu, for every dtype (one unified memory).
dtypeThe dtype (float32, float64, float16, bfloat16, the integer types or bool).
gradThe gradient (None before backward). Assignable; in-place changes write through.
grad_dtypeThe dtype of this tensor's gradient (its own dtype for floating tensors, else None).
grad_fnNone for a leaf, else the backward node of the op that made the tensor (name: PyTorch's name, as MulBackward0).
HThe conjugate transpose of a matrix (2-d only, as PyTorch); for real tensors the transpose.
imagImaginary part of a complex tensor; TypeError for real tensors, as PyTorch.
is_cpuTrue: Riptorch tensors live in one unified memory the CPU reads.
is_distributed_False: Riptorch has no distributed tensors.
Riptorch extra: not in stock PyTorch.
is_leafA tensor that needs no gradient, or one made by the user (not by an op that records gradients). grad_fn is None for leaves, else an object naming the op.
is_mpsFalse: the GPU is used internally, tensors are not MPS tensors.
is_quantized_False: Riptorch has no quantized tensors.
Riptorch extra: not in stock PyTorch.
mHThe conjugate transpose of the last two dims (the transpose: real tensors).
nameThe tensor's name (None unless set; named-tensor dims are not supported).
namesDimension names: None for every dim (no named tensors).
Riptorch extra: not in stock PyTorch.
output_nr0: the output index of this tensor in the op that made it (always 0 here).
requires_gradWhether autograd records operations on this tensor (settable; float dtypes).
retains_gradTrue after retain_grad on a non-leaf tensor (its.grad is kept by backward).
Tt: the transpose of a 0-, 1- or 2-d tensor (PyTorch also reverses the dims of higher-dimensional tensors, deprecated there; Riptorch raises).
Core methods
backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None)Backpropagates from the given tensor(s): the gradients of the graph's leaves accumulate into.grad (gradient= supplies the vector for a non-scalar output; retain_graph / create_graph as PyTorch). Callbacks queued with queue_callback run when it finishes.
clone(input, *, memory_format=None)Same as PyTorch’s torch.Tensor.clone.
contiguous(self, memory_format=None)self: Riptorch tensors are always contiguous.
cpu(self, *args, **kwargs)Tensor.cpu / cuda / mps / pin_memory: the tensor itself (one unified memory and one layout).
cuda(self, *args, **kwargs)Tensor.cpu / cuda / mps / pin_memory: the tensor itself (one unified memory and one layout).
data_ptr(self)A stable integer identity of the tensor (id(self)); Riptorch does not expose buffer addresses.
detach(self)The same values without autograd history (requires_grad False).
detach_(self)In place: self stops recording gradients; returns self.
expand(input, *size)A broadcast view to the given size (-1 keeps a dimension); size-1 dims repeat without copying. Dtypes: every dtype (autograd for the floating-point types).
is_contiguous(self, *a, **k)True: Riptorch tensors have one row-major layout.
item(self)The value of a one-element tensor as a Python number (more elements raise, as PyTorch).
mps(self, *args, **kwargs)Tensor.cpu / cuda / mps / pin_memory: the tensor itself (one unified memory and one layout).
Riptorch extra: not in stock PyTorch.
new_empty(self, *size, dtype=None, device=None, requires_grad=False, **kw)A new tensor of the given size filled with the constant (new_ones: 1; new_zeros and new_empty: 0), self's dtype unless dtype=.
new_full(self, size, fill_value, *, dtype=None, device=None, requires_grad=False, **kw)A new tensor of the given size filled with fill_value, self's dtype unless dtype=.
new_ones(self, *size, dtype=None, device=None, requires_grad=False, **kw)A new tensor of the given size filled with the constant (new_ones: 1; new_zeros and new_empty: 0), self's dtype unless dtype=.
new_tensor(self, data, *, dtype=None, device=None, requires_grad=False, **kw)A new tensor from data, self's dtype unless dtype=.
new_zeros(self, *size, dtype=None, device=None, requires_grad=False, **kw)A new tensor of the given size filled with the constant (new_ones: 1; new_zeros and new_empty: 0), self's dtype unless dtype=.
numpy(self, *, force=False)The tensor's values as a NumPy array (a copy; PyTorch shares memory on the CPU).
Raises RuntimeError when the tensor requires grad, unless force=True; bfloat16 raises TypeError, as PyTorch.
register_hook(self, hook)Leaves: the hook sees the gradient before it accumulates into.grad (and autograd.grad's result). Non-leaves: the hook applies to the gradient of the uses made after registering (PyTorch: of every use).
requires_grad_(self, requires_grad=True)Sets requires_grad in place; returns self. A tensor that records no gradient becomes a leaf that does (whatever op made it); a non-leaf cannot stop (RuntimeError, as PyTorch: detach it).
reshape(self, *shape)The values in a new shape (sizes or one sequence; one -1 is inferred); view is the same.
reshape_as(self, other)The tensor reshaped to other's shape (reshape_as too).
retain_grad(self)backward also keeps this non-leaf tensor's gradient in.grad (a leaf keeps its own anyway); RuntimeError on a tensor that does not require gradients, as PyTorch.
storage(self)A TypedStorage over this tensor's elements (PyTorch's deprecation warning once); writes go to the tensor.
stride(self, dim=None)The row-major (contiguous) strides of the shape, or the one of dim: Riptorch tensors are always laid out contiguously.
to(self, dtype=None, *args, **kwargs)The tensor in another dtype (from a dtype, a tensor's dtype, or dtype=); a device argument changes nothing (one unified memory). Returns self when nothing changes.
tolist(self)The values as nested Python lists (a 0-d tensor gives a number).
type(self, dtype=None)With no argument, the dtype (PyTorch returns a type string such as 'torch.FloatTensor'); with one, to(dtype).
untyped_storage(self)An UntypedStorage holding this tensor's bytes (a copy read when called; Riptorch shares no storage).
view(self, *shape)The values in a new shape (sizes or one sequence; one -1 is inferred); view is the same.
view_as(self, other)The tensor reshaped to other's shape (reshape_as too).
More methods
abs(input)Elementwise absolute value. Every dtype; autograd for the floating-point types.
absolute(input)Alias of Tensor.abs.
Elementwise absolute value. Every dtype; autograd for the floating-point types.
acos(input, *, out=None)Arccosine, elementwise, as atan2(sqrt(1 - x^2), x); differentiable. Integer input is computed in float32.
acosh(input)Inverse hyperbolic cosine (NaN below 1). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
add(input, other, *, alpha=1)self + alpha * other, with broadcasting and PyTorch type promotion. Every dtype; autograd for the floating-point types.
addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None)beta * input + alpha * sum over the batch of batch1[i] @ batch2[i].
addcdiv(input, tensor1, tensor2, *, value=1)input + value * tensor1 / tensor2.
addcmul(input, tensor1, tensor2, *, value=1)input + value * tensor1 * tensor2.
addmm(input, mat1, mat2, *, beta=1, alpha=1)beta * self + alpha * (mat1 @ mat2). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
addmv(input, mat, vec, *, beta=1, alpha=1, out=None)torch.addmv(self, *args, **kwargs).
beta * input + alpha * (mat @ vec).
addr(input, vec1, vec2, *, beta=1, alpha=1, out=None)beta * input + alpha * outer(vec1, vec2).
adjoint(self)The transpose of the last two dims (conjugated for complex tensors in PyTorch).
all(Tensor self, int? dim=None, bool keepdim=False) -> TensorWhether every element is nonzero, over all elements or along dim; returns bool. Every dtype; autograd for the floating-point types.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
allclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False)Whether isclose holds everywhere; a Python bool.
amax(Tensor self, int[] dim=[], bool keepdim=False) -> TensorMaximum along the given dims (all dims when empty); gradients split evenly between tied maxima, as PyTorch. Every dtype; autograd for the floating-point types.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
amin(Tensor self, int[] dim=[], bool keepdim=False) -> TensorMinimum along the given dims (all dims when empty); gradients split evenly between tied minima, as PyTorch. Every dtype; autograd for the floating-point types.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
aminmax(self, *, dim=None, keepdim=False)torch.aminmax(self, dim=dim, keepdim=keepdim).
angle(x)torch.angle(self, *args, **kwargs).
The argument atan2(imag, real) of each complex value (0 or pi for real values).
any(Tensor self, int? dim=None, bool keepdim=False) -> TensorWhether any element is nonzero, over all elements or along dim; returns bool. Every dtype; autograd for the floating-point types.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
arccos(input, *, out=None)Alias of Tensor.acos.
Arccosine, elementwise, as atan2(sqrt(1 - x^2), x); differentiable. Integer input is computed in float32.
arccosh(input)Inverse hyperbolic cosine (NaN below 1). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
arcsin(input, *, out=None)Alias of Tensor.asin.
Arcsine, elementwise, as atan2(x, sqrt(1 - x^2)); differentiable. Integer input is computed in float32.
arcsinh(input)Inverse hyperbolic sine. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
arctan(input, *, out=None)arctan: odd, with x > 1 folded through atan(x) = pi/2 - atan(1/x), then a polynomial on [0, 1] (|error| <= 2e-8) written with Riptorch ops.
arctan2(input, other, *, out=None)The angle of (other, input) in (-pi, pi], quadrant by quadrant from atan. Computed in float32 (float64 inputs give a float32 result; PyTorch keeps float64). Lazy and differentiable.
arctanh(input)Inverse hyperbolic tangent (inf at +-1, NaN outside). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
argmax(Tensor self, int? dim=None, bool keepdim=False) -> TensorThe first index of the maximum (as PyTorch), int64.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
argmin(Tensor self, int? dim=None, bool keepdim=False) -> TensorIndex of the minimum over the flattened tensor or along dim (the first one on ties); int64.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
argsort(Tensor self, int dim=-1, bool descending=False, *, bool stable=False) -> TensorIndices that sort along dim (descending= for largest first); ties keep their original order.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
argwhere(input, *, as_tuple=False)The indices of the nonzero elements, as an n x ndim int64 tensor or (as_tuple=True) one tensor per dim; argwhere too.
as_strided(input, size, stride, storage_offset=0)A tensor whose element [i0, i1,...] is the input's flat element storage_offset + sum(ik * stride[k]) (a copy: Riptorch has no shared storage).
as_strided_scatter(input, src, size, stride, storage_offset=None)input with the elements that as_strided(input, size, stride, storage_offset) would view replaced by src.
as_subclass(self, cls)This tensor's data as an instance of cls (a Tensor subclass); keeps autograd history.
asin(input, *, out=None)Arcsine, elementwise, as atan2(x, sqrt(1 - x^2)); differentiable. Integer input is computed in float32.
asinh(input)Inverse hyperbolic sine. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
atan(input, *, out=None)arctan: odd, with x > 1 folded through atan(x) = pi/2 - atan(1/x), then a polynomial on [0, 1] (|error| <= 2e-8) written with Riptorch ops.
atan2(input, other, *, out=None)The angle of (other, input) in (-pi, pi], quadrant by quadrant from atan. Computed in float32 (float64 inputs give a float32 result; PyTorch keeps float64). Lazy and differentiable.
atanh(input)Inverse hyperbolic tangent (inf at +-1, NaN outside). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
baddbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None)beta * input + alpha * (batch1 @ batch2), batched.
bernoulli(self, p=None, *, generator=None)Tensor.bernoulli: torch.bernoulli(self, p).
bincount(input, weights=None, minlength=0)Counts of each non-negative integer in the 1-d input (int64), or the sums of weights per value (float32 weights give float32, others float64); at least minlength entries.
bitwise_and(input, other)Bitwise AND of integers, logical AND of bools (also &, and torch.logical_and on bool casts). Every dtype.
bitwise_left_shift(input, other, *, out=None)Shift left: input << other, elementwise on integers, wrapping to input's width as PyTorch.
bitwise_not(input)Bitwise NOT of integers, logical NOT of bools (also ~, and logical_not on bool casts). Every dtype.
bitwise_or(input, other)Bitwise OR of integers, logical OR of bools (also |, and torch.logical_or on bool casts). Every dtype.
bitwise_right_shift(input, other, *, out=None)Shift right: input >> other (arithmetic for signed types), elementwise on integers, wrapping to input's width as PyTorch.
bitwise_xor(input, other)Bitwise XOR of integers, logical XOR of bools (also ^). Every dtype.
bmm(input, mat2, *, out=None)mm / bmm / mv / dot / inner / outer / addmv / baddbmm / einsum
Each checks its operands' dims as PyTorch does and is a matmul (or the einsum row).
broadcast_to(input, size)The tensor expanded to size (-1 keeps a dim), a broadcast view.
ccol_indices(self, *a, **k)Raises RuntimeError as PyTorch on a dense tensor: ccol_indices needs a sparse column compressed tensor.
ceil(input)Rounds up to an integer value (the dtype is kept). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
chalf(self, memory_format=None)Raises NotImplementedError: Riptorch has no complex32.
Different from PyTorch: Raises NotImplementedError: Riptorch has no complex32.
cholesky(A, upper=False, *, out=None)torch.cholesky (deprecated in PyTorch): linalg.cholesky(A, upper=upper).
cholesky_inverse(L, upper=False, *, out=None)torch.cholesky_inverse(L, upper=False): (L L^T)^-1 (or (U^T U)^-1). Gradient: -R (G + G^T) R L (lower).
cholesky_solve(B, L, upper=False, *, out=None)torch.cholesky_solve(B, L, upper=False): solves A X = B with A = L L^T (or U^T U). Gradients as PyTorch's: L as a full matrix in A = L L^T (not only its triangle).
chunk(Tensor self, int chunks, int dim=0) -> Tensor[]Splits into chunks of ceil(n / chunks) along dim (the last chunk may be smaller, or fewer chunks may come back), as PyTorch.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
clamp(input, min=None, max=None)Limits values to [min, max] (either may be None; clip too).
clamp_max(input, max)min(x, max). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
clip(input, min=None, max=None)Limits values to [min, max] (either may be None; clip too).
coalesce(self, *a, **k)Different from PyTorch: duplicate entries summed in float64 and rounded once: duplicates [1e8, 1, -1e8] give 1.0, PyTorch's float32 sum gives 0.0
- PyTorch
- sums duplicate entries in the values' dtype, in order (float32: 1e8 + 1 - 1e8 = 0)
- Riptorch
- sums duplicates in float64 and rounds once
- Measured
- duplicates [1e8, 1, -1e8]: PyTorch 0.0, Riptorch 1.0 (the exact sum)
- Stock behaviour
- torch.set_compat("pytorch")
col_indices(self, *a, **k)Raises RuntimeError as PyTorch on a dense tensor: col_indices needs a sparse row compressed tensor.
conj_physical(x)torch.conj_physical(self, *args, **kwargs).
The complex conjugate (a real tensor is returned as it is).
const_data_ptr(self)data_ptr (Riptorch has no read-only pointer distinction).
copysign(input, other, *, out=None)abs(input) with the sign of other, elementwise (other's sign bit decides, so -0.0 counts as negative); float.
corrcoef(input)The Pearson correlation matrix of the rows of input, clamped to [-1, 1].
cos(input)Different from PyTorch: float32 cos within 1 ulp of the correctly rounded value: worst 1.08 ulps of the exact value on [-100, 100] where PyTorch's CPU kernel has 1.57 (CPU and MPS: 2 ulps after rounding)
- PyTorch
- float32 cos up to 2 ulps off
- Riptorch
- float32: sin(x + pi/2) with the roundings of x + pi/2 and of pi/2 put back; float64: Cody-Waite reduction by pi/2 in three parts
- Measured
- 1500 points of [-100, 100]: Riptorch 1.08, PyTorch CPU 1.57 ulps of the exact value max 1 vs 2 ulps on [-1e-3, 1e-3], [1.5, 1.65], [-100, 100]
- Stock behaviour
- none: an accuracy gain, PyTorch's rounding is not reproduced
cosh(input)Hyperbolic cosine. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
count_nonzero(*a, **k)The number of non-zero entries (int64), over all or along dim (an int or a tuple).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
cov(input, *, correction=1, fweights=None, aweights=None)The covariance matrix of the rows (variables) of input over its columns (observations); correction=1 is Bessel's; fweights / aweights weight the observations. A 1-d input gives a 0-d variance.
cross(input, other, dim=-1)The 3-d cross product along dim (size 3), broadcasting.
crow_indices(self, *a, **k)Raises RuntimeError as PyTorch on a dense tensor: crow_indices needs a sparse row compressed tensor.
cummax(input, dim)Running maximum along dim and the index where it was reached, as (values, indices).
On ties the later index wins; a NaN propagates from where it appears. The values carry gradients (a gather of the input); the indices are int64.
cummin(input, dim)Running minimum along dim and the index where it was reached, as (values, indices).
On ties the later index wins; a NaN propagates from where it appears. The values carry gradients (a gather of the input); the indices are int64.
cumprod(*a, **k)Products along dim: for float32, a sequential product of slices (differentiable).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
cumsum(self, dim, *, dtype=None)torch.cumsum(self, dim, dtype=dtype).
deg2rad(input)Degrees to radians. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
dequantize(self)The float values of a quantized tensor; a float tensor is returned as it is (float16: as float32).
Different from PyTorch: one rounding of (q - zero_point) * scale; PyTorch's float32 scale gives a wrong last bit on 50 of 256 integers at scale 0.1
- PyTorch
- (q - zero_point) * float32(scale): the scale rounded to float32 first
- Riptorch
- the float32 nearest to (q - zero_point) * scale (one rounding)
- Measured
- scale 0.1, q in 0..255: PyTorch differs from the correctly rounded value at 22 of 256 integers (1 ulp)
- Stock behaviour
- torch.set_compat("pytorch")
det(A, *, out=None, maths=None, exact=False)Same as PyTorch’s torch.Tensor.det.
diag(input, diagonal=0)diag of a 1-d tensor: the square matrix with it on diagonal k; of a 2-d tensor: its diagonal k.
diag_embed(self, offset=0, dim1=-2, dim2=-1)torch.diag_embed(self, offset, dim1, dim2).
diagflat(input, offset=0)A square 2-d tensor with input's elements (flattened) on the offset diagonal and zeros elsewhere.
diagonal(input, offset=0, dim1=0, dim2=1)Tensor.diagonal / torch.diagonal: the diagonal at offset between dim1 and dim2, moved to the last dim (gradients flow).
diagonal_scatter(input, src, offset=0, dim1=0, dim2=1)A copy of a 2-d input with its offset diagonal replaced by src. Only 2-d input with dims (0, 1) (or (-2, -1)); others raise NotImplementedError.
Different from PyTorch: Only 2-d input with dims (0, 1) (or (-2, -1)); others raise NotImplementedError.
diff(*a, **k)The n-th forward difference along dim, after prepend / append are joined on; bool inputs use !=.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
digamma(input, *, out=None)Different from PyTorch: correctly rounded float32 values (computed in float64, rounded once); 1499 inputs in [-4.9, 5.7]: worst 125285 ulp (PyTorch) vs 0; MLX has no digamma
- PyTorch
- float32 kernels in float32 precision: values off by several ulp
- Riptorch
- computed in float64, rounded once to float32 (correctly rounded)
- Measured
- float32: 1499 inputs in [-4.9, 5.7]: worst 125285 ulp (PyTorch) vs 0
- Stock behaviour
- not reproduced: PyTorch's values come from its own float32 polynomial kernels, which Riptorch does not copy (compat keeps Riptorch's correctly rounded values)
dim_order(self, *, ambiguity_check=False)Dims ordered from outermost to innermost in memory (by stride).
dist(input, other, p=2)The p-norm (default 2) of input - other over all elements.
div(input, other, *, rounding_mode=None)Division, true by default; rounding_mode="trunc" or "floor" rounds the quotient. Integer inputs give float32, as PyTorch. Every dtype; autograd for the floating-point types.
divide(input, other, *, rounding_mode=None)Division, true by default; rounding_mode="trunc" or "floor" rounds the quotient. Integer inputs give float32, as PyTorch. Every dtype; autograd for the floating-point types.
eig(*a, _m='This function was deprecated since version 1.9 and is now removed. Please use the `torch.linalg.eig` function instead.', **k)Removed from PyTorch: raises RuntimeError as PyTorch does (This function was deprecated since version 1.9 and is now removed. Please use the torch.linalg.eig function instead.)
eq(input, other)Elementwise ==, with broadcasting and PyTorch type promotion; returns bool. Every dtype; autograd for the floating-point types.
equal(input, other)True if both tensors have the same shape and the same values.
erf(input)The error function. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
erfc(input)1 - erf(x), accurate in the upper tail. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
erfinv(input, *, out=None)Different from PyTorch: correctly rounded float32 values (computed in float64, rounded once); 1999 inputs in [0.9999, 1]: every value off, worst 127 ulp vs 0; MLX's GPU erfinv is up to 3 ulp off there
- PyTorch
- float32 kernels in float32 precision: values off by several ulp
- Riptorch
- computed in float64, rounded once to float32 (correctly rounded)
- Measured
- float32: 1999 inputs in [0.9999, 1]: every value off, worst 127 ulp vs 0
- Stock behaviour
- not reproduced: PyTorch's values come from its own float32 polynomial kernels, which Riptorch does not copy (compat keeps Riptorch's correctly rounded values)
exp(input)Elementwise e^x. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
exp2(input)Elementwise 2^x. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
expm1(input)Taylor series below ln 2 / 2, e^x - 1 above: no cancellation near 0.
fix(input)Rounds toward zero (fix too). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
flatten(Tensor self, int start_dim=0, int end_dim=-1) -> TensorA reshape (the dims from start_dim to end_dim become one).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
flip(*a, **k)torch.flip(self, dims): dims as a sequence or as separate ints.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
float_power(self, exponent)torch.float_power(self, exponent): in float64.
floor(input)Rounds down to an integer value (the dtype is kept). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
floor_divide(input, other, *, out=None)Division rounded down (torch.div with rounding_mode='floor'); integers stay integers.
fmax(input, other, *, out=None)Elementwise maximum ignoring NaN: where one side is NaN the other is returned (NaN only when both are).
fmin(input, other, *, out=None)Elementwise minimum ignoring NaN: where one side is NaN the other is returned (NaN only when both are).
frac(input)x - trunc(x), keeping the sign. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
frexp(input, *, out=None)(mantissa, exponent) with input = mantissa * 2**exponent and 0.5 <= |mantissa| < 1 (0 for 0).
mantissa keeps input's dtype, exponent is int32. Read back from the values: not differentiable.
gather(Tensor self, int dim, Tensor index, *, bool sparse_grad=False) -> Tensorout[i][j][k] = input[index[i][j][k]][j][k] along dim (any dtype). A float32 input that records gradients gathers through gather_positions, so gradients flow.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
gcd(input, other, *, out=None)Elementwise greatest common divisor of integer tensors, exact (Python integers), in the first input's dtype.
ge(input, other)Elementwise >=, with broadcasting and PyTorch type promotion; returns bool. Every dtype; autograd for the floating-point types.
gelu(input, approximate='none', *, maths=None)approximate="tanh": 0.5 x (1 + tanh(sqrt(2/pi) (x + 0.044715 x^3))).
Riptorch extra: not in stock PyTorch.
ger(input, vec2, *, out=None)torch.ger(self, *args, **kwargs).
The outer product of two vectors (ger too).
get_device(self)-1, PyTorch's answer for a CPU tensor (Riptorch's memory is unified).
greater_equal(input, other)Alias of Tensor.ge.
Elementwise >=, with broadcasting and PyTorch type promotion; returns bool. Every dtype; autograd for the floating-point types.
gt(input, other)Elementwise >, with broadcasting and PyTorch type promotion; returns bool. Every dtype; autograd for the floating-point types.
hardshrink(input, lambd=0.5)x where |x| > lambd, else 0. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
hash_tensor(input, dim=(), *, keepdim=False, mode=0)XOR of the elements' bit patterns (floats as float64 bits, integers as int64), over dim (all when empty). PyTorch returns uint64; the core has no uint64 tensors, so the same 64 bits come back as int64.
heaviside(input, values, *, out=None)The step function: 0 where input < 0, 1 where input > 0, values where input == 0; input's dtype.
histc(input, bins=100, min=0, max=0, *, out=None)Counts in bins equal-width bins over [min, max] (the data's range when min == max); values outside and nan are skipped. Integer inputs give float32 counts (PyTorch raises for them).
histogram(input, bins=100, *, range=None, weight=None, density=False, out=None)torch.histogram(self, *args, **kwargs).
(hist, bin_edges): counts (or weight sums) in bins equal bins over range (default the data's range) or over the given edges tensor; density=True normalises to a density.
hsplit(input, sections)tensor_split along dim 1 (dim 0 for a 1-d input).
hspmm(self, mat2)torch.hspmm(self, mat2): sparse self @ dense mat2 as a hybrid COO tensor.
Riptorch extra: not in stock PyTorch.
hypot(input, other)sqrt(a^2 + b^2) elementwise. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
i0(input, *, out=None)Different from PyTorch: correctly rounded float32 values (computed in float64, rounded once); 1500 inputs in [0, 75]: worst 3 ulp vs 0; MLX has no i0
- PyTorch
- float32 kernels in float32 precision: values off by several ulp
- Riptorch
- computed in float64, rounded once to float32 (correctly rounded)
- Measured
- float32: 1500 inputs in [0, 75]: worst 3 ulp vs 0
- Stock behaviour
- not reproduced: PyTorch's values come from its own float32 polynomial kernels, which Riptorch does not copy (compat keeps Riptorch's correctly rounded values)
igamma(input, other, *, out=None)The regularized lower incomplete gamma function P(a, x) (input a, other x), in float64 and rounded once.
igammac(input, other, *, out=None)The regularized upper incomplete gamma function Q(a, x) = 1 - P(a, x), in float64 and rounded once.
index(self, positions, dims)Binds dims to first-class Dim objects (functorch.dim) in PyTorch; not supported: NotImplementedError.
Different from PyTorch: Binds dims to first-class Dim objects (functorch.dim) in PyTorch; not supported: NotImplementedError.
index_add(input, dim, index, source, *, alpha=1)Different from PyTorch: repeated indices summed in float64 and rounded once: [1e8, 1, -1e8] at one index gives 1.0, PyTorch's float32 sum gives 0.0
- PyTorch
- adds source's slices one after another in the input's dtype (float32: 1e8 + 1 - 1e8 = 0)
- Riptorch
- without gradients, one CPU pass summing in float64, rounded once (any n x k); with gradients, the float32 one-hot product in blocks
- Measured
- [1e8, 1, -1e8] added at index 0 of zeros(2): PyTorch 0.0, Riptorch 1.0 (the exact sum)
- Stock behaviour
- torch.set_compat("pytorch")
index_copy(input, dim, index, source)A copy of input with source's slices written at index along dim.
index_fill(input, dim, index, value)A copy of input with value written into the slices at index along dim.
index_put(input, indices, values, accumulate=False)Different from PyTorch: accumulate=True sums repeated positions in float64 and rounds once: [1e8, 1, -1e8] at one position gives 1.0, PyTorch gives 0.0
- PyTorch
- accumulate=True adds the values one after another in the input's dtype
- Riptorch
- accumulate=True: index_add's float64 sum, rounded once
- Measured
- [1e8, 1, -1e8] put at position 0 of zeros(2) with accumulate=True: PyTorch 0.0, Riptorch 1.0; run to run, index_put_(accumulate=True) gives one result in 20 runs where PyTorch CPU and MPS give 20 different ones
- Stock behaviour
- torch.set_compat("pytorch")
index_reduce(self, dim, index, source, reduce, *, include_self=True)A copy of self where row index[j] of dim is reduced with source's row j: reduce "prod", "mean", "amax" or "amin"; include_self=False leaves self's own value out of rows that receive any. Integer mean floors.
index_select(*a, **k)The slices of input along dim at index (1-d, int); differentiable.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
indices(self, *a, **k)Raises RuntimeError as PyTorch on a dense tensor: indices needs a sparse coordinate tensor.
inner(input, other, *, out=None)Inner product over the last dims (a scalar input multiplies).
int_repr(input)The stored integers of a quantized tensor (raises for a float tensor, as PyTorch).
inverse(self)linalg.inv(self) (integer tensors give the exact inverse as a FractionTensor).
ipu(self, device=None, non_blocking=False, memory_format=None)Raises RuntimeError: no IPU support (PyTorch's message).
is_coalesced(self, *a, **k)Raises RuntimeError as PyTorch on a dense tensor: is_coalesced needs a sparse coordinate tensor.
is_floating_point(input)Same as PyTorch’s torch.Tensor.is_floating_point.
is_inference(self)False: Riptorch makes no inference tensors.
is_nonzero(self)The truth value of a one-element tensor; more elements raise RuntimeError as PyTorch.
is_set_to(self, t)Whether t is this very tensor (Riptorch tensors never share storage).
is_signed(self)Whether the dtype holds negative values (floats and signed integers).
isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False)|input - other| <= atol + rtol * |other| elementwise (equal_nan=True counts NaN == NaN); returns bool.
isfinite(input)True where the element is neither inf nor NaN (always True for integer and bool tensors).
isin(elements, test_elements, *, assume_unique=False, invert=False)torch.isin(self, *args, **kwargs).
Riptorch extra: not in stock PyTorch.
isinf(input)True where the element is +inf or -inf (always False for integer and bool tensors).
isnan(input)Tensor.isnan / torch.isnan: True where the element is NaN (x != x); always False for integer and bool tensors.
isneginf(x)torch.isneginf(self, *args, **kwargs).
True where the element is -inf.
isposinf(x)torch.isposinf(self, *args, **kwargs).
True where the element is +inf.
isreal(self)Elementwise: True where the imaginary part is zero (all True for real tensors).
istft(input, n_fft, hop_length=None, win_length=None, window=None, center=True, normalized=False, onesided=None, length=None, return_complex=False)Inverse of stft: the inverse FFT of each frame, windowed, overlap-added and divided by the summed squared window. center=True removes the n_fft // 2 padding; length= trims or sets the output length.
kron(input, other, *, out=None)torch.kron(a, b): the Kronecker product (dims aligned from the right), differentiable.
kthvalue(Tensor self, int k, int dim=-1, bool keepdim=False) -> (Tensor values, Tensor indices)The k-th smallest (1-based); among equal values the one the stable order puts k-th.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
lcm(input, other, *, out=None)Elementwise least common multiple of integer tensors (0 where either is 0), in the first input's dtype.
ldexp(input, other, *, out=None)input * 2**other, elementwise, as a float tensor.
le(input, other)Elementwise <=, with broadcasting and PyTorch type promotion; returns bool. Every dtype; autograd for the floating-point types.
less_equal(input, other)Alias of Tensor.le.
Elementwise <=, with broadcasting and PyTorch type promotion; returns bool. Every dtype; autograd for the floating-point types.
lgamma(input, *, out=None)log|Gamma(x)|, per element: computed in float64 and rounded once to the input's float dtype (integer inputs give float32); differentiable.
log(input)Elementwise natural log (-inf at 0, NaN below 0). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
log10(input)Elementwise log base 10. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
log1p(input)2 atanh(x / (2 + x)) below 1/4, log(1 + x) with the rounding of 1 + x put back above.
log2(input)Elementwise log base 2. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
log_softmax(Tensor input, int? dim=None, *, dtype? dtype=None) -> Tensorlog(softmax(x)) along dim, computed stably (x - logsumexp); dtype= casts the input first. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
logaddexp(input, other)log(exp(a) + exp(b)) computed stably. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
logaddexp2(input, other, *, out=None)log2(2^input + 2^other) without overflow: max + log2(1 + 2^-|input - other|).
logcumsumexp(*a, **k)log(cumsum(exp(input))) along dim, shifted by the maximum so large values don't overflow; integer inputs give float32 (PyTorch raises for them).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
logdet(A)torch.logdet(A): log det A (nan for a negative determinant, -inf for zero).
logical_and(input, other, *, out=None)Elementwise AND of the inputs' truth values (nonzero is True); bool.
logical_not(*args, **kw)logical_not: the inputs as bool, then bitwise_not (a bool result, as PyTorch's logical ops).
logical_or(input, other, *, out=None)Elementwise OR of the inputs' truth values (nonzero is True); bool.
logical_xor(input, other, *, out=None)Elementwise XOR of the inputs' truth values (nonzero is True); bool.
logit(input)log(x / (1 - x)). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
logsumexp(input, dim=None, keepdim=False, *, out=None)log(sum(exp(x))) over dim with the largest value taken out first; out= written. dim=[] reduces every dim, as sum(dim=[]) (set_compat("pytorch"): PyTorch's RuntimeError).
Different from PyTorch: dim=[] reduces every dim, as sum(dim=[]) does; PyTorch CPU and MPS raise RuntimeError
- PyTorch
- logsumexp(x, dim=[]) raises RuntimeError (output with shape [] doesn't match the broadcast shape)
- Riptorch
- dim=[] reduces every dim (the empty dim list means all, as for sum)
- Measured
- logsumexp([[1., 2.]], dim=[]): Riptorch 2.3132615, PyTorch CPU and MPS RuntimeError
- Stock behaviour
- torch.set_compat("pytorch")
lstsq(*a, _m='torch.lstsq is deprecated in favor of torch.linalg.lstsq and will be removed in a future PyTorch release.', **k)Removed from PyTorch: raises RuntimeError as PyTorch does (torch.lstsq is deprecated in favor of torch.linalg.lstsq and will be removed in a future PyTorch release.)
lt(input, other)Elementwise <, with broadcasting and PyTorch type promotion; returns bool. Every dtype; autograd for the floating-point types.
lu(self, pivot=True, get_infos=False)(LU, pivots) from linalg.lu_factor, plus zero infos with get_infos=True (deprecated in PyTorch).
lu_solve(b, LU_data, LU_pivots, *, out=None)torch.lu_solve(b, LU_data, LU_pivots) (deprecated in PyTorch): linalg.lu_solve with the arguments in the old order.
masked_fill(input, mask, value)value where mask is true, else the input; the result keeps the input's dtype.
masked_scatter(input, mask, source)A copy of input whose True positions of mask (broadcast), in row-major order, take source's leading elements.
masked_select(input, mask, *, out=None)The elements of input where mask (broadcast with it) is True, as a 1-d tensor in row-major order.
matmul(input, other)Different from PyTorch: exact integer products (int8 -> int32, int16/int32 -> int64) and int8 @ uint8; PyTorch wraps 200 of 200 entries of a 10x64 @ 64x20 int8 product (and its CPU float16 matmul is 249x slower), MLX has no integer matmul; fastest exact path at 4096 (quiet Mac, November 24, 2026): int8 x uint8 2.7 ms vs 136 ms PyTorch and 217 ms MLX, int16 10.2 vs 260 and 217; int8 @ int8 2.4 vs 3.2 ms (PyTorch MPS _int_mm, alternating runs)
- PyTorch
- integer matmul keeps the input dtype and wraps modulo 2^bits silently (int8, int16, int32, uint8: 200 of 200 entries wrong on 10x64 @ 64x20); int8 @ uint8 raises; float16 / bfloat16 on the CPU run 213x-836x slower than float32
- Riptorch
- exact: int8 / uint8 -> int32, int16 / int32 -> int64 (CPU matrix unit, GPU int8 hardware); int8 @ uint8 exact int32; 16-bit floats on the matrix unit (0.30 ms vs 74.7 ms at 512)
- Measured
- 200/200 wrong (PyTorch) vs 0 (Riptorch) per dtype; fp16 512x512 74.7 ms vs 0.30 ms
- Stock behaviour
- torch.set_compat("pytorch")
matrix_exp(A)linalg.matrix_exp(A): Pade-13 scaling and squaring (Higham 2005). Gradient: the exponential of the block matrix [[A^T, G], [0, A^T]] (its top-right block).
matrix_power(A, n, *, out=None)linalg.matrix_power(A, n): repeated squaring (n < 0: of the inverse); n = 0 gives the identity.
max(*a, **k)max(Tensor self, dim=None, bool keepdim=False)
max(x) is the largest value; max(x, dim) is (values, indices); max(x, y) is the elementwise maximum.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
maximum(input, other)Elementwise maximum of two tensors; a NaN in either input gives NaN, as in PyTorch. Every dtype; autograd for the floating-point types.
mean(Tensor self, int[]? dim=None, bool keepdim=False, *, dtype? dtype=None) -> TensorMean over all elements or along dim; dtype= casts first. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
median(input, dim=None, keepdim=False, *, out=None)The lower median (PyTorch's: not the mean of the two middle values), and with dim its index; NaN propagates.
min(*a, **k)min(Tensor self, dim=None, bool keepdim=False)
min(x): the smallest element; min(x, dim): (values, indices); min(x, y): the elementwise minimum.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
minimum(input, other)Elementwise minimum of two tensors; a NaN in either input gives NaN, as in PyTorch. Every dtype; autograd for the floating-point types.
mm(input, mat2, *, out=None)Matrix product of two 2-d tensors; a sparse operand goes to the sparse product (dense result for sparse @ dense, as PyTorch).
Different from PyTorch: exact integer products like torch.matmul; PyTorch keeps the input dtype and wraps (200 of 200 int8 entries wrong on 10x64 @ 64x20)
- PyTorch
- integer mm keeps the input dtype and wraps modulo 2^bits
- Riptorch
- exact (as torch.matmul)
- Measured
- as torch.matmul
- Stock behaviour
- torch.set_compat("pytorch")
mode(input, dim=-1, keepdim=False, *, out=None)The most frequent value along dim (the smallest on ties) and an index of it (its last occurrence, as PyTorch's CPU).
module_load(self, other, assign=False)What load_state_dict copies into this parameter: other (detached when assign=True).
moveaxis(input, source, destination)input with the dims at source moved to destination (ints or sequences), the others in order; a view.
movedim(*a, **k)input with the dims at source moved to destination (ints or sequences), the others in order; a view.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
mtia(self, device=None, non_blocking=False, memory_format=None)Raises AssertionError: no MTIA (as PyTorch does on a Mac).
mul(input, other)Elementwise product, with broadcasting and PyTorch type promotion. Every dtype; autograd for the floating-point types.
multinomial(self, num_samples, replacement=False, *, generator=None)Tensor.multinomial: torch.multinomial(self, num_samples, replacement).
mv(input, vec, *, out=None)Matrix-vector product (2-d @ 1-d); other ranks raise as PyTorch.
mvlgamma(input, p, *, out=None)The multivariate log-gamma function of dimension p: p(p-1)/4 log(pi) + sum_j lgamma(x - j/2).
nan_to_num(input, nan=0.0, posinf=None, neginf=None)NaN, +inf and -inf replaced by nan, posinf and neginf (default: 0 and the dtype's largest / smallest finite values).
nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None)Mean of the non-NaN elements, over dim or over all elements (NaN where every element is NaN). dtype= is accepted and ignored.
nanmedian(input, dim=None, keepdim=False, *, out=None)The lower median of the non-NaN elements (NaN only when all are NaN); with dim, (values, indices).
Computed from the values read back: not differentiable.
nanquantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None)quantile ignoring NaN: NaN only where a row has no other values.
nansum(input, dim=None, keepdim=False, *, dtype=None)Sum with NaN counted as zero, over dim or over all elements. dtype= is accepted and ignored.
narrow(Tensor self, int dim, int start, int length) -> TensorThe slice [start, start + length) along dim. Dtypes: every dtype (autograd for the floating-point types).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
narrow_copy(self, dim, start, length)narrow(dim, start, length) as a new tensor.
ne(input, other)Elementwise !=, with broadcasting and PyTorch type promotion; returns bool. Every dtype; autograd for the floating-point types.
negative(input)-x (alias of neg). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
new(self, *args)Legacy constructor in self's dtype: new(data_list) builds from data, new(*size) a zero-filled tensor.
new_empty_strided(self, size, stride, *, dtype=None, **kw)A zero-filled tensor of size in self's dtype; stride is ignored (contiguous layout).
nextafter(input, other, *, out=None)The next representable value after input in the direction of other, in input's float type (one float32 ulp for float32, one float64 ulp for float64); NaN if either is NaN.
nonzero(self, *, as_tuple=False)torch.nonzero(self, as_tuple=as_tuple).
nonzero_static(input, *, size, fill_value=-1)nonzero cut or padded to exactly size rows (padding rows filled with fill_value), int64 (n, input.dim).
norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None)torch.norm / Tensor.norm (deprecated in PyTorch): 'nuc' and 'fro' over two dims are matrix norms; everything else is the vector norm it always was.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
not_equal(input, other)Alias of Tensor.ne.
Elementwise !=, with broadcasting and PyTorch type promotion; returns bool. Every dtype; autograd for the floating-point types.
orgqr(A, tau, *, out=None)linalg.householder_product(A, tau): the first n columns of H_1... H_k (LAPACK orgqr).
ormqr(input, tau, other, left=True, transpose=False, *, out=None)torch.ormqr(a, tau, C, left=True, transpose=False): C multiplied by Q from geqrf's reflectors.
outer(input, vec2, *, out=None)The outer product of two vectors (ger too).
permute(input, *dims)Reorders the dimensions. Dtypes: every dtype (autograd for the floating-point types).
pin_memory(self, *args, **kwargs)Tensor.cpu / cuda / mps / pin_memory: the tensor itself (one unified memory and one layout).
pinverse(input, rcond=1e-15)torch.pinverse: linalg.pinv with rtol=rcond.
polygamma(self, n)torch.polygamma(n, self): the n-th derivative of digamma.
positive(input)x unchanged. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
prod(input, dim=None, keepdim=False, *, dtype=None)Product of the elements, over dim or over all of them; dtype= casts first.
Floats go through cumprod (differentiable). Integers and bool are multiplied exactly in Python integers and returned as int64.
put(input, index, source, accumulate=False)A copy of input with the flat positions index set to source's values (accumulate=True: added instead).
q_per_channel_axis(input)The per-channel axis of a quantized tensor (raises for a float tensor, as PyTorch).
q_per_channel_scales(input)The per-channel scales of a quantized tensor (raises for a float tensor, as PyTorch).
q_per_channel_zero_points(input)The per-channel zero points of a quantized tensor (raises for a float tensor).
q_scale(input)The scale of a per-tensor quantized tensor (raises for a float tensor, as PyTorch).
q_zero_point(input)The zero point of a per-tensor quantized tensor (raises for a float tensor, as PyTorch).
qr(A, some=True, *, out=None)torch.qr (deprecated in PyTorch): linalg.qr with mode 'reduced' (some=True) or 'complete'.
qscheme(name)The quantization scheme of a quantized tensor (raises for a float tensor, as PyTorch).
quantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None, _nan=False)The q-th quantiles (q a float or a 1-d tensor, each in [0, 1]) over dim or over all elements.
interpolation: 'linear' (default), 'lower', 'higher', 'nearest' or 'midpoint'. A NaN in a row gives NaN. With a tensor q the quantiles stack along a new leading dim. Computed from the sorted values read back: not differentiable.
rad2deg(input)Radians to degrees. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
reciprocal(input)1 / x. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
record_stream(self, stream)Nothing to do: Riptorch has no device streams to track.
register_post_accumulate_grad_hook(self, hook)Same as PyTorch’s torch.Tensor.register_post_accumulate_grad_hook.
reinforce(self, reward)Removed in PyTorch: raises its RuntimeError (use torch.distributions).
relu(input, inplace=False)max(x, 0). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
remainder(input, other, *, out=None)Different from PyTorch: float32 remainder is one rounding of the exact x - floor(x / y) y for every input: 0 of 20000 random pairs wrong where PyTorch MPS gets 10511 wrong (and remainder(7, -inf) is nan there)
- PyTorch
- CPU: correctly rounded too; MPS: 10511 of 20000 random pairs wrong, remainder(7, -inf) = nan
- Riptorch
- the exact remainder rounded once (one rounding, the divisor's sign), on every device
- Measured
- 20000 random float32 pairs, x up to 1e12, y down to 1e-6: Riptorch 0 wrong, PyTorch CPU 0, PyTorch MPS 10511 (8293 in the rules doc's sample)
- Stock behaviour
- none: PyTorch's CPU kernel already gives these values; MPS's errors are not reproduced
renorm(input, p, dim, maxnorm)input with each slice along dim (taken over all other dims) scaled down so its p-norm is at most maxnorm (scale maxnorm / (norm + 1e-7), as PyTorch).
repeat(input, *repeats)Tensor.repeat: the tensor tiled repeats[i] times along each dim (leading new dims allowed); lazy, gradients summed back.
repeat_interleave(self, repeats=None, dim=None, *, output_size=None)torch.repeat_interleave(self, repeats, dim).
resize(self, *size)A tensor of the given size from self's elements in row-major order, cut short or extended with zeros (deprecated in PyTorch; a new tensor here).
resolve_conj(self)self: there is never a lazy conjugate or negation to resolve.
resolve_neg(self)self: there is never a lazy conjugate or negation to resolve.
roll(Tensor input, int[] shifts, int[] dims=()) -> TensorEach dim rotated by its shift: two narrows joined by cat. No dims: the flattened tensor, as PyTorch.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
rot90(input, k=1, dims=(0, 1))input rotated by 90 degrees k times in the plane of dims, from the first dim towards the second.
row_indices(self, *a, **k)Raises RuntimeError as PyTorch on a dense tensor: row_indices needs a sparse column compressed tensor.
rsqrt(input)Classic only: as an elementwise op it has no rational form (the rational RMSNorm is a module-level row).
scatter(input, dim, index, src=None, *, value=None, reduce=None)A copy of input with src (or the scalar value) written at index along dim; reduce='add' / 'sum' adds and 'multiply' / 'prod' multiplies into the existing values instead of overwriting.
scatter_add(input, dim, index, src)scatter with reduce='add': repeated indices accumulate.
scatter_reduce(input, dim, index, src, reduce, *, include_self=True)A copy of input with src reduced into it at index along dim: reduce is 'sum', 'prod', 'mean', 'amax' or 'amin'; include_self=False leaves input's values out of the reduction. Integer 'mean' rounds down. Computed on the values (not differentiable).
select(*a, **k)The slice at index along dim, with dim removed; negative indices count from the end; IndexError outside.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
select_scatter(input, src, dim, index)A copy of input with input.select(dim, index) replaced by src.
sgn(input)-1, 0 or 1 by sign (sgn too). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
sigmoid(input, *, maths=None)1 / (1 + exp(-x)). Under maths="rational": (1 + softsign(x)) / 2, order 2 (a different function in the same role). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
signbit(input, *, out=None)True where the sign bit is set: negative values and -0.0 (integers: x < 0).
sin(input)Different from PyTorch: float32 sin within 1 ulp on [-100, 100]: worst 0.64 ulps of the exact value where PyTorch's CPU kernel has 1.71 (CPU and MPS: 2 ulps after rounding)
- PyTorch
- float32 sin up to 2 ulps off
- Riptorch
- argument reduction by pi/2 in parts and a polynomial in float32 (Riptide sin node)
- Measured
- 1500 points of [-100, 100]: Riptorch 0.64, PyTorch CPU 1.71 ulps of the exact value max 1 vs 2 ulps
- Stock behaviour
- none: an accuracy gain, PyTorch's rounding is not reproduced
sinh(input)Hyperbolic sine. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
slice_inverse(input, src, dim=0, start=None, end=None, step=1)The base a slice was taken from (for functionalization): src, viewed as itself.
slice_scatter(input, src, dim=0, start=None, end=None, step=1)A copy of input with the slice start:end:step of dim replaced by src.
slogdet(A, *, out=None, maths=None)Same as PyTorch’s torch.Tensor.slogdet.
smm(self, mat2)torch.smm(self, mat2): sparse self @ dense mat2, returned sparse (a dense self raises).
softmax(Tensor input, int? dim=None, *, dtype? dtype=None) -> TensorAlso takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
solve(*a, _m='torch.solve is deprecated in favor of torch.linalg.solve and will be removed in a future PyTorch release.', **k)Removed from PyTorch: raises RuntimeError as PyTorch does (torch.solve is deprecated in favor of torch.linalg.solve and will be removed in a future PyTorch release.)
sort(Tensor self, int dim=-1, bool descending=False, *, bool? stable=False) -> (Tensor values, Tensor indices)Always stable (equal values keep their order), so stable=False gives the stable order too.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
sparse_mask(d, mask)dense.sparse_mask(mask): mask's pattern with d's values there.
split(Tensor self, split_size_or_sections, int dim=0) -> Tensor[]Pieces are narrows: lazy views with gradients on float32 tensors.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
split_with_sizes(input, split_sizes, dim=0)Consecutive pieces of input along dim with the given sizes, as a tuple.
sqrt(input)Elementwise square root (NaN below 0). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
square(input)x * x. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
squeeze(Tensor self, dim=None) -> TensorRemoves size-1 dimensions (all, or the given dim / dims when they have size 1).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
sspaddmm(self, mat1, mat2, *, beta=1, alpha=1)torch.sspaddmm(self, mat1, mat2): beta * self + alpha * (mat1 @ mat2), sparse.
std(input, dim=None, unbiased=None, keepdim=False, *, correction=None, out=None)Standard deviation over dim (all elements when dim is None): the square root of torch.var.
correction= (or unbiased=True / False for 1 / 0); PyTorch's positional std(x, dim) spelling is accepted.
stft(input, n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=None, return_complex=None, align_to_window=None)Short-time Fourier transform of a 1-d signal or a batch of them, through torch.fft.
Frames of n_fft samples every hop_length (default n_fft // 4), multiplied by window (centered and zero-padded when shorter than n_fft; ones by default); center=True pads n_fft // 2 on both sides with pad_mode. Output (freq, frames), onesided by default. return_complex must be given for real input, as PyTorch.
storage_offset(self)0: a Riptorch tensor always starts at the beginning of its own storage.
storage_type(self)The legacy storage class of this tensor's dtype (torch.FloatStorage for float32,...).
sub(input, other, *, alpha=1)self - alpha * other, with broadcasting and PyTorch type promotion. Every dtype; autograd for the floating-point types.
subtract(input, other, *, alpha=1)torch.subtract(self, *args, **kwargs).
sum(*a, **k)Different from PyTorch: float64 sums compensated: the sum of 1e5 normal values is 3.39e-15 off the exact sum where PyTorch's is 5.35e-14 (1e6 values: 3.05e-14 vs 7.13e-13)
- PyTorch
- float64 sum by pairwise blocks in float64
- Riptorch
- float64 CPU programs sum with compensation (an error term carried with the running sum)
- Measured
- 2026-11-24: 1e5 normal values 3.39e-15 vs 5.35e-14 absolute error; 1e6: 3.05e-14 vs 7.13e-13
- Stock behaviour
- none: an accuracy gain, PyTorch's rounding is not reproduced
sum_to_size(input, *size)input summed down to size: leading extra dims summed away, dims that are 1 in size summed with keepdim (the reverse of broadcasting).
svd(A, some=True, compute_uv=True, *, out=None)torch.svd (deprecated in PyTorch): (U, S, V) with V not transposed; some=False gives the full U and V; compute_uv=False gives zero U and V, as PyTorch.
swapaxes(Tensor self, int dim0, int dim1) -> TensorSwaps two dimensions (swapaxes too). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
swapdims(Tensor self, int dim0, int dim1) -> TensorAlias of Tensor.transpose.
Swaps two dimensions (swapaxes too). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
symeig(*a, _m='This function was deprecated since version 1.9 and is now removed. Please use the `torch.linalg.eigh` function instead.', **k)Removed from PyTorch: raises RuntimeError as PyTorch does (This function was deprecated since version 1.9 and is now removed. Please use the torch.linalg.eigh function instead.)
t(self)The transpose of a 2-d tensor; 0-d and 1-d tensors are returned as they are; more dims raise.
take(input, index)input's elements at the given flat indices (input read as 1-d), shaped like index.
take_along_dim(*a, **k)input's values at indices along dim, input and indices broadcast on the other dims; dim=None takes from the flattened input.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
tan(input)Elementwise tangent. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
tensor_split(input, indices_or_sections, dim=0)input cut along dim into a tuple of pieces: an int k gives k pieces of near-equal size (the first n % k one longer); a list or tensor of indices cuts before each of them.
tile(input, dims)input repeated dims[i] times along each dimension; a dims shorter than input's rank is padded with leading 1s.
to_dense(self, dtype=None, *, masked_grad=None)Different from PyTorch: duplicate entries summed in float64 and rounded once: duplicates [1e8, 1, -1e8] give 1.0, PyTorch gives 0.0
- PyTorch
- a sparse tensor's duplicate entries summed in the values' dtype, in order
- Riptorch
- duplicates summed in float64, rounded once (coalesced entries placed as they are)
- Measured
- duplicates [1e8, 1, -1e8] at one position: PyTorch 0.0, Riptorch 1.0
- Stock behaviour
- torch.set_compat("pytorch")
to_mkldnn(self, dtype=None)Raises RuntimeError("MKL-DNN build is disabled"), as PyTorch does on a Mac.
to_padded_tensor(self, padding, output_size=None)torch.nested.to_padded_tensor(self, padding, output_size) (a dense self raises as PyTorch).
to_sparse(self, *args, layout=None, blocksize=None, dense_dim=None)This dense tensor as a sparse one: COO by default (args[0] = sparse_dim: the leading dims that become sparse), or layout= (blocksize= for BSR / BSC). Zeros are not stored.
to_sparse_bsc(self, blocksize, dense_dim=None)This dense tensor in the BSC sparse layout (zeros not stored; blocksize = (rows, cols)).
to_sparse_bsr(self, blocksize, dense_dim=None)This dense tensor in the BSR sparse layout (zeros not stored; blocksize = (rows, cols)).
to_sparse_coo(self)This dense tensor in the COO sparse layout (zeros not stored).
to_sparse_csc(self, dense_dim=None)This dense tensor in the CSC sparse layout (zeros not stored).
to_sparse_csr(self, dense_dim=None)This dense tensor in the CSR sparse layout (zeros not stored).
topk(Tensor self, int k, int dim=-1, bool largest=True, bool sorted=True) -> (Tensor values, Tensor indices)Partial selection on every core (no full sort for small k) or the GPU; values keep gradients. Results are always sorted (sorted=False is allowed and returns them sorted). Top-k of a score matrix made as an outer product (cosine_similarity(Q[:, None], X[None]), q @ X.T) runs the fused search: the scores are never all computed.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
transpose(Tensor self, int dim0, int dim1) -> TensorSwaps two dimensions (swapaxes too). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
triangular_solve(b, A, upper=True, transpose=False, unitriangular=False, *, out=None)torch.triangular_solve(b, A, upper=True, transpose=False, unitriangular=False) (deprecated in PyTorch).
true_divide(input, other, *, rounding_mode=None)Division, true by default; rounding_mode="trunc" or "floor" rounds the quotient. Integer inputs give float32, as PyTorch. Every dtype; autograd for the floating-point types.
trunc(input)Rounds toward zero (fix too). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
unbind(*a, **k)A tuple of the slices along dim, each without dim.
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
unflatten(input, dim, sizes)input with dim replaced by the given sizes (one of them may be -1).
unfold(input, dimension, size, step)Tensor.unfold: every window of size along dimension, step apart, as a new last dim.
unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None)The distinct values (or distinct slices along dim), sorted; optionally the inverse indices and the counts. sorted=False returns sorted values too (as PyTorch on the CPU for dim=None).
unique_consecutive(input, return_inverse=False, return_counts=False, dim=None)input with runs of equal consecutive values collapsed to one; optionally the inverse indices and run lengths. dim= raises NotImplementedError.
Different from PyTorch: input with runs of equal consecutive values collapsed to one; optionally the inverse indices and run lengths. dim= raises NotImplementedError.
unsafe_chunk(self, chunks, dim=0)chunk (the same pieces; nothing is unsafe here).
unsafe_split(self, split_size, dim=0)split (the same pieces; nothing is unsafe here).
unsafe_split_with_sizes(self, sizes, dim=0)split_with_sizes (the same pieces; nothing is unsafe here).
unsqueeze(Tensor self, int dim) -> TensorInserts a size-1 dimension at dim (negative dims count from the end of the result). Dtypes: every dtype (autograd for the floating-point types).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
values(self)Raises RuntimeError as PyTorch on a dense tensor: values needs a sparse tensor.
var(Tensor self, int[]? dim=None, *, float correction=1, bool keepdim=False, bool? unbiased=None) -> TensorVariance over all elements or along dim with Bessel's correction (correction=, or unbiased=). Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
Also takes NumPy's axis= / keepdims= for dim= / keepdim=, as PyTorch.
vdot(input, other, *, out=None)Dot product of the flattened inputs: sum(input * other). Complex input is not conjugated (PyTorch conjugates the first argument).
where(self, condition, other)Tensor.where(condition, other): self where condition holds, else other.
xlogy(input, other)x * log(y), 0 where x is 0. Dtypes: float32, float64, float16 and bfloat16 (autograd for the floating-point types).
xpu(self, device=None, non_blocking=False, memory_format=None)Raises AssertionError: no XPU (as PyTorch does on a Mac).
In-place methods
abs_(input)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
absolute_(input)absolute in place: self takes the result of absolute(self,...); returns self.
acos_(input, *, out=None)acos in place: self takes the result of acos(self,...); returns self.
acosh_(input)acosh in place: self takes the result of acosh(self,...); returns self.
add_(input, other, *, alpha=1)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
addbmm_(self, b1, b2, *, beta=1, alpha=1)addbmm in place on self; returns self.
addcdiv_(input, tensor1, tensor2, *, value=1)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
addcmul_(input, tensor1, tensor2, *, value=1)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
addmm_(input, mat1, mat2, *, beta=1, alpha=1)addmm in place: self takes the result of addmm(self,...); returns self.
addmv_(input, mat, vec, *, beta=1, alpha=1, out=None)addmv in place: self takes the result of addmv(self,...); returns self.
addr_(input, vec1, vec2, *, beta=1, alpha=1, out=None)addr in place: self takes the result of addr(self,...); returns self.
apply_(self, fn)In place: each element x becomes fn(x) (a Python callable, run on the values read back).
arccos_(input, *, out=None)arccos in place: self takes the result of arccos(self,...); returns self.
arccosh_(input)arccosh in place: self takes the result of arccosh(self,...); returns self.
arcsin_(input, *, out=None)arcsin in place: self takes the result of arcsin(self,...); returns self.
arcsinh_(input)arcsinh in place: self takes the result of arcsinh(self,...); returns self.
arctan2_(input, other, *, out=None)arctan2 in place: self takes the result of arctan2(self,...); returns self.
arctan_(input, *, out=None)arctan in place: self takes the result of arctan(self,...); returns self.
arctanh_(input)arctanh in place: self takes the result of arctanh(self,...); returns self.
as_strided_(input, size, stride, storage_offset=None)In-place as_strided: the tensor becomes the strided view's values (Riptorch copies; no shared storage).
asin_(input, *, out=None)asin in place: self takes the result of asin(self,...); returns self.
asinh_(input)asinh in place: self takes the result of asinh(self,...); returns self.
atan2_(input, other, *, out=None)In-place Tensor.atan2: the result written into self (self's dtype kept).
atan_(input, *, out=None)In-place Tensor.atan: the result written into self (self's dtype kept).
atanh_(input)atanh in place: self takes the result of atanh(self,...); returns self.
baddbmm_(input, batch1, batch2, *, beta=1, alpha=1, out=None)baddbmm in place: self takes the result of baddbmm(self,...); returns self.
bernoulli_(self, p=0.5, *, generator=None)Tensor.bernoulli_(p=0.5): fills with 1 with probability p (a float or a tensor broadcast to self), else 0. In place; the dtype is kept.
bitwise_and_(input, other)bitwise_and in place: self takes the result of bitwise_and(self,...); returns self.
bitwise_left_shift_(self, other)bitwise_left_shift in place; returns self.
bitwise_not_(input)bitwise_not in place: self takes the result of bitwise_not(self,...); returns self.
bitwise_or_(input, other)bitwise_or in place: self takes the result of bitwise_or(self,...); returns self.
bitwise_right_shift_(self, other)bitwise_right_shift in place; returns self.
bitwise_xor_(input, other)bitwise_xor in place: self takes the result of bitwise_xor(self,...); returns self.
cauchy_(self, median=0.0, sigma=1.0, *, generator=None)Tensor.cauchy_(median=0, sigma=1): fills with Cauchy draws, median + sigma tan(pi (U - 1/2)). In place.
ceil_(input)ceil in place: self takes the result of ceil(self,...); returns self.
clamp_(input, min=None, max=None)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
clamp_max_(input, max)clamp_max in place: self takes the result of clamp_max(self,...); returns self.
clamp_min_(input, min)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
clip_(input, min=None, max=None)clip in place: self takes the result of clip(self,...); returns self.
conj_physical_(input)In-place conjugate; real tensors are returned unchanged.
copy_(self, src, non_blocking=False)Writes src (broadcast, converted to this dtype) into this tensor in place; a view writes through.
copysign_(input, other, *, out=None)copysign in place: self takes the result of copysign(self,...); returns self.
cos_(input)cos in place: self takes the result of cos(self,...); returns self.
Different from PyTorch: float32 cos within 1 ulp of the correctly rounded value: worst 1.08 ulps of the exact value on [-100, 100] where PyTorch's CPU kernel has 1.57 (CPU and MPS: 2 ulps after rounding)
- PyTorch
- float32 cos up to 2 ulps off
- Riptorch
- float32: sin(x + pi/2) with the roundings of x + pi/2 and of pi/2 put back; float64: Cody-Waite reduction by pi/2 in three parts
- Measured
- 1500 points of [-100, 100]: Riptorch 1.08, PyTorch CPU 1.57 ulps of the exact value max 1 vs 2 ulps on [-1e-3, 1e-3], [1.5, 1.65], [-100, 100]
- Stock behaviour
- none: an accuracy gain, PyTorch's rounding is not reproduced
cosh_(input)cosh in place: self takes the result of cosh(self,...); returns self.
cumprod_(self, *a, **k)In-place Tensor.cumprod: the result written into self (self's dtype kept).
cumsum_(self, dim, *, dtype=None)In-place torch.cumsum(self, dim, dtype=dtype); the dtype is kept.
deg2rad_(input)deg2rad in place: self takes the result of deg2rad(self,...); returns self.
digamma_(self)In-place torch.digamma: the result written into self (self's dtype kept).
Different from PyTorch: correctly rounded float32 values (computed in float64, rounded once); 1499 inputs in [-4.9, 5.7]: worst 125285 ulp (PyTorch) vs 0; MLX has no digamma
- PyTorch
- float32 kernels in float32 precision: values off by several ulp
- Riptorch
- computed in float64, rounded once to float32 (correctly rounded)
- Measured
- float32: 1499 inputs in [-4.9, 5.7]: worst 125285 ulp (PyTorch) vs 0
- Stock behaviour
- not reproduced: PyTorch's values come from its own float32 polynomial kernels, which Riptorch does not copy (compat keeps Riptorch's correctly rounded values)
div_(input, other, *, rounding_mode=None)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
divide_(input, other, *, rounding_mode=None)divide in place: self takes the result of divide(self,...); returns self.
eq_(input, other)eq in place: self takes the result of eq(self,...); returns self.
erf_(input)erf in place: self takes the result of erf(self,...); returns self.
erfc_(input)erfc in place: self takes the result of erfc(self,...); returns self.
erfinv_(self)In-place torch.erfinv: the result written into self (self's dtype kept).
Different from PyTorch: correctly rounded float32 values (computed in float64, rounded once); 1999 inputs in [0.9999, 1]: every value off, worst 127 ulp vs 0; MLX's GPU erfinv is up to 3 ulp off there
- PyTorch
- float32 kernels in float32 precision: values off by several ulp
- Riptorch
- computed in float64, rounded once to float32 (correctly rounded)
- Measured
- float32: 1999 inputs in [0.9999, 1]: every value off, worst 127 ulp vs 0
- Stock behaviour
- not reproduced: PyTorch's values come from its own float32 polynomial kernels, which Riptorch does not copy (compat keeps Riptorch's correctly rounded values)
exp2_(input)exp2 in place: self takes the result of exp2(self,...); returns self.
exp_(input)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
expm1_(input)expm1 in place: self takes the result of expm1(self,...); returns self.
exponential_(self, lambd=1.0, *, generator=None)Tensor.exponential_(lambd=1): fills with Exponential(rate lambd) draws, -log1p(-U) / lambd. In place.
fill_(tensor, val)Fills the tensor in place with val (Tensor.fill_ too). Every dtype.
fill_diagonal_(self, fill_value, wrap=False)In place: the main diagonal (all indices equal) set to fill_value; wrap=True continues a tall 2-d matrix's diagonal every ncols + 1 rows, as PyTorch. Returns self.
fix_(input)fix in place: self takes the result of fix(self,...); returns self.
float_power_(input, exponent)float_power in place: self takes the result of float_power(self,...); returns self.
floor_(input)floor in place: self takes the result of floor(self,...); returns self.
floor_divide_(input, other, *, out=None)In-place Tensor.floor_divide: the result written into self (self's dtype kept).
fmod_(input, other, *, out=None)In-place Tensor.fmod: the result written into self (self's dtype kept).
frac_(input)In-place Tensor.frac: the result written into self (self's dtype kept).
gcd_(input, other, *, out=None)gcd in place: self takes the result of gcd(self,...); returns self.
ge_(input, other)ge in place: self takes the result of ge(self,...); returns self.
geometric_(self, p, *, generator=None)Tensor.geometric_(p): fills with Geometric(p) draws (trials to the first success, from 1). In place.
greater_(input, other)greater in place: self takes the result of greater(self,...); returns self.
greater_equal_(input, other)greater_equal in place: self takes the result of greater_equal(self,...); returns self.
gt_(input, other)gt in place: self takes the result of gt(self,...); returns self.
heaviside_(input, values, *, out=None)heaviside in place: self takes the result of heaviside(self,...); returns self.
hypot_(input, other)hypot in place: self takes the result of hypot(self,...); returns self.
i0_(self)In-place torch.i0: the result written into self (self's dtype kept).
Different from PyTorch: correctly rounded float32 values (computed in float64, rounded once); 1500 inputs in [0, 75]: worst 3 ulp vs 0; MLX has no i0
- PyTorch
- float32 kernels in float32 precision: values off by several ulp
- Riptorch
- computed in float64, rounded once to float32 (correctly rounded)
- Measured
- float32: 1500 inputs in [0, 75]: worst 3 ulp vs 0
- Stock behaviour
- not reproduced: PyTorch's values come from its own float32 polynomial kernels, which Riptorch does not copy (compat keeps Riptorch's correctly rounded values)
igamma_(input, other, *, out=None)igamma in place: self takes the result of igamma(self,...); returns self.
igammac_(input, other, *, out=None)igammac in place: self takes the result of igammac(self,...); returns self.
index_add_(input, dim, index, source, *, alpha=1)In-place Tensor.index_add: the result written into self (self's dtype kept).
Different from PyTorch: repeated indices summed in float64 and rounded once: [1e8, 1, -1e8] at one index gives 1.0, PyTorch's float32 sum gives 0.0
- PyTorch
- adds source's slices one after another in the input's dtype (float32: 1e8 + 1 - 1e8 = 0)
- Riptorch
- without gradients, one CPU pass summing in float64, rounded once (any n x k); with gradients, the float32 one-hot product in blocks
- Measured
- [1e8, 1, -1e8] added at index 0 of zeros(2): PyTorch 0.0, Riptorch 1.0 (the exact sum)
- Stock behaviour
- torch.set_compat("pytorch")
index_copy_(input, dim, index, source)In-place Tensor.index_copy: the result written into self (self's dtype kept).
index_fill_(input, dim, index, value)In-place Tensor.index_fill: the result written into self (self's dtype kept).
index_put_(input, indices, values, accumulate=False)index_put in place: self takes the result of index_put(self,...); returns self.
Different from PyTorch: accumulate=True sums repeated positions in float64 and rounds once: [1e8, 1, -1e8] at one position gives 1.0, PyTorch gives 0.0
- PyTorch
- accumulate=True adds the values one after another in the input's dtype
- Riptorch
- accumulate=True: index_add's float64 sum, rounded once
- Measured
- [1e8, 1, -1e8] put at position 0 of zeros(2) with accumulate=True: PyTorch 0.0, Riptorch 1.0; run to run, index_put_(accumulate=True) gives one result in 20 runs where PyTorch CPU and MPS give 20 different ones
- Stock behaviour
- torch.set_compat("pytorch")
index_reduce_(self, dim, index, source, reduce, *, include_self=True)index_reduce in place; returns self.
lcm_(input, other, *, out=None)lcm in place: self takes the result of lcm(self,...); returns self.
ldexp_(input, other, *, out=None)ldexp in place: self takes the result of ldexp(self,...); returns self.
le_(input, other)le in place: self takes the result of le(self,...); returns self.
lerp_(input, end, weight)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
less_(input, other)less in place: self takes the result of less(self,...); returns self.
less_equal_(input, other)less_equal in place: self takes the result of less_equal(self,...); returns self.
lgamma_(self)In-place torch.lgamma: the result written into self (self's dtype kept).
log10_(input)log10 in place: self takes the result of log10(self,...); returns self.
log1p_(input)log1p in place: self takes the result of log1p(self,...); returns self.
log2_(input)log2 in place: self takes the result of log2(self,...); returns self.
log_(input)log in place: self takes the result of log(self,...); returns self.
log_normal_(self, mean=1.0, std=2.0, *, generator=None)Tensor.log_normal_(mean=1, std=2): fills with exp(N(mean, std)) draws. In place.
logical_and_(self, *a, **k)logical_and in place: self takes the result of logical_and(self,...); returns self.
logical_not_(self, *a, **k)logical_not in place: self takes the result of logical_not(self,...); returns self.
logical_or_(self, *a, **k)logical_or in place: self takes the result of logical_or(self,...); returns self.
logical_xor_(input, other, *, out=None)logical_xor in place: self takes the result of logical_xor(self,...); returns self.
logit_(input)logit in place: self takes the result of logit(self,...); returns self.
lt_(input, other)lt in place: self takes the result of lt(self,...); returns self.
map2_(self, x, y, fn)In place: each element a becomes fn(a, b, c), b and c the matching elements of x and y broadcast to self.
map_(self, other, fn)In place: each element x becomes fn(x, y), y the matching element of other broadcast to self.
masked_scatter_(input, mask, source)masked_scatter in place: self takes the result of masked_scatter(self,...); returns self.
mul_(input, other)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
multiply_(input, other)multiply in place: self takes the result of multiply(self,...); returns self.
mvlgamma_(input, p, *, out=None)mvlgamma in place: self takes the result of mvlgamma(self,...); returns self.
nan_to_num_(input, nan=0.0, posinf=None, neginf=None)nan_to_num in place: self takes the result of nan_to_num(self,...); returns self.
ne_(input, other)ne in place: self takes the result of ne(self,...); returns self.
neg_(input)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
negative_(input)negative in place: self takes the result of negative(self,...); returns self.
nextafter_(input, other, *, out=None)nextafter in place: self takes the result of nextafter(self,...); returns self.
normal_(tensor, mean=0.0, std=1.0, generator=None)Fills the tensor in place with normal draws N(mean, std). Dtypes: float32.
not_equal_(input, other)not_equal in place: self takes the result of not_equal(self,...); returns self.
polygamma_(n, input, *, out=None)polygamma in place: self takes the result of polygamma(self,...); returns self.
pow_(input, exponent)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
put_(input, index, source, accumulate=False)put in place: self takes the result of put(self,...); returns self.
rad2deg_(input)rad2deg in place: self takes the result of rad2deg(self,...); returns self.
random_(self, from_=0, to=None, *, generator=None)Tensor.random_([from_,] to): fills with integers drawn uniformly from [from_, to); without to, from [0, the largest integer the dtype holds exactly + 1) as PyTorch (2^24 + 1 for float32, 2^63 for int64). In place.
reciprocal_(input)reciprocal in place: self takes the result of reciprocal(self,...); returns self.
relu_(Tensor self, bool inplace=False) -> TensorIn-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
remainder_(input, other, *, out=None)In-place Tensor.remainder: the result written into self (self's dtype kept).
Different from PyTorch: float32 remainder is one rounding of the exact x - floor(x / y) y for every input: 0 of 20000 random pairs wrong where PyTorch MPS gets 10511 wrong (and remainder(7, -inf) is nan there)
- PyTorch
- CPU: correctly rounded too; MPS: 10511 of 20000 random pairs wrong, remainder(7, -inf) = nan
- Riptorch
- the exact remainder rounded once (one rounding, the divisor's sign), on every device
- Measured
- 20000 random float32 pairs, x up to 1e12, y down to 1e-6: Riptorch 0 wrong, PyTorch CPU 0, PyTorch MPS 10511 (8293 in the rules doc's sample)
- Stock behaviour
- none: PyTorch's CPU kernel already gives these values; MPS's errors are not reproduced
renorm_(input, p, dim, maxnorm)renorm in place: self takes the result of renorm(self,...); returns self.
resize_(self, *size)In place: self takes the given size, keeping its elements in row-major order (cut short, or extended with zeros where PyTorch leaves memory uninitialized); returns self.
resize_as_sparse_(self, the_template)torch.resize_as_sparse_(self, the_template) (both sparse COO).
round_(input)round in place: self takes the result of round(self,...); returns self.
rsqrt_(input)rsqrt in place: self takes the result of rsqrt(self,...); returns self.
scatter_(input, dim, index, src=None, *, value=None, reduce=None)In-place Tensor.scatter: the result written into self (self's dtype kept).
scatter_add_(input, dim, index, src)In-place Tensor.scatter_add: the result written into self (self's dtype kept).
scatter_reduce_(input, dim, index, src, reduce, *, include_self=True)In-place Tensor.scatter_reduce: the result written into self (self's dtype kept).
set_(self, source=None, storage_offset=0, size=None, stride=None)self takes source's data (a tensor or a storage; with size / stride: that view of it). Riptorch tensors own their memory: the data is copied, not shared.
sgn_(input)sgn in place: self takes the result of sgn(self,...); returns self.
sigmoid_(input, *, maths=None)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
sign_(input)sign in place: self takes the result of sign(self,...); returns self.
sin_(input)sin in place: self takes the result of sin(self,...); returns self.
Different from PyTorch: float32 sin within 1 ulp on [-100, 100]: worst 0.64 ulps of the exact value where PyTorch's CPU kernel has 1.71 (CPU and MPS: 2 ulps after rounding)
- PyTorch
- float32 sin up to 2 ulps off
- Riptorch
- argument reduction by pi/2 in parts and a polynomial in float32 (Riptide sin node)
- Measured
- 1500 points of [-100, 100]: Riptorch 0.64, PyTorch CPU 1.71 ulps of the exact value max 1 vs 2 ulps
- Stock behaviour
- none: an accuracy gain, PyTorch's rounding is not reproduced
sinc_(self)In-place torch.sinc: the result written into self (self's dtype kept).
sinh_(input)sinh in place: self takes the result of sinh(self,...); returns self.
sparse_resize_(self, *a, **k)Raises RuntimeError as PyTorch on a dense tensor: sparse_resize_ needs a sparse coordinate tensor.
sparse_resize_and_clear_(self, *a, **k)Raises RuntimeError as PyTorch on a dense tensor: sparse_resize_and_clear_ needs a sparse coordinate tensor.
sqrt_(input)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
square_(input)square in place: self takes the result of square(self,...); returns self.
sub_(input, other, *, alpha=1)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
subtract_(input, other, *, alpha=1)subtract in place: self takes the result of subtract(self,...); returns self.
tan_(input)tan in place: self takes the result of tan(self,...); returns self.
tanh_(input, *, maths=None)In-place form: the out-of-place result written into self. Raises on a leaf that requires grad while grad mode is on, as PyTorch.
transpose_(self, a, b)transpose(a, b) in place; returns self.
true_divide_(input, other, *, rounding_mode=None)true_divide in place: self takes the result of true_divide(self,...); returns self.
trunc_(input)trunc in place: self takes the result of trunc(self,...); returns self.
uniform_(tensor, a=0.0, b=1.0, generator=None)Fills the tensor in place with uniform draws in [a, b). Dtypes: float32.
xlogy_(input, other)xlogy in place: self takes the result of xlogy(self,...); returns self.
zero_(tensor)Fills the tensor in place with zeros (Tensor.zero_ too). Every dtype.