MCPcopy Index your code
hub / github.com/scikit-learn/scikit-learn / get_namespace

Function get_namespace

sklearn/utils/_array_api.py:375–467  ·  view source on GitHub ↗

Get namespace of arrays. Introspect `arrays` arguments and return their common Array API compatible namespace object, if any. Note that sparse arrays are filtered by default. See: https://numpy.org/neps/nep-0047-array-api-standard.html If `arrays` are regular numpy arrays, `a

(
    *arrays, remove_none=True, remove_types=REMOVE_TYPES_DEFAULT, xp=None
)

Source from the content-addressed store, hash-verified

373
374
375def get_namespace(
376 *arrays, remove_none=True, remove_types=REMOVE_TYPES_DEFAULT, xp=None
377):
378 """Get namespace of arrays.
379
380 Introspect `arrays` arguments and return their common Array API compatible
381 namespace object, if any.
382
383 Note that sparse arrays are filtered by default.
384
385 See: https://numpy.org/neps/nep-0047-array-api-standard.html
386
387 If `arrays` are regular numpy arrays, `array_api_compat.numpy` is returned instead.
388
389 Namespace support is not enabled by default. To enabled it call:
390
391 sklearn.set_config(array_api_dispatch=True)
392
393 or:
394
395 with sklearn.config_context(array_api_dispatch=True):
396 # your code here
397
398 Otherwise `array_api_compat.numpy` is
399 always returned irrespective of the fact that arrays implement the
400 `__array_namespace__` protocol or not.
401
402 Note that if no arrays pass the set filters, ``_NUMPY_API_WRAPPER_INSTANCE, False``
403 is returned.
404
405 Parameters
406 ----------
407 *arrays : array objects
408 Array objects.
409
410 remove_none : bool, default=True
411 Whether to ignore None objects passed in arrays.
412
413 remove_types : tuple or list, default=(str, list, tuple)
414 Types to ignore in the arrays.
415
416 xp : module, default=None
417 Precomputed array namespace module. When passed, typically from a caller
418 that has already performed inspection of its own inputs, skips array
419 namespace inspection.
420
421 Returns
422 -------
423 namespace : module
424 Namespace shared by array objects. If any of the `arrays` are not arrays,
425 the namespace defaults to the NumPy namespace.
426
427 is_array_api_compliant : bool
428 True if the arrays are containers that implement the array API spec (see
429 https://data-apis.org/array-api/latest/index.html).
430 Always False when array_api_dispatch=False.
431 """
432 array_api_dispatch = get_config()["array_api_dispatch"]

Callers 15

predictMethod · 0.90
predict_probaMethod · 0.90
_hstackMethod · 0.90
predictMethod · 0.90
predict_log_probaMethod · 0.90
predict_probaMethod · 0.90
fitMethod · 0.90
_update_mean_varianceMethod · 0.90
_partial_fitMethod · 0.90
_joint_log_likelihoodMethod · 0.90
_class_meansFunction · 0.90
_solve_svdMethod · 0.90

Calls 4

get_configFunction · 0.90
_remove_non_arraysFunction · 0.85
_unwrap_memoryviewslicesFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…