espnet2.asr.transducer.rnnt_multi_blank.rnnt_multi_blank.check_contiguous
Less than 1 minute
espnet2.asr.transducer.rnnt_multi_blank.rnnt_multi_blank.check_contiguous
espnet2.asr.transducer.rnnt_multi_blank.rnnt_multi_blank.check_contiguous(var, name)
Check if the given variable is contiguous in memory.
This function raises a ValueError if the input tensor is not contiguous. Contiguous tensors are stored in a single, contiguous block of memory, which can be more efficient for certain operations in PyTorch.
- Parameters:
- var (torch.Tensor) – The tensor to check for contiguity.
- name (str) – The name of the tensor being checked, used in the error message.
- Raises:ValueError – If the input tensor is not contiguous.
Examples
>>> import torch
>>> a = torch.tensor([[1, 2], [3, 4]])
>>> check_contiguous(a, "a") # This will pass
>>> b = a.transpose(0, 1)
>>> check_contiguous(b, "b") # This will raise a ValueError