rlmesh.torch.as_tensor
Return a Torch tensor view or copy of an RLMesh tensor.
as_tensor(
tensor: Tensor | bool | int | float,
*,
copy: bool = False,
) -> TorchTensorViews by default: without copy=True the result shares the tensor’s
memory (zero copy, via DLPack); with copy=True it owns a fresh,
writable buffer (exactly one copy). Scalar primitives
(bool/int/float) are accepted and become 0-d tensors (always
freshly constructed, never aliased).
Without copy=True the returned tensor shares memory with the
RLMesh tensor, and Torch will let you write through it even though
the export is flagged read-only (DLPack consumers may ignore that
flag). Mutating the view corrupts the RLMesh tensor – the wire
buffer – for every other view of the same data. Treat shared views
as read-only, and pass copy=True for any tensor you intend to
modify.
Parameters
| Name | Type | Description |
|---|---|---|
tensor | Tensor | bool | int | float | RLMesh tensor or scalar primitive to convert. |
copy | bool | If True, copy tensor data before creating the Torch tensor. |
Returns
| Type | Description |
|---|---|
TorchTensor | Torch tensor sharing the RLMesh tensor's memory via DLPack, or an |
TorchTensor | independent copy when copy=True. |