There are many dedicated paths in NumPy which cast and should check for floating point errors which occurred during those casts.
(dtype, value)
| 52 | |
| 53 | |
| 54 | def check_operations(dtype, value): |
| 55 | """ |
| 56 | There are many dedicated paths in NumPy which cast and should check for |
| 57 | floating point errors which occurred during those casts. |
| 58 | """ |
| 59 | if dtype.kind != 'i': |
| 60 | # These assignments use the stricter setitem logic: |
| 61 | def assignment(): |
| 62 | arr = np.empty(3, dtype=dtype) |
| 63 | arr[0] = value |
| 64 | |
| 65 | yield assignment |
| 66 | |
| 67 | def fill(): |
| 68 | arr = np.empty(3, dtype=dtype) |
| 69 | arr.fill(value) |
| 70 | |
| 71 | yield fill |
| 72 | |
| 73 | def copyto_scalar(): |
| 74 | arr = np.empty(3, dtype=dtype) |
| 75 | np.copyto(arr, value, casting="unsafe") |
| 76 | |
| 77 | yield copyto_scalar |
| 78 | |
| 79 | def copyto(): |
| 80 | arr = np.empty(3, dtype=dtype) |
| 81 | np.copyto(arr, np.array([value, value, value]), casting="unsafe") |
| 82 | |
| 83 | yield copyto |
| 84 | |
| 85 | def copyto_scalar_masked(): |
| 86 | arr = np.empty(3, dtype=dtype) |
| 87 | np.copyto(arr, value, casting="unsafe", |
| 88 | where=[True, False, True]) |
| 89 | |
| 90 | yield copyto_scalar_masked |
| 91 | |
| 92 | def copyto_masked(): |
| 93 | arr = np.empty(3, dtype=dtype) |
| 94 | np.copyto(arr, np.array([value, value, value]), casting="unsafe", |
| 95 | where=[True, False, True]) |
| 96 | |
| 97 | yield copyto_masked |
| 98 | |
| 99 | def direct_cast(): |
| 100 | np.array([value, value, value]).astype(dtype) |
| 101 | |
| 102 | yield direct_cast |
| 103 | |
| 104 | def direct_cast_nd_strided(): |
| 105 | arr = np.full((5, 5, 5), fill_value=value)[:, ::2, :] |
| 106 | arr.astype(dtype) |
| 107 | |
| 108 | yield direct_cast_nd_strided |
| 109 | |
| 110 | def boolean_array_assignment(): |
| 111 | arr = np.empty(3, dtype=dtype) |
no outgoing calls
no test coverage detected