@@ -85,24 +85,19 @@ def assert_dtype_allclose(
8585 assert dpnp_arr .dtype == numpy_arr .dtype
8686
8787
88- def get_integer_dtypes ():
88+ def get_integer_dtypes (no_unsigned = False ):
8989 """
9090 Build a list of integer types supported by DPNP.
9191 """
9292
93+ dtypes = [dpnp .int32 , dpnp .int64 ]
94+
9395 if config .all_int_types :
94- return [
95- dpnp .int8 ,
96- dpnp .int16 ,
97- dpnp .int32 ,
98- dpnp .int64 ,
99- dpnp .uint8 ,
100- dpnp .uint16 ,
101- dpnp .uint32 ,
102- dpnp .uint64 ,
103- ]
96+ dtypes += [dpnp .int8 , dpnp .int16 ]
97+ if not no_unsigned :
98+ dtypes += [dpnp .uint8 , dpnp .uint16 , dpnp .uint32 , dpnp .uint64 ]
10499
105- return [ dpnp . int32 , dpnp . int64 ]
100+ return dtypes
106101
107102
108103def get_complex_dtypes (device = None ):
@@ -147,17 +142,25 @@ def get_float_complex_dtypes(no_float16=True, device=None):
147142 return dtypes
148143
149144
145+ def get_abs_array (data , dtype = None ):
146+ if numpy .issubdtype (dtype , numpy .unsignedinteger ):
147+ data = numpy .abs (data )
148+ return numpy .array (data , dtype = dtype )
149+
150+
150151def get_all_dtypes (
151152 no_bool = False ,
152153 no_float16 = True ,
153154 no_complex = False ,
154155 no_none = False ,
155- device = None ,
156156 xfail_dtypes = None ,
157157 exclude = None ,
158+ no_unsigned = False ,
159+ device = None ,
158160):
159161 """
160- Build a list of types supported by DPNP based on input flags and device capabilities.
162+ Build a list of types supported by DPNP based on
163+ input flags and device capabilities.
161164 """
162165
163166 dev = dpctl .select_default_device () if device is None else device
@@ -166,7 +169,7 @@ def get_all_dtypes(
166169 dtypes = [dpnp .bool ] if not no_bool else []
167170
168171 # add integer types
169- dtypes .extend (get_integer_dtypes ())
172+ dtypes .extend (get_integer_dtypes (no_unsigned = no_unsigned ))
170173
171174 # add floating types
172175 dtypes .extend (get_float_dtypes (no_float16 = no_float16 , device = dev ))
@@ -194,7 +197,13 @@ def not_excluded(dtype):
194197
195198
196199def generate_random_numpy_array (
197- shape , dtype = None , hermitian = False , seed_value = None , low = - 10 , high = 10
200+ shape ,
201+ dtype = None ,
202+ order = "C" ,
203+ hermitian = False ,
204+ seed_value = None ,
205+ low = - 10 ,
206+ high = 10 ,
198207):
199208 """
200209 Generate a random numpy array with the specified shape and dtype.
@@ -210,6 +219,9 @@ def generate_random_numpy_array(
210219 Desired data-type for the output array.
211220 If not specified, data type will be determined by numpy.
212221 Default : ``None``
222+ order : {"C", "F"}, optional
223+ Specify the memory layout of the output array.
224+ Default: ``"C"``.
213225 hermitian : bool, optional
214226 If True, generates a Hermitian (symmetric if `dtype` is real) matrix.
215227 Default : ``False``
@@ -226,7 +238,7 @@ def generate_random_numpy_array(
226238 Returns
227239 -------
228240 out : numpy.ndarray
229- A random numpy array of the specified shape and dtype .
241+ A random numpy array of the specified shape, dtype and memory layout .
230242 The array is Hermitian or symmetric if `hermitian` is True.
231243
232244 Note:
@@ -239,10 +251,13 @@ def generate_random_numpy_array(
239251 seed_value = 42
240252 numpy .random .seed (seed_value )
241253
254+ if numpy .issubdtype (dtype , numpy .unsignedinteger ):
255+ low = 0
256+
242257 # dtype=int is needed for 0d arrays
243258 size = numpy .prod (shape , dtype = int )
244259 a = numpy .random .uniform (low , high , size ).astype (dtype )
245- if numpy .issubdtype (a . dtype , numpy .complexfloating ):
260+ if numpy .issubdtype (dtype , numpy .complexfloating ):
246261 a += 1j * numpy .random .uniform (low , high , size )
247262
248263 a = a .reshape (shape )
@@ -256,6 +271,10 @@ def generate_random_numpy_array(
256271 a = a .reshape (orig_shape )
257272 else :
258273 a = numpy .conj (a .T ) @ a
274+
275+ # a.reshape(shape) returns an array in C order by default
276+ if order != "C" and a .ndim > 1 :
277+ a = numpy .array (a , order = order )
259278 return a
260279
261280
0 commit comments