TensorPlay
latest (dev)
Copy
View Markdown

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, and dtype, filled with values drawn uniformly from [low, high).

If low or high are outside the range of the dtype’s representable finite values, they are clamped to the lowest or highest representable finite value, respectively. If None, they default to -9 and 9 respectively (0 and 2 for bool).

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 (1 for 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.

On this page

Ask DeepWiki