espnet2.asr.transducer.rnnt_multi_blank.rnnt_multi_blank.check_dim
Less than 1 minute
espnet2.asr.transducer.rnnt_multi_blank.rnnt_multi_blank.check_dim
espnet2.asr.transducer.rnnt_multi_blank.rnnt_multi_blank.check_dim(var, dim, name)
Check if the tensor has the specified number of dimensions.
This function verifies whether the input tensor var has the expected number of dimensions specified by dim. If the number of dimensions does not match, a ValueError is raised.
- Parameters:
- var (torch.Tensor) – The input tensor to be checked.
- dim (int) – The expected number of dimensions.
- name (str) – The name of the tensor, used in the error message.
- Raises:ValueError – If the number of dimensions of var does not match dim.
Examples
>>> check_dim(torch.randn(2, 3), 2, "input_tensor") # No exception
>>> check_dim(torch.randn(2, 3, 4), 2, "input_tensor") # Raises ValueError