Checks if a numpy array is valid (not None and has the expected shape). Raises an error if the array is None or has an unexpected shape.
(array, name)
| 76 | |
| 77 | |
| 78 | def check_valid_numpy(array, name): |
| 79 | """ |
| 80 | Checks if a numpy array is valid (not None and has the expected shape). |
| 81 | Raises an error if the array is None or has an unexpected shape. |
| 82 | """ |
| 83 | if array is None: |
| 84 | print(f"{name} is None") |
| 85 | return True |
| 86 | |
| 87 | if not isinstance(array, np.ndarray): |
| 88 | print(f"{name} must be a numpy.ndarray, got {type(array)}") |
| 89 | return True |
| 90 | |
| 91 | if array.size == 0: |
| 92 | print(f"{name} is empty") |
| 93 | return True |
| 94 | |
| 95 | if np.isnan(array).any(): |
| 96 | print(f"{name} contains NaN values") |
| 97 | return True |
| 98 | |
| 99 | if np.isinf(array).any(): |
| 100 | print(f"{name} contains Inf values") |
| 101 | return True |
| 102 | |
| 103 | return False # No exception raised, array is valid |
| 104 | |
| 105 | |
| 106 | class SftJSONLIterableReconDataset(DistributedIterableDataset): |
nothing calls this directly
no outgoing calls
no test coverage detected