rlmesh.torch.as_tensor

functionExperimentalfrom rlmesh.torch import as_tensor[source]

Return a Torch tensor view or copy of an RLMesh tensor.

as_tensor(
    tensor: Tensor | bool | int | float,
    *,
    copy: bool = False,
) -> TorchTensor

Views 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

NameTypeDescription
tensorTensor | bool | int | floatRLMesh tensor or scalar primitive to convert.
copyboolIf True, copy tensor data before creating the Torch tensor.

Returns

TypeDescription
TorchTensorTorch tensor sharing the RLMesh tensor's memory via DLPack, or an
TorchTensorindependent copy when copy=True.