diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0f1d71343f4..395a9c5581d 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 d8bb7cbf4a6..0d166720479 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum * 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) * Aligned the signature of `dpnp.reshape` function with Python array API by making `shape` a required argument [#2673](https://github.com/IntelPython/dpnp/pull/2673) +* 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 ecafb2462e9..8a558fa00fe 100644 --- a/dpnp/__init__.py +++ b/dpnp/__init__.py @@ -68,10 +68,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 @@ -79,6 +75,48 @@ from . import random as random 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 @@ -87,6 +125,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 # ----------------------------------------------------------------------------- @@ -144,7 +194,6 @@ atleast_3d, broadcast_arrays, broadcast_to, - can_cast, column_stack, concat, concatenate, @@ -169,7 +218,6 @@ require, reshape, resize, - result_type, roll, rollaxis, rot90, @@ -206,6 +254,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 # ----------------------------------------------------------------------------- @@ -226,7 +287,6 @@ diagonal, extract, fill_diagonal, - flatnonzero, indices, iterable, ix_, @@ -247,6 +307,7 @@ triu_indices_from, unravel_index, ) +from .dpnp_flatiter import flatiter # ----------------------------------------------------------------------------- # Linear algebra @@ -423,6 +484,7 @@ # Miscellaneous routines # ----------------------------------------------------------------------------- from .dpnp_iface_manipulation import broadcast_shapes +from .dpnp_iface_utils import byte_bounds from .dpnp_iface import get_include # ----------------------------------------------------------------------------- @@ -440,6 +502,7 @@ # Sorting, searching, and counting # ----------------------------------------------------------------------------- from .dpnp_iface_counting import count_nonzero +from .dpnp_iface_indexing import flatnonzero from .dpnp_iface_nanfunctions import nanargmax, nanargmin from .dpnp_iface_searching import ( argmax, @@ -529,6 +592,57 @@ __all__ = ["__array_namespace_info__", "ndarray"] +# 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", @@ -582,7 +696,6 @@ "atleast_3d", "broadcast_arrays", "broadcast_to", - "can_cast", "column_stack", "concat", "concatenate", @@ -607,7 +720,6 @@ "require", "reshape", "resize", - "result_type", "roll", "rollaxis", "rot90", @@ -642,6 +754,18 @@ "right_shift", ] +# Data type routines +__all__ += [ + "can_cast", + "common_type", + "dtype", + "finfo", + "iinfo", + "isdtype", + "issubdtype", + "result_type", +] + # Functional programming __all__ += [ "apply_along_axis", @@ -659,7 +783,6 @@ "extract", "fill_diagonal", "flatiter", - "flatnonzero", "indices", "iterable", "ix_", @@ -850,6 +973,7 @@ # Miscellaneous routines __all__ += [ "broadcast_shapes", + "byte_bounds", "get_include", ] @@ -869,6 +993,7 @@ "argwhere", "argsort", "count_nonzero", + "flatnonzero", "partition", "searchsorted", "sort", @@ -933,8 +1058,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()