|
52 | 52 | def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
|
53 | 53 | if isinstance(x, numba.types.Array):
|
54 | 54 |
|
55 |
| - def nan_to_num_impl(x, copy=True, nan=0.0, posinf=None, neginf=None): |
56 |
| - out = numpy.copy(x).reshape(-1) if copy else x.reshape(-1) |
57 |
| - for i in range(len(out)): |
58 |
| - if numpy.isnan(out[i]): |
59 |
| - out[i] = nan |
60 |
| - if posinf is not None and numpy.isinf(out[i]) and out[i] > 0: |
61 |
| - out[i] = posinf |
62 |
| - if neginf is not None and numpy.isinf(out[i]) and out[i] < 0: |
63 |
| - out[i] = neginf |
64 |
| - return out.reshape(x.shape) |
| 55 | + if isinstance(nan, numba.types.Array): |
| 56 | + |
| 57 | + def nan_to_num_impl(x, copy=True, nan=0.0, posinf=None, neginf=None): |
| 58 | + out = numpy.copy(x).reshape(-1) if copy else x.reshape(-1) |
| 59 | + for i in range(len(out)): |
| 60 | + if numpy.isnan(out[i]): |
| 61 | + out[i] = nan[i] |
| 62 | + if posinf is not None and numpy.isinf(out[i]) and out[i] > 0: |
| 63 | + out[i] = posinf |
| 64 | + if neginf is not None and numpy.isinf(out[i]) and out[i] < 0: |
| 65 | + out[i] = neginf |
| 66 | + return out.reshape(x.shape) |
| 67 | + |
| 68 | + else: |
| 69 | + |
| 70 | + def nan_to_num_impl(x, copy=True, nan=0.0, posinf=None, neginf=None): |
| 71 | + out = numpy.copy(x).reshape(-1) if copy else x.reshape(-1) |
| 72 | + for i in range(len(out)): |
| 73 | + if numpy.isnan(out[i]): |
| 74 | + out[i] = nan |
| 75 | + if posinf is not None and numpy.isinf(out[i]) and out[i] > 0: |
| 76 | + out[i] = posinf |
| 77 | + if neginf is not None and numpy.isinf(out[i]) and out[i] < 0: |
| 78 | + out[i] = neginf |
| 79 | + return out.reshape(x.shape) |
65 | 80 |
|
66 | 81 | else:
|
67 | 82 |
|
|
0 commit comments