scipy_namespace_for

scipy_namespace_for(xp: ModuleType) ModuleType | None[source][source]

Return the scipy-like namespace of a non-NumPy backend

That is, return the namespace corresponding with backend xp that contains scipy sub-namespaces like linalg and special. If no such namespace exists, return None. Useful for dispatching.

Parameters:

xp (module) –

The array API namespace for which to find the corresponding SciPy-like

namespace.

Returns:

The SciPy-like namespace for the given array API namespace, or None if

no such namespace exists.

Return type:

module or None

Examples

>>> import numpy as np
>>> import scipy
>>> scipy_namespace = scipy_namespace_for(np)
>>> scipy_namespace is scipy
True
>>> import cupy as cp
>>> scipy_namespace = scipy_namespace_for(cp)
>>> scipy_namespace is cupyx.scipy
True