From 7cbc63a18e9503582c82d649f337c6007c7b5212 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 14 Nov 2025 03:30:23 -0800 Subject: [PATCH 1/9] Remove __all__ from dpnp_array_api_info.py --- dpnp/dpnp_array_api_info.py | 2 -- 1 file changed, 2 deletions(-) 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__(): """ From b8a4b736ad5f2e7ca5718532b1606295afc412d0 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 14 Nov 2025 03:55:39 -0800 Subject: [PATCH 2/9] Unify type exports in __init__.py and remove wildcard import --- dpnp/__init__.py | 76 +++++++++++++++++++++++++++++++++++++++- dpnp/dpnp_iface_types.py | 54 ---------------------------- 2 files changed, 75 insertions(+), 55 deletions(-) diff --git a/dpnp/__init__.py b/dpnp/__init__.py index bce5dac20c9..09b4ce24c61 100644 --- a/dpnp/__init__.py +++ b/dpnp/__init__.py @@ -66,7 +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 @@ -77,6 +76,81 @@ from . import scipy as scipy +# ============================================================================= +# Data types, constants and type-related helpers +# ============================================================================= + +# ----------------------------------------------------------------------------- +# Data types (borrowed from NumPy) +# +# The order of these declarations are borrowed from the NumPy document: +# https://numpy.org/doc/stable/reference/arrays.scalars.html +# ----------------------------------------------------------------------------- +from .dpnp_iface_types import ( + bool, + bool_, + byte, + cdouble, + complex128, + complex64, + complexfloating, + csingle, + double, + dtype, + 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 (borrowed from NumPy) +# ----------------------------------------------------------------------------- +from .dpnp_iface_types import ( + e, + euler_gamma, + inf, + nan, + newaxis, + pi, +) + +# ----------------------------------------------------------------------------- +# Type-related helper functions +# ----------------------------------------------------------------------------- +from .dpnp_iface_types import ( + common_type, + finfo, + iinfo, + isdtype, + issubdtype, + is_type_supported, +) + # ============================================================================= # Routines # diff --git a/dpnp/dpnp_iface_types.py b/dpnp/dpnp_iface_types.py index aa9489a00f6..12e292e1f79 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) From 57fb9f340c82b63743b2959e1b8ea490dcb01de4 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 14 Nov 2025 05:25:44 -0800 Subject: [PATCH 3/9] Unify byte_bounds() export in __init__.py and remove wildcard import --- dpnp/__init__.py | 11 ++++++----- dpnp/dpnp_iface_utils.py | 2 -- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dpnp/__init__.py b/dpnp/__init__.py index 09b4ce24c61..92a93f57b80 100644 --- a/dpnp/__init__.py +++ b/dpnp/__init__.py @@ -66,8 +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_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 @@ -498,6 +496,11 @@ unwrap, ) +# ----------------------------------------------------------------------------- +# Miscellaneous routines +# ----------------------------------------------------------------------------- +from .dpnp_iface_utils import byte_bounds + # ----------------------------------------------------------------------------- # Sorting, searching, and counting # ----------------------------------------------------------------------------- @@ -588,10 +591,8 @@ ) -__all__ = _ifaceutils__all__ - # add submodules -__all__ += ["exceptions", "fft", "linalg", "random", "scipy"] +__all__ = ["exceptions", "fft", "linalg", "random", "scipy"] __version__ = get_versions()["version"] 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): """ From 723e2c15bec1a7aeb752dae76a7b399ff8bb569b Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 14 Nov 2025 05:49:45 -0800 Subject: [PATCH 4/9] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff0350039b2..0104e5ca290 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum * Redesigned `dpnp.modf` function to be a part of `ufunc` and `vm` pybind11 extensions [#2654](https://github.com/IntelPython/dpnp/pull/2654) * 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 `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 From 21f983763b301f41eb4ac2dcee5605e1880cc25a Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Tue, 18 Nov 2025 04:42:29 -0800 Subject: [PATCH 5/9] Expand __all__ in relation to new changes --- dpnp/__init__.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/dpnp/__init__.py b/dpnp/__init__.py index 57d14482e79..39e744bd782 100644 --- a/dpnp/__init__.py +++ b/dpnp/__init__.py @@ -597,8 +597,66 @@ # Public API # ============================================================================= -# Array creation routines +# Data types, constants and type-related helpers __all__ = [ + "bool", + "bool_", + "byte", + "cdouble", + "complex128", + "complex64", + "complexfloating", + "csingle", + "double", + "dtype", + "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", +] +__all__ += [ + "e", + "euler_gamma", + "inf", + "nan", + "newaxis", + "pi", +] +__all__ += [ + "common_type", + "finfo", + "iinfo", + "isdtype", + "issubdtype", + "is_type_supported", +] + +# Array creation routines +__all__ += [ "arange", "array", "asanyarray", @@ -917,6 +975,7 @@ # Miscellaneous routines __all__ += [ "broadcast_shapes", + "byte_bounds", "get_include", ] @@ -1001,7 +1060,7 @@ ] # add submodules -__all__ = ["exceptions", "fft", "linalg", "random", "scipy"] +__all__ += ["exceptions", "fft", "linalg", "random", "scipy"] __version__ = get_versions()["version"] From afaf007b41e6cc5056589205cf0ccc1d09c7eefc Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Tue, 18 Nov 2025 05:11:24 -0800 Subject: [PATCH 6/9] Apply remarks --- dpnp/__init__.py | 82 +++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/dpnp/__init__.py b/dpnp/__init__.py index 39e744bd782..ad167b6016a 100644 --- a/dpnp/__init__.py +++ b/dpnp/__init__.py @@ -75,15 +75,8 @@ # ============================================================================= -# Data types, constants and type-related helpers +# Data types # ============================================================================= - -# ----------------------------------------------------------------------------- -# Data types (borrowed from NumPy) -# -# The order of these declarations are borrowed from the NumPy document: -# https://numpy.org/doc/stable/reference/arrays.scalars.html -# ----------------------------------------------------------------------------- from .dpnp_iface_types import ( bool, bool_, @@ -94,7 +87,6 @@ complexfloating, csingle, double, - dtype, float16, float32, float64, @@ -125,8 +117,15 @@ ulonglong, ) +# ============================================================================= +# Routines +# +# The order of these declarations are borrowed from the NumPy document: +# https://numpy.org/doc/stable/reference/routines.html +# ============================================================================= + # ----------------------------------------------------------------------------- -# Constants (borrowed from NumPy) +# Constants # ----------------------------------------------------------------------------- from .dpnp_iface_types import ( e, @@ -137,25 +136,6 @@ pi, ) -# ----------------------------------------------------------------------------- -# Type-related helper functions -# ----------------------------------------------------------------------------- -from .dpnp_iface_types import ( - common_type, - finfo, - iinfo, - isdtype, - issubdtype, - is_type_supported, -) - -# ============================================================================= -# Routines -# -# The order of these declarations are borrowed from the NumPy document: -# https://numpy.org/doc/stable/reference/routines.html -# ============================================================================= - # ----------------------------------------------------------------------------- # Array creation routines # ----------------------------------------------------------------------------- @@ -213,7 +193,6 @@ atleast_3d, broadcast_arrays, broadcast_to, - can_cast, column_stack, concat, concatenate, @@ -238,7 +217,6 @@ require, reshape, resize, - result_type, roll, rollaxis, rot90, @@ -275,6 +253,20 @@ right_shift, ) +# ----------------------------------------------------------------------------- +# Data type routines +# ----------------------------------------------------------------------------- +from .dpnp_iface_types import ( + common_type, + finfo, + iinfo, + isdtype, + issubdtype, + is_type_supported, +) +from .dpnp_iface_manipulation import can_cast, result_type +from .dpnp_iface_types import dtype + # ----------------------------------------------------------------------------- # Functional programming # ----------------------------------------------------------------------------- @@ -597,7 +589,7 @@ # Public API # ============================================================================= -# Data types, constants and type-related helpers +# Data types __all__ = [ "bool", "bool_", @@ -608,7 +600,6 @@ "complexfloating", "csingle", "double", - "dtype", "float16", "float32", "float64", @@ -638,6 +629,8 @@ "ushort", "ulonglong", ] + +# Constants __all__ += [ "e", "euler_gamma", @@ -646,14 +639,6 @@ "newaxis", "pi", ] -__all__ += [ - "common_type", - "finfo", - "iinfo", - "isdtype", - "issubdtype", - "is_type_supported", -] # Array creation routines __all__ += [ @@ -708,7 +693,6 @@ "atleast_3d", "broadcast_arrays", "broadcast_to", - "can_cast", "column_stack", "concat", "concatenate", @@ -733,7 +717,6 @@ "require", "reshape", "resize", - "result_type", "roll", "rollaxis", "rot90", @@ -768,6 +751,19 @@ "right_shift", ] +# Data type routines +__all__ += [ + "can_cast", + "common_type", + "dtype", + "finfo", + "iinfo", + "isdtype", + "issubdtype", + "is_type_supported", + "result_type", +] + # Functional programming __all__ += [ "apply_along_axis", From 244721beb8cecf3ac88df250de00d13fef6fa17d Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Tue, 18 Nov 2025 05:14:45 -0800 Subject: [PATCH 7/9] Remove obsolete pre-commit disables --- .flake8 | 2 -- .pre-commit-config.yaml | 1 - 2 files changed, 3 deletions(-) diff --git a/.flake8 b/.flake8 index 37b70721bd4..7822c9a3cfb 100644 --- a/.flake8 +++ b/.flake8 @@ -3,8 +3,6 @@ extend-ignore = # whitespace before ':' (currently conflicts with black formatting): E203, # line too long (in docstrings): - E501, - # ‘from module import *’ used; unable to detect undefined names: F403, # name may be undefined, or defined from star imports: module: F405, 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" From 2bbd6de472b932485843edf6cb5f417a0cda2a2e Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Tue, 18 Nov 2025 05:40:01 -0800 Subject: [PATCH 8/9] Revert E501 flake ignore --- .flake8 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.flake8 b/.flake8 index 7822c9a3cfb..37b70721bd4 100644 --- a/.flake8 +++ b/.flake8 @@ -3,6 +3,8 @@ extend-ignore = # whitespace before ':' (currently conflicts with black formatting): E203, # line too long (in docstrings): + E501, + # ‘from module import *’ used; unable to detect undefined names: F403, # name may be undefined, or defined from star imports: module: F405, From 7971b3b37f515ef33af5a853d29ff77815caaaa1 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Tue, 18 Nov 2025 05:42:14 -0800 Subject: [PATCH 9/9] Move is_type_supported() to dpnp_iface_random.py and remove from public API --- dpnp/__init__.py | 2 -- dpnp/dpnp_iface_types.py | 8 -------- dpnp/random/dpnp_iface_random.py | 10 +++++++++- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/dpnp/__init__.py b/dpnp/__init__.py index ad167b6016a..e2bacac7df6 100644 --- a/dpnp/__init__.py +++ b/dpnp/__init__.py @@ -262,7 +262,6 @@ iinfo, isdtype, issubdtype, - is_type_supported, ) from .dpnp_iface_manipulation import can_cast, result_type from .dpnp_iface_types import dtype @@ -760,7 +759,6 @@ "iinfo", "isdtype", "issubdtype", - "is_type_supported", "result_type", ] diff --git a/dpnp/dpnp_iface_types.py b/dpnp/dpnp_iface_types.py index 12e292e1f79..8fdb9e1d3d3 100644 --- a/dpnp/dpnp_iface_types.py +++ b/dpnp/dpnp_iface_types.py @@ -311,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/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()