diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b0aa661eea8..4562714c1e2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -112,7 +112,6 @@ repos: [ "-rn", # Only display messages "-sn", # Don't display the score - "--disable=c-extension-no-member", "--disable=import-error", "--disable=redefined-builtin", "--disable=unused-wildcard-import" diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cf88d9266d..9b2c036bb7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum * Refactored `dpnp.fft` and `dpnp.random` submodules by removing wildcard imports and defining explicit public exports [#2649](https://github.com/IntelPython/dpnp/pull/2649) * Added support for the `out` keyword to accept a tuple, bringing ufunc signatures into alignment with those in NumPy [#2664](https://github.com/IntelPython/dpnp/pull/2664) * Unified public API definitions in `dpnp.linalg` and `dpnp.scipy` submodules [#2663](https://github.com/IntelPython/dpnp/pull/2663) +* Unified `dpnp` public API exports by consolidating function exports in `__init__.py` and removing wildcard imports [#2665](https://github.com/IntelPython/dpnp/pull/2665) [#2666](https://github.com/IntelPython/dpnp/pull/2666) ### Deprecated diff --git a/dpnp/__init__.py b/dpnp/__init__.py index a6eea502e49..e2bacac7df6 100644 --- a/dpnp/__init__.py +++ b/dpnp/__init__.py @@ -66,9 +66,6 @@ from .dpnp_array import dpnp_array as ndarray from .dpnp_array_api_info import __array_namespace_info__ from .dpnp_flatiter import flatiter as flatiter -from .dpnp_iface_types import * -from .dpnp_iface_utils import * -from .dpnp_iface_utils import __all__ as _ifaceutils__all__ from ._version import get_versions from . import exceptions as exceptions from . import fft as fft @@ -77,6 +74,49 @@ from . import scipy as scipy +# ============================================================================= +# Data types +# ============================================================================= +from .dpnp_iface_types import ( + bool, + bool_, + byte, + cdouble, + complex128, + complex64, + complexfloating, + csingle, + double, + float16, + float32, + float64, + floating, + inexact, + int_, + int8, + int16, + int32, + int64, + integer, + intc, + intp, + longlong, + number, + short, + signedinteger, + single, + ubyte, + uint8, + uint16, + uint32, + uint64, + uintc, + uintp, + unsignedinteger, + ushort, + ulonglong, +) + # ============================================================================= # Routines # @@ -84,6 +124,18 @@ # https://numpy.org/doc/stable/reference/routines.html # ============================================================================= +# ----------------------------------------------------------------------------- +# Constants +# ----------------------------------------------------------------------------- +from .dpnp_iface_types import ( + e, + euler_gamma, + inf, + nan, + newaxis, + pi, +) + # ----------------------------------------------------------------------------- # Array creation routines # ----------------------------------------------------------------------------- @@ -141,7 +193,6 @@ atleast_3d, broadcast_arrays, broadcast_to, - can_cast, column_stack, concat, concatenate, @@ -166,7 +217,6 @@ require, reshape, resize, - result_type, roll, rollaxis, rot90, @@ -203,6 +253,19 @@ right_shift, ) +# ----------------------------------------------------------------------------- +# Data type routines +# ----------------------------------------------------------------------------- +from .dpnp_iface_types import ( + common_type, + finfo, + iinfo, + isdtype, + issubdtype, +) +from .dpnp_iface_manipulation import can_cast, result_type +from .dpnp_iface_types import dtype + # ----------------------------------------------------------------------------- # Functional programming # ----------------------------------------------------------------------------- @@ -420,6 +483,7 @@ # Miscellaneous routines # ----------------------------------------------------------------------------- from .dpnp_iface_manipulation import broadcast_shapes +from .dpnp_iface_utils import byte_bounds from .dpnp_iface import get_include # ----------------------------------------------------------------------------- @@ -524,8 +588,59 @@ # Public API # ============================================================================= -# Array creation routines +# Data types __all__ = [ + "bool", + "bool_", + "byte", + "cdouble", + "complex128", + "complex64", + "complexfloating", + "csingle", + "double", + "float16", + "float32", + "float64", + "floating", + "inexact", + "int_", + "int8", + "int16", + "int32", + "int64", + "integer", + "intc", + "intp", + "longlong", + "number", + "short", + "signedinteger", + "single", + "ubyte", + "uint8", + "uint16", + "uint32", + "uint64", + "uintc", + "uintp", + "unsignedinteger", + "ushort", + "ulonglong", +] + +# Constants +__all__ += [ + "e", + "euler_gamma", + "inf", + "nan", + "newaxis", + "pi", +] + +# Array creation routines +__all__ += [ "arange", "array", "asanyarray", @@ -577,7 +692,6 @@ "atleast_3d", "broadcast_arrays", "broadcast_to", - "can_cast", "column_stack", "concat", "concatenate", @@ -602,7 +716,6 @@ "require", "reshape", "resize", - "result_type", "roll", "rollaxis", "rot90", @@ -637,6 +750,18 @@ "right_shift", ] +# Data type routines +__all__ += [ + "can_cast", + "common_type", + "dtype", + "finfo", + "iinfo", + "isdtype", + "issubdtype", + "result_type", +] + # Functional programming __all__ += [ "apply_along_axis", @@ -844,6 +969,7 @@ # Miscellaneous routines __all__ += [ "broadcast_shapes", + "byte_bounds", "get_include", ] @@ -927,8 +1053,6 @@ "synchronize_array_data", ] -__all__ += _ifaceutils__all__ - # add submodules __all__ += ["exceptions", "fft", "linalg", "random", "scipy"] diff --git a/dpnp/dpnp_array_api_info.py b/dpnp/dpnp_array_api_info.py index d8cd58d9473..6a3939d046b 100644 --- a/dpnp/dpnp_array_api_info.py +++ b/dpnp/dpnp_array_api_info.py @@ -38,8 +38,6 @@ import dpctl.tensor as dpt -__all__ = ["__array_namespace_info__"] - def __array_namespace_info__(): """ diff --git a/dpnp/dpnp_iface_types.py b/dpnp/dpnp_iface_types.py index aa9489a00f6..8fdb9e1d3d3 100644 --- a/dpnp/dpnp_iface_types.py +++ b/dpnp/dpnp_iface_types.py @@ -47,60 +47,6 @@ # pylint: disable=no-name-in-module from .dpnp_utils import get_usm_allocations -__all__ = [ - "bool", - "bool_", - "byte", - "cdouble", - "common_type", - "complex128", - "complex64", - "complexfloating", - "csingle", - "double", - "dtype", - "e", - "euler_gamma", - "finfo", - "float16", - "float32", - "float64", - "floating", - "iinfo", - "inexact", - "inf", - "int_", - "int8", - "int16", - "int32", - "int64", - "integer", - "intc", - "intp", - "isdtype", - "issubdtype", - "is_type_supported", - "longlong", - "nan", - "newaxis", - "number", - "pi", - "short", - "signedinteger", - "single", - "ubyte", - "uint8", - "uint16", - "uint32", - "uint64", - "uintc", - "uintp", - "unsignedinteger", - "ushort", - "ulonglong", -] - - # pylint: disable=invalid-name # ============================================================================= # Data types (borrowed from NumPy) @@ -365,11 +311,3 @@ def issubdtype(arg1, arg2): """ return numpy.issubdtype(arg1, arg2) - - -def is_type_supported(obj_type): - """Return True if type is supported by DPNP python level.""" - - if obj_type in (float64, float32, int64, int32): - return True - return False diff --git a/dpnp/dpnp_iface_utils.py b/dpnp/dpnp_iface_utils.py index a577d44ac12..8cd1196ee6d 100644 --- a/dpnp/dpnp_iface_utils.py +++ b/dpnp/dpnp_iface_utils.py @@ -37,8 +37,6 @@ import dpnp -__all__ = ["byte_bounds"] - def byte_bounds(a): """ diff --git a/dpnp/random/dpnp_iface_random.py b/dpnp/random/dpnp_iface_random.py index adc32332595..31a82fa5ac7 100644 --- a/dpnp/random/dpnp_iface_random.py +++ b/dpnp/random/dpnp_iface_random.py @@ -69,6 +69,14 @@ def _get_random_state(device=None, sycl_queue=None): return _dpnp_random_states[sycl_queue] +def _is_type_supported(obj_type): + """Return True if type is supported by dpnp.random""" + + if obj_type in (dpnp.float64, dpnp.float32, dpnp.int64, dpnp.int32): + return True + return False + + def beta(a, b, size=None): """ Draw samples from a Beta distribution. @@ -1587,7 +1595,7 @@ def shuffle(x1): "Running on CUDA is currently not supported" ) - if not dpnp.is_type_supported(x1_desc.dtype): + if not _is_type_supported(x1_desc.dtype): pass else: dpnp_rng_shuffle(x1_desc).get_pyobj()