Returns the number of elements in a NumPy array, PyTorch array, or integer.
(tensor)
| 312 | |
| 313 | |
| 314 | def numel(tensor) -> int: |
| 315 | """ |
| 316 | Returns the number of elements in a NumPy array, PyTorch array, or integer. |
| 317 | """ |
| 318 | if isinstance(tensor, int): # Integer |
| 319 | return tensor |
| 320 | elif hasattr(tensor, 'numel'): # PyTorch array |
| 321 | return tensor.numel() |
| 322 | else: # NumPy array |
| 323 | return tensor.size |
| 324 | |
| 325 | |
| 326 | # Mimics the other tester's determination of working directory |
no outgoing calls
no test coverage detected