warp.to_torch#

warp.to_torch(a, requires_grad=None)[source]#

Convert a Warp array to a PyTorch tensor without copying the data.

The returned PyTorch tensor aliases the Warp array’s storage. Clone the tensor if PyTorch must retain those values after Warp may modify or zero the underlying array.

Parameters:
  • a (array) – The Warp array to convert.

  • requires_grad (bool | None) – Whether the resulting tensor should convert the array’s gradient, if it exists, to a grad tensor. Defaults to the array’s requires_grad value.

Returns:

The converted PyTorch tensor.

Return type:

torch.Tensor