Check a and weights have matching shapes, and ravel both
(a, weights)
| 276 | |
| 277 | |
| 278 | def _ravel_and_check_weights(a, weights): |
| 279 | """ Check a and weights have matching shapes, and ravel both """ |
| 280 | a = np.asarray(a) |
| 281 | |
| 282 | # Ensure that the array is a "subtractable" dtype |
| 283 | if a.dtype == np.bool: |
| 284 | msg = f"Converting input from {a.dtype} to {np.uint8} for compatibility." |
| 285 | warnings.warn(msg, RuntimeWarning, stacklevel=3) |
| 286 | a = a.astype(np.uint8) |
| 287 | |
| 288 | if weights is not None: |
| 289 | weights = np.asarray(weights) |
| 290 | if weights.shape != a.shape: |
| 291 | raise ValueError( |
| 292 | 'weights should have the same shape as a.') |
| 293 | weights = weights.ravel() |
| 294 | a = a.ravel() |
| 295 | return a, weights |
| 296 | |
| 297 | |
| 298 | def _get_outer_edges(a, range): |
no test coverage detected
searching dependent graphs…