Helper to create "interesting" operands to cover common code paths: * scalar inputs * only first "values" is an array (e.g. scalar division fast-paths) * Longer array (SIMD) placing the value of interest at different positions * Oddly strided arrays which may not be SIMD compati
(val1, val2, dtype)
| 40 | ] |
| 41 | |
| 42 | def interesting_binop_operands(val1, val2, dtype): |
| 43 | """ |
| 44 | Helper to create "interesting" operands to cover common code paths: |
| 45 | * scalar inputs |
| 46 | * only first "values" is an array (e.g. scalar division fast-paths) |
| 47 | * Longer array (SIMD) placing the value of interest at different positions |
| 48 | * Oddly strided arrays which may not be SIMD compatible |
| 49 | |
| 50 | It does not attempt to cover unaligned access or mixed dtypes. |
| 51 | These are normally handled by the casting/buffering machinery. |
| 52 | |
| 53 | This is not a fixture (currently), since I believe a fixture normally |
| 54 | only yields once? |
| 55 | """ |
| 56 | fill_value = 1 # could be a parameter, but maybe not an optional one? |
| 57 | |
| 58 | arr1 = np.full(10003, dtype=dtype, fill_value=fill_value) |
| 59 | arr2 = np.full(10003, dtype=dtype, fill_value=fill_value) |
| 60 | |
| 61 | arr1[0] = val1 |
| 62 | arr2[0] = val2 |
| 63 | |
| 64 | extractor = lambda res: res |
| 65 | yield arr1[0], arr2[0], extractor, "scalars" |
| 66 | |
| 67 | extractor = lambda res: res |
| 68 | yield arr1[0, ...], arr2[0, ...], extractor, "scalar-arrays" |
| 69 | |
| 70 | # reset array values to fill_value: |
| 71 | arr1[0] = fill_value |
| 72 | arr2[0] = fill_value |
| 73 | |
| 74 | for pos in [0, 1, 2, 3, 4, 5, -1, -2, -3, -4]: |
| 75 | arr1[pos] = val1 |
| 76 | arr2[pos] = val2 |
| 77 | |
| 78 | extractor = lambda res: res[pos] |
| 79 | yield arr1, arr2, extractor, f"off-{pos}" |
| 80 | yield arr1, arr2[pos], extractor, f"off-{pos}-with-scalar" |
| 81 | |
| 82 | arr1[pos] = fill_value |
| 83 | arr2[pos] = fill_value |
| 84 | |
| 85 | for stride in [-1, 113]: |
| 86 | op1 = arr1[::stride] |
| 87 | op2 = arr2[::stride] |
| 88 | op1[10] = val1 |
| 89 | op2[10] = val2 |
| 90 | |
| 91 | extractor = lambda res: res[10] |
| 92 | yield op1, op2, extractor, f"stride-{stride}" |
| 93 | |
| 94 | op1[10] = fill_value |
| 95 | op2[10] = fill_value |
| 96 | |
| 97 | |
| 98 | def on_powerpc(): |
no outgoing calls
no test coverage detected