MCPcopy
hub / github.com/scikit-learn/scikit-learn / test_average

Function test_average

sklearn/utils/tests/test_array_api.py:240–259  ·  view source on GitHub ↗
(
    array_namespace, device_name, dtype_name, weights, axis, normalize, expected
)

Source from the content-addressed store, hash-verified

238 ],
239)
240def test_average(
241 array_namespace, device_name, dtype_name, weights, axis, normalize, expected
242):
243 xp, device = _array_api_for_tests(array_namespace, device_name, dtype_name)
244 array_in = numpy.asarray([[1, 2, 3], [4, 5, 6]], dtype=dtype_name)
245 array_in = xp.asarray(array_in, device=device)
246 if weights is not None:
247 weights = numpy.asarray(weights, dtype=dtype_name)
248 weights = xp.asarray(weights, device=device)
249
250 with config_context(array_api_dispatch=True):
251 result = _average(array_in, axis=axis, weights=weights, normalize=normalize)
252
253 if np_version < parse_version("2.0.0") or np_version >= parse_version("2.1.0"):
254 # NumPy 2.0 has a problem with the device attribute of scalar arrays:
255 # https://github.com/numpy/numpy/issues/26850
256 assert array_api_device(array_in) == array_api_device(result)
257
258 result = move_to(result, xp=numpy, device="cpu")
259 assert_allclose(result, expected, atol=_atol_for_type(dtype_name))
260
261
262@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 6

_array_api_for_testsFunction · 0.90
config_contextFunction · 0.90
_averageFunction · 0.90
move_toFunction · 0.90
assert_allcloseFunction · 0.90
_atol_for_typeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…