Skip to content

Commit 225b0db

Browse files
Unify dpnp public API exports by refactoring __init__.py (#2666)
This PR removes the remaining wildcard imports and `__all__` declarations from internal modules and consolidates the corresponding exports in `dpnp/__init__.py` as part of the ongoing public API unification. This work follows #2665
1 parent 167c3e6 commit 225b0db

File tree

7 files changed

+145
-80
lines changed

7 files changed

+145
-80
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ repos:
112112
[
113113
"-rn", # Only display messages
114114
"-sn", # Don't display the score
115-
"--disable=c-extension-no-member",
116115
"--disable=import-error",
117116
"--disable=redefined-builtin",
118117
"--disable=unused-wildcard-import"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum
3737
* 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)
3838
* Unified public API definitions in `dpnp.linalg` and `dpnp.scipy` submodules [#2663](https://github.com/IntelPython/dpnp/pull/2663)
3939
* 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)
40+
* 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)
4041

4142
### Deprecated
4243

dpnp/__init__.py

Lines changed: 135 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,55 @@
6868

6969
from .dpnp_array import dpnp_array as ndarray
7070
from .dpnp_array_api_info import __array_namespace_info__
71-
from .dpnp_flatiter import flatiter as flatiter
72-
from .dpnp_iface_types import *
73-
from .dpnp_iface_utils import *
74-
from .dpnp_iface_utils import __all__ as _ifaceutils__all__
7571
from ._version import get_versions
7672
from . import exceptions as exceptions
7773
from . import fft as fft
7874
from . import linalg as linalg
7975
from . import random as random
8076
from . import scipy as scipy
8177

78+
# =============================================================================
79+
# Data types
80+
# =============================================================================
81+
from .dpnp_iface_types import (
82+
bool,
83+
bool_,
84+
byte,
85+
cdouble,
86+
complex128,
87+
complex64,
88+
complexfloating,
89+
csingle,
90+
double,
91+
float16,
92+
float32,
93+
float64,
94+
floating,
95+
inexact,
96+
int_,
97+
int8,
98+
int16,
99+
int32,
100+
int64,
101+
integer,
102+
intc,
103+
intp,
104+
longlong,
105+
number,
106+
short,
107+
signedinteger,
108+
single,
109+
ubyte,
110+
uint8,
111+
uint16,
112+
uint32,
113+
uint64,
114+
uintc,
115+
uintp,
116+
unsignedinteger,
117+
ushort,
118+
ulonglong,
119+
)
82120

83121
# =============================================================================
84122
# Routines
@@ -87,6 +125,18 @@
87125
# https://numpy.org/doc/stable/reference/routines.html
88126
# =============================================================================
89127

128+
# -----------------------------------------------------------------------------
129+
# Constants
130+
# -----------------------------------------------------------------------------
131+
from .dpnp_iface_types import (
132+
e,
133+
euler_gamma,
134+
inf,
135+
nan,
136+
newaxis,
137+
pi,
138+
)
139+
90140
# -----------------------------------------------------------------------------
91141
# Array creation routines
92142
# -----------------------------------------------------------------------------
@@ -144,7 +194,6 @@
144194
atleast_3d,
145195
broadcast_arrays,
146196
broadcast_to,
147-
can_cast,
148197
column_stack,
149198
concat,
150199
concatenate,
@@ -169,7 +218,6 @@
169218
require,
170219
reshape,
171220
resize,
172-
result_type,
173221
roll,
174222
rollaxis,
175223
rot90,
@@ -206,6 +254,19 @@
206254
right_shift,
207255
)
208256

257+
# -----------------------------------------------------------------------------
258+
# Data type routines
259+
# -----------------------------------------------------------------------------
260+
from .dpnp_iface_types import (
261+
common_type,
262+
finfo,
263+
iinfo,
264+
isdtype,
265+
issubdtype,
266+
)
267+
from .dpnp_iface_manipulation import can_cast, result_type
268+
from .dpnp_iface_types import dtype
269+
209270
# -----------------------------------------------------------------------------
210271
# Functional programming
211272
# -----------------------------------------------------------------------------
@@ -226,7 +287,6 @@
226287
diagonal,
227288
extract,
228289
fill_diagonal,
229-
flatnonzero,
230290
indices,
231291
iterable,
232292
ix_,
@@ -247,6 +307,7 @@
247307
triu_indices_from,
248308
unravel_index,
249309
)
310+
from .dpnp_flatiter import flatiter
250311

251312
# -----------------------------------------------------------------------------
252313
# Linear algebra
@@ -423,6 +484,7 @@
423484
# Miscellaneous routines
424485
# -----------------------------------------------------------------------------
425486
from .dpnp_iface_manipulation import broadcast_shapes
487+
from .dpnp_iface_utils import byte_bounds
426488
from .dpnp_iface import get_include
427489

