Wrap a transformed array with __array_wrap__ if it can be done safely. This lets us treat arbitrary functions that take and return ndarray objects like ufuncs, as long as they return an array with the same shape.
(original, new_array)
| 223 | |
| 224 | |
| 225 | def maybe_wrap_array(original, new_array): |
| 226 | """Wrap a transformed array with __array_wrap__ if it can be done safely. |
| 227 | |
| 228 | This lets us treat arbitrary functions that take and return ndarray objects |
| 229 | like ufuncs, as long as they return an array with the same shape. |
| 230 | """ |
| 231 | # in case func lost array's metadata |
| 232 | if isinstance(new_array, np.ndarray) and new_array.shape == original.shape: |
| 233 | return original.__array_wrap__(new_array) |
| 234 | else: |
| 235 | return new_array |
| 236 | |
| 237 | |
| 238 | def equivalent(first: T, second: T) -> bool: |
no test coverage detected
searching dependent graphs…