MCPcopy Index your code
hub / github.com/numpy/numpy / check_function

Method check_function

numpy/_core/tests/test_numeric.py:3323–3371  ·  view source on GitHub ↗
(self, func, fill_value=None)

Source from the content-addressed store, hash-verified

3321
3322class TestCreationFuncs:
3323 def check_function(self, func, fill_value=None):
3324 dtypes_info = {np.dtype(tp) for tp in itertools.chain(*sctypes.values())}
3325 keyfunc = lambda dtype: dtype.str
3326 variable_sized = {tp for tp in dtypes_info if tp.str.endswith('0')}
3327 dtypes = sorted(dtypes_info - variable_sized |
3328 {np.dtype(tp.str.replace("0", str(i)))
3329 for tp in variable_sized for i in range(1, 10)},
3330 key=keyfunc)
3331 dtypes += [type(dt) for dt in sorted(dtypes_info, key=keyfunc)]
3332 orders = {'C': 'c_contiguous', 'F': 'f_contiguous'}
3333 ndims = 10
3334
3335 par = ((0, 1, 2),
3336 range(ndims),
3337 orders,
3338 dtypes)
3339 fill_kwarg = {}
3340 if fill_value is not None:
3341 fill_kwarg = {'fill_value': fill_value}
3342
3343 for size, ndims, order, dtype in itertools.product(*par):
3344 shape = ndims * [size]
3345
3346 is_void = dtype is np.dtypes.VoidDType or (
3347 isinstance(dtype, np.dtype) and dtype.str.startswith('|V'))
3348
3349 # do not fill void type
3350 if fill_kwarg and is_void:
3351 continue
3352
3353 arr = func(shape, order=order, dtype=dtype,
3354 **fill_kwarg)
3355
3356 if isinstance(dtype, np.dtype):
3357 assert_equal(arr.dtype, dtype)
3358 elif isinstance(dtype, type(np.dtype)):
3359 if dtype in (np.dtypes.StrDType, np.dtypes.BytesDType):
3360 dtype_str = np.dtype(dtype.type).str.replace('0', '1')
3361 assert_equal(arr.dtype, np.dtype(dtype_str))
3362 else:
3363 assert_equal(arr.dtype, np.dtype(dtype.type))
3364 assert_(getattr(arr.flags, orders[order]))
3365
3366 if fill_value is not None:
3367 if arr.dtype.str.startswith('|S'):
3368 val = str(fill_value)
3369 else:
3370 val = fill_value
3371 assert_equal(arr, dtype.type(val))
3372
3373 def test_zeros(self):
3374 self.check_function(np.zeros)

Callers 4

test_zerosMethod · 0.95
test_onesMethod · 0.95
test_emptyMethod · 0.95
test_fullMethod · 0.95

Calls 8

assert_equalFunction · 0.90
assert_Function · 0.90
endswithMethod · 0.80
replaceMethod · 0.80
startswithMethod · 0.80
funcFunction · 0.70
dtypeMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected