Subtract two values where a >= b, and produce an unsigned result This is needed when finding the difference between the upper and lower bound of an int16 histogram
(a, b)
| 326 | |
| 327 | |
| 328 | def _unsigned_subtract(a, b): |
| 329 | """ |
| 330 | Subtract two values where a >= b, and produce an unsigned result |
| 331 | |
| 332 | This is needed when finding the difference between the upper and lower |
| 333 | bound of an int16 histogram |
| 334 | """ |
| 335 | # coerce to a single type |
| 336 | signed_to_unsigned = { |
| 337 | np.byte: np.ubyte, |
| 338 | np.short: np.ushort, |
| 339 | np.intc: np.uintc, |
| 340 | np.int_: np.uint, |
| 341 | np.longlong: np.ulonglong |
| 342 | } |
| 343 | dt = np.result_type(a, b) |
| 344 | try: |
| 345 | unsigned_dt = signed_to_unsigned[dt.type] |
| 346 | except KeyError: |
| 347 | return np.subtract(a, b, dtype=type(dt)) |
| 348 | else: |
| 349 | # we know the inputs are integers, and we are deliberately casting |
| 350 | # signed to unsigned. The input may be negative python integers so |
| 351 | # ensure we pass in arrays with the initial dtype (related to NEP 50). |
| 352 | return np.subtract(np.asarray(a, dtype=dt), np.asarray(b, dtype=dt), |
| 353 | casting='unsafe', dtype=unsigned_dt) |
| 354 | |
| 355 | |
| 356 | def _get_bin_edges(a, bins, range, weights): |
no outgoing calls
searching dependent graphs…