MCPcopy Create free account
hub / github.com/NVIDIA/DALI / tensor

Function tensor

dali/python/nvidia/dali/experimental/dynamic/_tensor.py:986–1028  ·  view source on GitHub ↗

Copies an existing tensor-like object into a DALI tensor. Parameters ---------- data : TensorLike, default: None The data to construct the tensor from. It can be a tensor-like object, a (nested) list, TensorCPU/TensorGPU or other supported type. Supported types a

(
    data: TensorLike,
    dtype: Any | None = None,
    device: DeviceLike | None = None,
    layout: str | None = None,
    pad: bool = False,
)

Source from the content-addressed store, hash-verified

984
985@_call_site.mark_transparent
986def tensor(
987 data: TensorLike,
988 dtype: Any | None = None,
989 device: DeviceLike | None = None,
990 layout: str | None = None,
991 pad: bool = False,
992) -> Tensor:
993 """Copies an existing tensor-like object into a DALI tensor.
994
995 Parameters
996 ----------
997 data : TensorLike, default: None
998 The data to construct the tensor from. It can be a tensor-like object, a (nested) list,
999 TensorCPU/TensorGPU or other supported type.
1000 Supported types are:
1001
1002 - numpy arrays
1003 - torch tensors
1004 - types exposing __dlpack__ or __array__ interface
1005 - existing :class:`Tensor` objects
1006 dtype : DType, default: None
1007 The desired data type of the tensor. If not specified, the data type is inferred
1008 from the input data. If specified, the input data is cast to the desired data type.
1009 device : Device or str, optional, default: None
1010 The device on which the tensor should reside (e.g., "cpu" or "gpu").
1011 If not specified, the device is inferred from the input data.
1012 layout : str, optional, default: None
1013 The layout string describing the dimensions of the tensor (e.g., "HWC").
1014 If not specified, the layout is inferred from the input data, if possible.
1015 pad : bool, optional, default: False
1016 If ``True`` and `data` is a batch, the batch will be zero-padded.
1017 If ``False`` and `data` is a batch of non-uniformly shaped tensors, an error is raised.
1018 """
1019 from . import _batch
1020
1021 if isinstance(data, _batch.Batch):
1022 from . import _batch2tensor
1023
1024 return _batch2tensor.batch_to_tensor(
1025 data, pad=pad, dtype=dtype, layout=layout, device=device, force_copy=True
1026 )
1027
1028 return Tensor(data, dtype=dtype, device=device, layout=layout, copy=True)
1029
1030
1031@_call_site.mark_transparent

Callers 1

_imread_implFunction · 0.70

Calls 1

TensorClass · 0.70

Tested by

no test coverage detected