latest (dev)
Copy
Latest development documentation · Updated 2026-10-08
tensorplay.testing.make_tensor
- tensorplay.testing.make_tensor(*shape: int | Size | list[int] | tuple[int, ...], dtype: dtype, device: str | device, low: float | None = None, high: float | None = None, requires_grad: bool = False, noncontiguous: bool = False, exclude_zero: bool = False) Tensor[source]
Creates a tensor with the given
shape,device, anddtype, filled with values drawn uniformly from[low, high).If
loworhighare outside the range of thedtype’s representable finite values, they are clamped to the lowest or highest representable finite value, respectively. IfNone, they default to-9and9respectively (0and2forbool).- Parameters:
shape (Tuple[int, ...]) – Single integer or a collection of integers defining the shape of the output tensor.
dtype (tensorplay.dtype) – The data type of the returned tensor.
device (Union[str, tensorplay.device]) – The device of the returned tensor.
low (Optional[Number]) – Sets the lower limit of the range of the values in the returned tensor.
high (Optional[Number]) – Sets the upper limit of the range of the values in the returned tensor.
requires_grad (bool) – If
True, the returned tensor is set to require gradient.noncontiguous (bool) – If
True, the returned tensor is non-contiguous.exclude_zero (bool) – If
True, zeros in the returned tensor are replaced by the smallest normal value of the dtype (1for boolean and integral dtypes).
- Raises:
ValueError – If
low>=high, or if the interval[low, high)does not intersect the dtype’s representable range.TypeError – For unsupported dtypes.
Help improve this page
Found an error, an unclear step, or a missing example?

