latest (dev)
Copy
Latest development documentation · Updated 2026-10-08
tensorplay.testing API
Functions 5
assert_allclose
functionFull reference ↗assert_close
functionFull reference ↗- tensorplay.testing.assert_close(actual: Any, expected: Any, *, allow_subclasses: bool = True, rtol: float | None = None, atol: float | None = None, equal_nan: bool = False, check_device: bool = True, check_dtype: bool = True, check_layout: bool = True, check_stride: bool = False, msg: str | Callable[[str], str] | None = None)[source]
Asserts that
actualandexpectedare close.If
actualandexpectedare strided and finite, they are considered close ifNon-finite values (
-infandinf) are only considered close if and only if they are equal.NaN’s are only considered equal to each other ifequal_nanisTrue.In addition, they are only considered close if they have the same
device (if
check_deviceisTrue),dtype (if
check_dtypeisTrue),layout (if
check_layoutisTrue), andstride (if
check_strideisTrue).
If either
actualorexpectedis a scalar or a nested python container, the other side is converted to a tensor-like value before the comparison.- Parameters:
actual (Any) – Actual input.
expected (Any) – Expected input.
allow_subclasses (bool) – If
True(default) and other than exact type match, inputs that are subclasses of each other are considered close.rtol (Optional[float]) – Relative tolerance. If specified
atolmust also be specified. If omitted, default values based on thedtypeare selected. See below for details.atol (Optional[float]) – Absolute tolerance. If specified
rtolmust also be specified. If omitted, default values based on thedtypeare selected. See below for details.equal_nan (bool) – If
True, twoNaNvalues are considered equal. Defaults toFalse.check_device (bool) – If
True(default), asserts that corresponding tensors are on the same device.check_dtype (bool) – If
True(default), asserts that corresponding tensors have the same dtype.check_layout (bool) – If
True(default), asserts that corresponding tensors have the same layout.check_stride (bool) – If
True, asserts that corresponding strided tensors have the same stride.msg (Optional[Union[str, Callable[[str], str]]]) – Optional error message to use in case of failure.
- Raises:
ValueError – If only
rtolor onlyatolis specified.AssertionError – If corresponding values are not close.
Default tolerances by dtype:
dtypertolatolfloat161e-31e-5bfloat161.6e-21e-5float321.3e-61e-5float641e-71e-7complex641.3e-61e-5complex1281e-71e-7Note
Tensors are compared elementwise, allowing for a relative and an absolute tolerance per element. If both tolerances are omitted, the loosest tolerance of the involved dtypes is selected.
default_tolerances
functionFull reference ↗get_tolerances
functionFull reference ↗- tensorplay.testing.get_tolerances(*inputs: Tensor | dtype, rtol: float | None, atol: float | None, id: tuple[Any, ...] = ()) tuple[float, float][source]
Gets absolute and relative tolerances to be used for numeric comparisons.
If both
rtolandatolare specified, this is a no-op. If neither is specified,default_tolerances()is used. Specifying only one raises aValueError, since a single tolerance might lead to surprising results.
make_tensor
functionFull reference ↗- 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.
Classes 1
FileCheck
classFull reference ↗- class tensorplay.testing.FileCheck
- check(self: tensorplay._C.FileCheck, test_string: str) tensorplay._C.FileCheck
- check_count(self: tensorplay._C.FileCheck, test_string: str, count: SupportsInt | SupportsIndex, exactly: bool = False) tensorplay._C.FileCheck
- check_dag(self: tensorplay._C.FileCheck, test_string: str) tensorplay._C.FileCheck
- check_next(self: tensorplay._C.FileCheck, test_string: str) tensorplay._C.FileCheck
- check_not(self: tensorplay._C.FileCheck, test_string: str) tensorplay._C.FileCheck
- check_regex(self: tensorplay._C.FileCheck, test_string: str) tensorplay._C.FileCheck
- check_same(self: tensorplay._C.FileCheck, test_string: str) tensorplay._C.FileCheck
- check_source_highlighted(self: tensorplay._C.FileCheck, test_string: str) tensorplay._C.FileCheck
Help improve this page
Found an error, an unclear step, or a missing example?