428490
# -----------------------------------------------------------------------------
@@ -440,6 +502,7 @@
440502
# Sorting, searching, and counting
441503
# -----------------------------------------------------------------------------
442504
from .dpnp_iface_counting import count_nonzero
505+
from .dpnp_iface_indexing import flatnonzero
443506
from .dpnp_iface_nanfunctions import nanargmax, nanargmin
444507
from .dpnp_iface_searching import (
445508
argmax,
@@ -529,6 +592,57 @@
529592

530593
__all__ = ["__array_namespace_info__", "ndarray"]
531594

595+
# Data types
596+
__all__ = [
597+
"bool",
598+
"bool_",
599+
"byte",
600+
"cdouble",
601+
"complex128",
602+
"complex64",
603+
"complexfloating",
604+
"csingle",
605+
"double",
606+
"float16",
607+
"float32",
608+
"float64",
609+
"floating",
610+
"inexact",
611+
"int_",
612+
"int8",
613+
"int16",
614+
"int32",
615+
"int64",
616+
"integer",
617+
"intc",
618+
"intp",
619+
"longlong",
620+
"number",
621+
"short",
622+
"signedinteger",
623+
"single",
624+
"ubyte",
625+
"uint8",
626+
"uint16",
627+
"uint32",
628+
"uint64",
629+
"uintc",
630+
"uintp",
631+
"unsignedinteger",
632+
"ushort",
633+
"ulonglong",
634+
]
635+
636+
# Constants
637+
__all__ += [
638+
"e",
639+
"euler_gamma",
640+
"inf",
641+
"nan",
642+
"newaxis",
643+
"pi",
644+
]
645+
532646
# Array creation routines
533647
__all__ += [
534648
"arange",
@@ -582,7 +696,6 @@
582696
"atleast_3d",
583697
"broadcast_arrays",
584698
"broadcast_to",
585-
"can_cast",
586699
"column_stack",
587700
"concat",
588701
"concatenate",
@@ -607,7 +720,6 @@
607720
"require",
608721
"reshape",
609722
"resize",
610-
"result_type",
611723
"roll",
612724
"rollaxis",
613725
"rot90",
@@ -642,6 +754,18 @@
642754
"right_shift",
643755
]
644756

757+
# Data type routines
758+
__all__ += [
759+
"can_cast",
760+
"common_type",
761+
"dtype",
762+
"finfo",
763+
"iinfo",
764+
"isdtype",
765+
"issubdtype",
766+
"result_type",
767+
]
768+
645769
# Functional programming
646770
__all__ += [
647771
"apply_along_axis",
@@ -659,7 +783,6 @@
659783
"extract",
660784
"fill_diagonal",
661785
"flatiter",
662-
"flatnonzero",
663786
"indices",
664787
"iterable",
665788
"ix_",
@@ -850,6 +973,7 @@
850973
# Miscellaneous routines
851974
__all__ += [
852975
"broadcast_shapes",
976+
"byte_bounds",
853977
"get_include",
854978
]
855979

@@ -869,6 +993,7 @@
869993
"argwhere",
870994
"argsort",
871995
"count_nonzero",
996+
"flatnonzero",
872997
"partition",
873998
"searchsorted",
874999
"sort",
@@ -933,8 +1058,6 @@
9331058
"synchronize_array_data",
9341059
]
9351060

936-
__all__ += _ifaceutils__all__
937-
9381061
# add submodules
9391062
__all__ += ["exceptions", "fft", "linalg", "random", "scipy"]
9401063

dpnp/dpnp_array_api_info.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838

3939
import dpctl.tensor as dpt
4040

41-
__all__ = ["__array_namespace_info__"]
42-
4341

4442
def __array_namespace_info__():
4543
"""

dpnp/dpnp_iface_types.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -47,60 +47,6 @@
4747
# pylint: disable=no-name-in-module
4848
from .dpnp_utils import get_usm_allocations
4949

50-
__all__ = [
51-
"bool",
52-
"bool_",
53-
"byte",
54-
"cdouble",
55-
"common_type",
56-
"complex128",
57-
"complex64",
58-
"complexfloating",
59-
"csingle",
60-
"double",
61-
"dtype",
62-
"e",
63-
"euler_gamma",
64-
"finfo",
65-
"float16",
66-
"float32",
67-
"float64",
68-
"floating",
69-
"iinfo",
70-
"inexact",
71-
"inf",
72-
"int_",
73-
"int8",
74-
"int16",
75-
"int32",
76-
"int64",
77-
"integer",
78-
"intc",
79-
"intp",
80-
"isdtype",
81-
"issubdtype",
82-
"is_type_supported",
83-
"longlong",
84-
"nan",
85-
"newaxis",
86-
"number",
87-
"pi",
88-
"short",
89-
"signedinteger",
90-
"single",
91-
"ubyte",
92-
"uint8",
93-
"uint16",
94-
"uint32",
95-
"uint64",
96-
"uintc",
97-
"uintp",
98-
"unsignedinteger",
99-
"ushort",
100-
"ulonglong",
101-
]
102-
103-
10450
# pylint: disable=invalid-name
10551
# =============================================================================
10652
# Data types (borrowed from NumPy)
@@ -365,11 +311,3 @@ def issubdtype(arg1, arg2):
365311
"""
366312

367313
return numpy.issubdtype(arg1, arg2)
368-
369-
370-
def is_type_supported(obj_type):
371-
"""Return True if type is supported by DPNP python level."""
372-
373-
if obj_type in (float64, float32, int64, int32):
374-
return True
375-
return False

dpnp/dpnp_iface_utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737

3838
import dpnp
3939

40-
__all__ = ["byte_bounds"]
41-
4240

4341
def byte_bounds(a):
4442
"""

0 commit comments

Comments
 (0)