|
1 |
| -from ._array_module import (asarray, arange, ceil, empty, eye, full, |
2 |
| -equal, all, linspace, ones, zeros, isnan) |
| 1 | +from ._array_module import (asarray, arange, ceil, empty, eye, full, full_like, |
| 2 | + equal, all, linspace, ones, zeros, isnan) |
3 | 3 | from .array_helpers import (is_integer_dtype, dtype_ranges,
|
4 | 4 | assert_exactly_equal, isintegral, is_float_dtype)
|
5 | 5 | from .hypothesis_helpers import (numeric_dtypes, dtypes, MAX_ARRAY_SIZE,
|
6 | 6 | shapes, sizes, sqrt_sizes, shared_dtypes,
|
7 |
| - scalars) |
| 7 | + scalars, xps) |
8 | 8 |
|
9 | 9 | from hypothesis import assume, given
|
10 |
| -from hypothesis.strategies import integers, floats, one_of, none, booleans, just |
| 10 | +from hypothesis.strategies import integers, floats, one_of, none, booleans, just, shared |
11 | 11 |
|
12 | 12 | int_range = integers(-MAX_ARRAY_SIZE, MAX_ARRAY_SIZE)
|
13 | 13 | float_range = floats(-MAX_ARRAY_SIZE, MAX_ARRAY_SIZE,
|
@@ -131,8 +131,32 @@ def test_full(shape, fill_value, dtype):
|
131 | 131 | assert all(equal(a, asarray(fill_value, **kwargs))), "full() array did not equal the fill value"
|
132 | 132 |
|
133 | 133 | # TODO: implement full_like (requires hypothesis arrays support)
|
134 |
| -def test_full_like(): |
135 |
| - pass |
| 134 | +@given( |
| 135 | + a=xps.arrays( |
| 136 | + dtype=shared(xps.scalar_dtypes(), key='dtypes'), |
| 137 | + shape=xps.array_shapes(), |
| 138 | + ), |
| 139 | + fill_value=shared(xps.scalar_dtypes(), key='dtypes').flatmap(xps.from_dtype), |
| 140 | + kwargs=one_of( |
| 141 | + just({}), |
| 142 | + shared(xps.scalar_dtypes(), key='dtypes').map(lambda d: {'dtype': d}), |
| 143 | + ), |
| 144 | +) |
| 145 | +def test_full_like(a, fill_value, kwargs): |
| 146 | + a_like = full_like(a, fill_value, **kwargs) |
| 147 | + |
| 148 | + if kwargs is None: |
| 149 | + pass # TODO: Should it actually match the fill_value? |
| 150 | + else: |
| 151 | + assert a_like.dtype == a.dtype |
| 152 | + |
| 153 | + assert a_like.shape == a.shape, "full_like() produced an array with incorrect shape" |
| 154 | + |
| 155 | + if is_float_dtype(a_like.dtype) and isnan(asarray(fill_value)): |
| 156 | + assert all(isnan(a_like)), "full_like() array did not equal the fill value" |
| 157 | + else: |
| 158 | + assert all(equal(a_like, asarray(fill_value, dtype=a.dtype))), "full_like() array did not equal the fill value" |
| 159 | + |
136 | 160 |
|
137 | 161 | @given(scalars(shared_dtypes, finite=True),
|
138 | 162 | scalars(shared_dtypes, finite=True),
|
|
0 commit comments