code: def test_weighted_sum(
      array_namespace,
      device,
      dtype_name,
      sample_weight,
      normalize,
      expected,
  ):
      xp = _array_api_for_tests(array_namespace, device)
      sample_score = numpy.asarray([1, 2, 3, 4], dtype=dtype_name)
      sample_score = xp.asarray(sample_score, device=device)
      if sample_weight is not None:
          sample_weight = numpy.asarray(sample_weight, dtype=dtype_name)
          sample_weight = xp.asarray(sample_weight, device=device)
  
      with config_context(array_api_dispatch=True):
          result = _weighted_sum(sample_score, sample_weight, normalize)
  
      assert isinstance(result, float)
      assert_allclose(result, expected, atol=_atol_for_type(dtype_name))
  
imports: from functools import partial
  import numpy
  import pytest
  from numpy.testing import assert_allclose
  from sklearn._config import config_context
  from sklearn.base import BaseEstimator
  from sklearn.utils._array_api import _ArrayAPIWrapper, _asarray_with_order, _atol_for_type, _convert_to_numpy, _estimator_with_converted_arrays, _nanmax, _nanmin, _NumPyAPIWrapper, _weighted_sum, get_namespace, supported_float_dtypes, yield_namespace_device_dtype_combinations
  from sklearn.utils._testing import _array_api_for_tests, skip_if_array_api_compat_not_configured
label_desc: Use image node_id 8 for calling a global function with example usage: test_weighted_sum(array_namespace, device, dtype_name, sample_weight, normalize, expected) without return types