warp.from_torch#
- warp.from_torch(
- t,
- dtype=None,
- requires_grad=None,
- grad=None,
- return_ctype=False,
- retain_grad=False,
Convert a PyTorch tensor to a Warp array without copying the data.
The resulting Warp array aliases the PyTorch tensor’s storage, so mutations through either view are visible from the other. Scalar Warp dtypes preserve the PyTorch tensor’s shape and strides. Vector and matrix Warp dtypes consume trailing component dimensions, and those trailing dimensions must be contiguous.
- Parameters:
t (torch.Tensor) – The PyTorch tensor to wrap.
dtype (type | None) – The target data type of the resulting Warp array. Defaults to the tensor value type mapped to a Warp array value type.
requires_grad (bool | None) – Whether the resulting array should wrap the tensor’s gradient, if it exists (the grad tensor will be allocated otherwise). Defaults to the tensor’s
requires_gradvalue.grad – Optional gradient array to attach to the result. Can be a Warp array or PyTorch tensor. If not provided and
requires_gradis True, the tensor’s gradient will be wrapped or allocated.return_ctype (bool) – Whether to return a low-level array descriptor instead of a
warp.arrayobject (faster). The descriptor can be passed to Warp kernels.retain_grad (bool) – Whether to preserve gradients during backward instead of zeroing after read.
- Returns:
The wrapped array or array descriptor.
- Return type:
warp.array | warp._src.types.array_t