Skip to content

Commit 1897cf4

Browse files
authored
Add missing dtype aliases (#1309)
* Add missing type aliases * Remove dpnp.object_ type alias * Remove dpnp.longcomplex and dpnp.void * Add dpnp.pi, dpnp.e, dpnp.inf constants * Add remaining numpy constants
1 parent 7ed9b40 commit 1897cf4

16 files changed

+189
-119
lines changed

dpnp/dpnp_algo/dpnp_algo.pyx

+10-10
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ cpdef dpnp_queue_is_cpu():
233233
Internal functions
234234
"""
235235
cdef DPNPFuncType dpnp_dtype_to_DPNPFuncType(dtype):
236-
dt_c = numpy.dtype(dtype).char
237-
kind = numpy.dtype(dtype).kind
236+
dt_c = dpnp.dtype(dtype).char
237+
kind = dpnp.dtype(dtype).kind
238238
if isinstance(kind, int):
239239
kind = chr(kind)
240-
itemsize = numpy.dtype(dtype).itemsize
240+
itemsize = dpnp.dtype(dtype).itemsize
241241

242242
if dt_c == 'd':
243243
return DPNP_FT_DOUBLE
@@ -266,19 +266,19 @@ cdef dpnp_DPNPFuncType_to_dtype(size_t type):
266266
TODO needs to use DPNPFuncType here
267267
"""
268268
if type == <size_t > DPNP_FT_DOUBLE:
269-
return numpy.float64
269+
return dpnp.float64
270270
elif type == <size_t > DPNP_FT_FLOAT:
271-
return numpy.float32
271+
return dpnp.float32
272272
elif type == <size_t > DPNP_FT_LONG:
273-
return numpy.int64
273+
return dpnp.int64
274274
elif type == <size_t > DPNP_FT_INT:
275-
return numpy.int32
275+
return dpnp.int32
276276
elif type == <size_t > DPNP_FT_CMPLX64:
277-
return numpy.complex64
277+
return dpnp.complex64
278278
elif type == <size_t > DPNP_FT_CMPLX128:
279-
return numpy.complex128
279+
return dpnp.complex128
280280
elif type == <size_t > DPNP_FT_BOOL:
281-
return numpy.bool_
281+
return dpnp.bool
282282
else:
283283
utils.checker_throw_type_error("dpnp_DPNPFuncType_to_dtype", type)
284284

dpnp/dpnp_algo/dpnp_algo_statistics.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# cython: language_level=3
22
# -*- coding: utf-8 -*-
33
# *****************************************************************************
4-
# Copyright (c) 2016-2020, Intel Corporation
4+
# Copyright (c) 2016-2023, Intel Corporation
55
# All rights reserved.
66
#
77
# Redistribution and use in source and binary forms, with or without
@@ -129,7 +129,7 @@ cpdef dpnp_average(utils.dpnp_descriptor x1):
129129
array_sum = dpnp_sum(x1).get_pyobj()
130130

131131
""" Numpy interface inconsistency """
132-
return_type = numpy.float32 if (x1.dtype == numpy.float32) else numpy.float64
132+
return_type = dpnp.float32 if (x1.dtype == dpnp.float32) else dpnp.float64
133133

134134
return (return_type(array_sum / x1.size))
135135

dpnp/dpnp_array.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def conj(self):
537537
538538
"""
539539

540-
if not numpy.issubsctype(self.dtype, numpy.complex_):
540+
if not dpnp.issubsctype(self.dtype, dpnp.complex_):
541541
return self
542542
else:
543543
return dpnp.conjugate(self)
@@ -550,7 +550,7 @@ def conjugate(self):
550550
551551
"""
552552

553-
if not numpy.issubsctype(self.dtype, numpy.complex_):
553+
if not dpnp.issubsctype(self.dtype, dpnp.complex_):
554554
return self
555555
else:
556556
return dpnp.conjugate(self)

dpnp/dpnp_iface_linearalgebra.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# distutils: language = c++
33
# -*- coding: utf-8 -*-
44
# *****************************************************************************
5-
# Copyright (c) 2016-2020, Intel Corporation
5+
# Copyright (c) 2016-2023, Intel Corporation
66
# All rights reserved.
77
#
88
# Redistribution and use in source and binary forms, with or without
@@ -269,7 +269,7 @@ def matmul(x1, x2, out=None, **kwargs):
269269
array2_size = x2_desc.size
270270
cost_size = 4096 # 2D array shape(64, 64)
271271

272-
if ((x1_desc.dtype == numpy.float64) or (x1_desc.dtype == numpy.float32)):
272+
if ((x1_desc.dtype == dpnp.float64) or (x1_desc.dtype == dpnp.float32)):
273273
"""
274274
Floating point types are handled via original math library better than SYCL math library
275275
"""

dpnp/dpnp_iface_logic.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,8 @@ def isfinite(x1, out=None, **kwargs):
511511
512512
Examples
513513
--------
514-
>>> import numpy
515514
>>> import dpnp as np
516-
>>> x = np.array([-numpy.inf, 0., numpy.inf])
515+
>>> x = np.array([-np.inf, 0., np.inf])
517516
>>> out = np.isfinite(x)
518517
>>> [i for i in out]
519518
[False, True, False]
@@ -556,9 +555,8 @@ def isinf(x1, out=None, **kwargs):
556555
557556
Examples
558557
--------
559-
>>> import numpy
560558
>>> import dpnp as np
561-
>>> x = np.array([-numpy.inf, 0., numpy.inf])
559+
>>> x = np.array([-np.inf, 0., np.inf])
562560
>>> out = np.isinf(x)
563561
>>> [i for i in out]
564562
[True, False, True]
@@ -602,9 +600,8 @@ def isnan(x1, out=None, **kwargs):
602600
603601
Examples
604602
--------
605-
>>> import numpy
606603
>>> import dpnp as np
607-
>>> x = np.array([numpy.inf, 0., np.nan])
604+
>>> x = np.array([np.inf, 0., np.nan])
608605
>>> out = np.isnan(x)
609606
>>> [i for i in out]
610607
[False, False, True]

dpnp/dpnp_iface_manipulation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def asfarray(x1, dtype=None):
8989

9090
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
9191
if x1_desc:
92-
if dtype is None or not numpy.issubdtype(dtype, numpy.inexact):
92+
if dtype is None or not numpy.issubdtype(dtype, dpnp.inexact):
9393
dtype = dpnp.default_float_type(sycl_queue=x1.sycl_queue)
9494

9595
# if type is the same then same object should be returned

dpnp/dpnp_iface_trigonometric.py

+12-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# distutils: language = c++
33
# -*- coding: utf-8 -*-
44
# *****************************************************************************
5-
# Copyright (c) 2016-2020, Intel Corporation
5+
# Copyright (c) 2016-2023, Intel Corporation
66
# All rights reserved.
77
#
88
# Redistribution and use in source and binary forms, with or without
@@ -136,9 +136,8 @@ def arccosh(x1):
136136
137137
Examples
138138
--------
139-
>>> import numpy
140139
>>> import dpnp as np
141-
>>> x = np.array([numpy.e, 10.0])
140+
>>> x = np.array([np.e, 10.0])
142141
>>> out = np.arccosh(x)
143142
>>> [i for i in out]
144143
[1.65745445, 2.99322285]
@@ -205,9 +204,8 @@ def arcsinh(x1):
205204
206205
Examples
207206
--------
208-
>>> import numpy
209207
>>> import dpnp as np
210-
>>> x = np.array([numpy.e, 10.0])
208+
>>> x = np.array([np.e, 10.0])
211209
>>> out = np.arcsinh(x)
212210
>>> [i for i in out]
213211
[1.72538256, 2.99822295]
@@ -384,9 +382,8 @@ def cos(x1, out=None, **kwargs):
384382
385383
Examples
386384
--------
387-
>>> import numpy
388385
>>> import dpnp as np
389-
>>> x = np.array([0, numpy.pi/2, numpy.pi])
386+
>>> x = np.array([0, np.pi/2, np.pi])
390387
>>> out = np.cos(x)
391388
>>> [i for i in out]
392389
[1.0, 6.123233995736766e-17, -1.0]
@@ -464,9 +461,8 @@ def degrees(x1):
464461
465462
Examples
466463
--------
467-
>>> import numpy
468464
>>> import dpnp as np
469-
>>> rad = np.arange(6.) * numpy.pi/6
465+
>>> rad = np.arange(6.) * np.pi/6
470466
>>> out = np.degrees(rad)
471467
>>> [i for i in out]
472468
[0.0, 30.0, 60.0, 90.0, 120.0, 150.0]
@@ -652,9 +648,8 @@ def log(x1, out=None, **kwargs):
652648
653649
Examples
654650
--------
655-
>>> import numpy
656651
>>> import dpnp as np
657-
>>> x = np.array([1.0, numpy.e, numpy.e**2, 0.0])
652+
>>> x = np.array([1.0, np.e, np.e**2, 0.0])
658653
>>> out = np.log(x)
659654
>>> [i for i in out]
660655
[0.0, 1.0, 2.0, -inf]
@@ -867,9 +862,8 @@ def sin(x1, out=None, **kwargs):
867862
868863
Examples
869864
--------
870-
>>> import numpy
871865
>>> import dpnp as np
872-
>>> x = np.array([0, numpy.pi/2, numpy.pi])
866+
>>> x = np.array([0, np.pi/2, np.pi])
873867
>>> out = np.sin(x)
874868
>>> [i for i in out]
875869
[0.0, 1.0, 1.2246467991473532e-16]
@@ -897,9 +891,8 @@ def sinh(x1):
897891
898892
Examples
899893
--------
900-
>>> import numpy
901894
>>> import dpnp as np
902-
>>> x = np.array([0, numpy.pi/2, numpy.pi])
895+
>>> x = np.array([0, np.pi/2, np.pi])
903896
>>> out = np.sinh(x)
904897
>>> [i for i in out]
905898
[0.0, 2.3012989, 11.548739]
@@ -991,9 +984,8 @@ def tan(x1, out=None, **kwargs):
991984
992985
Examples
993986
--------
994-
>>> import numpy
995987
>>> import dpnp as np
996-
>>> x = np.array([-numpy.pi, numpy.pi/2, numpy.pi])
988+
>>> x = np.array([-np.pi, np.pi/2, np.pi])
997989
>>> out = np.tan(x)
998990
>>> [i for i in out]
999991
[1.22460635e-16, 1.63317787e+16, -1.22460635e-16]
@@ -1021,9 +1013,8 @@ def tanh(x1):
10211013
10221014
Examples
10231015
--------
1024-
>>> import numpy
10251016
>>> import dpnp as np
1026-
>>> x = np.array([-numpy.pi, numpy.pi/2, numpy.pi])
1017+
>>> x = np.array([-np.pi, np.pi/2, np.pi])
10271018
>>> out = np.tanh(x)
10281019
>>> [i for i in out]
10291020
[-0.996272, 0.917152, 0.996272]
@@ -1055,11 +1046,10 @@ def unwrap(x1):
10551046
10561047
Examples
10571048
--------
1058-
>>> import numpy
10591049
>>> import dpnp as np
1060-
>>> phase = np.linspace(0, numpy.pi, num=5)
1050+
>>> phase = np.linspace(0, np.pi, num=5)
10611051
>>> for i in range(3, 5):
1062-
>>> phase[i] += numpy.pi
1052+
>>> phase[i] += np.pi
10631053
>>> out = np.unwrap(phase)
10641054
>>> [i for i in out]
10651055
[0.0, 0.78539816, 1.57079633, 5.49778714, 6.28318531]

0 commit comments

Comments
 (0)