Skip to content

Commit

Permalink
Import dpnp to be working with numpy 2.0 in the environment (#1985)
Browse files Browse the repository at this point in the history
* Remove alias on numpy.complex_

* Remove alias on numpy.cfloat

* Remove alias on numpy.float and numpy.float_

* Remove alias on numpy.float and numpy.singlecomplex

* Remove aliases on numpy.Inf, numpy.Infinity and numpy.infty constants

* Get rid of dpnp.float in the code

* Remove aliases on numpy.NAN and numpy.NaN constants

* Remove aliases on numpy.NINF and numpy.PINF constants

* Remove aliases on numpy.NZERO and numpy.PZERO constants
  • Loading branch information
antonwolfy authored Aug 19, 2024
1 parent efba9a4 commit 0b7f324
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 106 deletions.
16 changes: 2 additions & 14 deletions doc/reference/dtypes_table.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,23 @@ Table below shows a list of all supported data types (dtypes) and constants of t
- :obj:`bool <numpy.bool_>`
- :obj:`int32 <numpy.int32>`
- :obj:`int64 <numpy.int64>`
- :obj:`float32 <numpy.float32>`
- :obj:`float64 <numpy.float64>`
- :obj:`complex64 <numpy.complex64>`
- :obj:`complex128 <numpy.complex128>`
-
- :obj:`bool_ <numpy.bool_>`
- :obj:`cdouble <numpy.cdouble>`
- :obj:`complex <numpy.complex_>`
- :obj:`cfloat <numpy.cfloat>`
- :obj:`csingle <numpy.csingle>`
- :obj:`double <numpy.double>`
- :obj:`float <numpy.float>`
- :obj:`float_ <numpy.float_>`
- :obj:`float16 <numpy.float16>`
- :obj:`int <numpy.int>`
- :obj:`int_ <numpy.int_>`
- :obj:`intc <numpy.intc>`
- :obj:`single <numpy.single>`
- :obj:`singlecomplex <numpy.singlecomplex>`
-
- :obj:`e <numpy.e>`
- :obj:`euler_gamma <numpy.euler_gamma>`
- :obj:`Inf <numpy.Inf>`
- :obj:`inf <numpy.inf>`
- :obj:`Infinity <numpy.Infinity>`
- :obj:`infty <numpy.infty>`
- :obj:`NAN <numpy.NAN>`
- :obj:`NaN <numpy.NaN>`
- :obj:`nan <numpy.nan>`
- :obj:`NINF <numpy.NINF>`
- :obj:`NZERO <numpy.NZERO>`
- :obj:`pi <numpy.pi>`
- :obj:`PINF <numpy.PINF>`
- :obj:`PZERO <numpy.PZERO>`
7 changes: 5 additions & 2 deletions dpnp/dpnp_iface_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3266,7 +3266,7 @@ def tri(
/,
M=None,
k=0,
dtype=dpnp.float,
dtype=float,
*,
device=None,
usm_type="device",
Expand Down Expand Up @@ -3376,7 +3376,10 @@ def tri(
if _k is None:
raise TypeError(f"`k` must be a integer data type, but got {type(k)}")

_dtype = dpnp.default_float_type() if dtype in (dpnp.float, None) else dtype
sycl_dev = dpnp.get_normalized_queue_device(
sycl_queue=sycl_queue, device=device
).sycl_device
_dtype = map_dtype_to_device(dtype, sycl_dev)

if usm_type is None:
usm_type = "device"
Expand Down
2 changes: 1 addition & 1 deletion dpnp/dpnp_iface_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ def isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False):
_b += atol
result = less_equal(dpnp.abs(a - b), _b)

# Handle "Inf" values: they are treated as equal if they are in the same
# Handle "inf" values: they are treated as equal if they are in the same
# place and of the same sign in both arrays
result &= isfinite(b)
result |= a == b
Expand Down
4 changes: 2 additions & 2 deletions dpnp/dpnp_iface_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2295,7 +2295,7 @@ def gradient(f, *varargs, axis=None, edge_order=1):
>>> np.maximum(x1, x2)
array([nan, nan, nan])
>>> np.maximum(np.array(np.Inf), 1)
>>> np.maximum(np.array(np.inf), 1)
array(inf)
"""

Expand Down Expand Up @@ -2375,7 +2375,7 @@ def gradient(f, *varargs, axis=None, edge_order=1):
>>> np.minimum(x1, x2)
array([nan, nan, nan])
>>> np.minimum(np.array(-np.Inf), 1)
>>> np.minimum(np.array(-np.inf), 1)
array(-inf)
"""

Expand Down
6 changes: 3 additions & 3 deletions dpnp/dpnp_iface_nanfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def nanmax(a, axis=None, out=None, keepdims=False, initial=None, where=True):
When positive infinity and negative infinity are present:
>>> np.nanmax(np.array([1, 2, np.nan, np.NINF]))
>>> np.nanmax(np.array([1, 2, np.nan, -np.inf]))
array(2.)
>>> np.nanmax(np.array([1, 2, np.nan, np.inf]))
array(inf)
Expand Down Expand Up @@ -639,7 +639,7 @@ def nanmin(a, axis=None, out=None, keepdims=False, initial=None, where=True):
>>> np.nanmin(np.array([1, 2, np.nan, np.inf]))
array(1.)
>>> np.nanmin(np.array([1, 2, np.nan, np.NINF]))
>>> np.nanmin(np.array([1, 2, np.nan, -np.inf]))
array(-inf)
"""
Expand Down Expand Up @@ -831,7 +831,7 @@ def nansum(
array([2., 1.])
>>> np.nansum(np.array([1, np.nan, np.inf]))
array(inf)
>>> np.nansum(np.array([1, np.nan, np.NINF]))
>>> np.nansum(np.array([1, np.nan, -np.inf]))
array(-inf)
>>> # both +/- infinity present
>>> np.nansum(np.array([1, np.nan, np.inf, -np.inf]))
Expand Down
4 changes: 2 additions & 2 deletions dpnp/dpnp_iface_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def max(a, axis=None, out=None, keepdims=False, initial=None, where=True):
array([1, 3])
>>> b = np.arange(5, dtype=float)
>>> b[2] = np.NaN
>>> b[2] = np.nan
>>> np.max(b)
array(nan)
Expand Down Expand Up @@ -736,7 +736,7 @@ def min(a, axis=None, out=None, keepdims=False, initial=None, where=True):
array([0, 2])
>>> b = np.arange(5, dtype=float)
>>> b[2] = np.NaN
>>> b[2] = np.nan
>>> np.min(b)
array(nan)
Expand Down
28 changes: 0 additions & 28 deletions dpnp/dpnp_iface_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,22 @@
"bool",
"bool_",
"cdouble",
"complex_",
"complex128",
"complex64",
"complexfloating",
"cfloat",
"csingle",
"double",
"dtype",
"e",
"euler_gamma",
"finfo",
"float",
"float_",
"float16",
"float32",
"float64",
"floating",
"iinfo",
"inexact",
"Inf",
"inf",
"Infinity",
"infty",
"int",
"int_",
"int32",
Expand All @@ -74,19 +67,12 @@
"issubdtype",
"issubsctype",
"is_type_supported",
"NAN",
"NaN",
"nan",
"newaxis",
"NINF",
"NZERO",
"number",
"pi",
"PINF",
"PZERO",
"signedinteger",
"single",
"singlecomplex",
]


Expand All @@ -97,16 +83,12 @@
bool = numpy.bool_
bool_ = numpy.bool_
cdouble = numpy.cdouble
complex_ = numpy.complex_
complex128 = numpy.complex128
complex64 = numpy.complex64
complexfloating = numpy.complexfloating
cfloat = numpy.cfloat
csingle = numpy.csingle
double = numpy.double
dtype = numpy.dtype
float = numpy.float_
float_ = numpy.float_
float16 = numpy.float16
float32 = numpy.float32
float64 = numpy.float64
Expand All @@ -122,27 +104,17 @@
number = numpy.number
signedinteger = numpy.signedinteger
single = numpy.single
singlecomplex = numpy.singlecomplex


# =============================================================================
# Constants (borrowed from NumPy)
# =============================================================================
e = numpy.e
euler_gamma = numpy.euler_gamma
Inf = numpy.Inf
inf = numpy.inf
Infinity = numpy.Infinity
infty = numpy.infty
NAN = numpy.NAN
NaN = numpy.NaN
nan = numpy.nan
newaxis = None
NINF = numpy.NINF
NZERO = numpy.NZERO
pi = numpy.pi
PINF = numpy.PINF
PZERO = numpy.PZERO


# pylint: disable=redefined-outer-name
Expand Down
2 changes: 1 addition & 1 deletion dpnp/linalg/dpnp_utils_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ def _multi_dot_matrix_chain_order(n, arrays, return_costs=False):
for ll in range(1, n):
for i in range(n - ll):
j = i + ll
m[i, j] = dpnp.Inf
m[i, j] = dpnp.inf
for k in range(i, j):
q = m[i, k] + m[k + 1, j] + p[i] * p[k + 1] * p[j + 1]
if q < m[i, j]:
Expand Down
Loading

0 comments on commit 0b7f324

Please sign in to comment.