|
10 | 10 | from hypothesis import assume, reject
|
11 | 11 | from hypothesis.strategies import (SearchStrategy, booleans, composite, floats,
|
12 | 12 | integers, just, lists, none, one_of,
|
13 |
| - sampled_from, shared, builds) |
| 13 | + sampled_from, shared, builds, permutations) |
14 | 14 |
|
15 | 15 | from . import _array_module as xp, api_version
|
16 | 16 | from . import array_helpers as ah
|
@@ -148,6 +148,25 @@ def mutually_promotable_dtypes(
|
148 | 148 | return one_of(strats).map(tuple)
|
149 | 149 |
|
150 | 150 |
|
| 151 | +@composite |
| 152 | +def mutually_non_promotable_dtypes( |
| 153 | + draw, |
| 154 | + max_size: Optional[int] = 2, |
| 155 | +) -> Sequence[Tuple[DataType, ...]]: |
| 156 | + """Generate a pair of dtypes which cannot be promoted.""" |
| 157 | + assert max_size == 2 |
| 158 | + |
| 159 | + _categories = [ |
| 160 | + (xp.bool,), |
| 161 | + dh.uint_dtypes + dh.int_dtypes, |
| 162 | + dh.real_float_dtypes + dh.complex_dtypes |
| 163 | + ] |
| 164 | + cat_st = permutations(_categories).map(lambda s: s[:2]) |
| 165 | + cat_from, cat_to = draw(cat_st) |
| 166 | + from_, to = draw(sampled_from(cat_from)), draw(sampled_from(cat_to)) |
| 167 | + return from_, to |
| 168 | + |
| 169 | + |
151 | 170 | class OnewayPromotableDtypes(NamedTuple):
|
152 | 171 | input_dtype: DataType
|
153 | 172 | result_dtype: DataType
|
|
0 commit comments