TensorPlay
API symbolsas_tensor
Copy
View MarkdownDownload .md

tensorplay.as_tensor

tensorplay.as_tensor(data, dtype=None, device=None)[source]

Convert data into a tensor, sharing storage when possible.

If data is already a tensor with the requested dtype and device, it is returned as-is (no copy). Otherwise it is converted, mirroring torch.as_tensor.

Parameters:
  • data (tensor, list, or scalar) – Initial data for the tensor.

  • dtype (tensorplay.DType, optional) – the desired data type of the returned tensor.

  • device (tensorplay.Device, str, optional) – the device of the constructed tensor.

Example:

>>> x = tensorplay.tensor([1.0, 2.0])
>>> tensorplay.as_tensor(x) is x
True
>>> tensorplay.as_tensor([0, 1, 2], dtype=tensorplay.int64).dtype == tensorplay.int64
True
Ask DeepWiki