vak.common.validators.is_1d_or_2d_tensor

vak.common.validators.is_1d_or_2d_tensor(y: Tensor, name: str | None = None) bool[source]

Validates that y is a one-dimension or two-dimensional torch.Tensor.

If y is not a torch.Tensor, raises a TypeError. If y does not have one or two dimensions, raises a ValueError.

Parameters:
  • y (torch.Tensor) – Array to be validated.

  • name (str, optional) – Name of array in calling function. Used in any error message if supplied.

Returns:

is_1d_or_2d_tensorTrue if y.ndim==1 or y.ndim == 2

Return type:

bool

Examples

>>> y = torch.tensor([[0, 1, 2], [0, 1, 2]])
>>> vak.metrics.boundary_detection.validators.is_1d_or_2d_tensor(y)
True
>>> y = torch.tensor([0, 1, 2])
>>> vak.metrics.boundary_detection.validators.is_1d_or_2d_tensor(y)
True