Skip to content

Commit d83ea3d

Browse files
authored
Merge pull request #2227 from IntelPython/update-tests-part-2
This is part 2 of a series of PRs in which the tests are refactored. In this PR, `test_linalg.py`, `test_product.py`, `test_statistics.py`, `test_fft.py`, and `test_sort.py` are updated. Part 1 was #2210. The main change is to use a common function `generate_random_numpy_array` from `dpnp/tests/helper.py` for generating input array for different tests.
2 parents c4997cc + a9e76ef commit d83ea3d

File tree

8 files changed

+284
-994
lines changed

8 files changed

+284
-994
lines changed

dpnp/tests/helper.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def get_all_dtypes(
162162

163163

164164
def generate_random_numpy_array(
165-
shape, dtype=None, hermitian=False, seed_value=None
165+
shape, dtype=None, hermitian=False, seed_value=None, low=-10, high=10
166166
):
167167
"""
168168
Generate a random numpy array with the specified shape and dtype.
@@ -177,13 +177,19 @@ def generate_random_numpy_array(
177177
dtype : str or dtype, optional
178178
Desired data-type for the output array.
179179
If not specified, data type will be determined by numpy.
180-
Default : None
180+
Default : ``None``
181181
hermitian : bool, optional
182182
If True, generates a Hermitian (symmetric if `dtype` is real) matrix.
183-
Default : False
183+
Default : ``False``
184184
seed_value : int, optional
185185
The seed value to initialize the random number generator.
186-
Default : None
186+
Default : ``None``
187+
low : {int, float}, optional
188+
Lower boundary of the generated samples from a uniform distribution.
189+
Default : ``-10``.
190+
high : {int, float}, optional
191+
Upper boundary of the generated samples from a uniform distribution.
192+
Default : ``10``.
187193
188194
Returns
189195
-------
@@ -197,13 +203,17 @@ def generate_random_numpy_array(
197203
198204
"""
199205

206+
if seed_value is None:
207+
seed_value = 42
200208
numpy.random.seed(seed_value)
201209

202-
a = numpy.random.randn(*shape).astype(dtype)
210+
# dtype=int is needed for 0d arrays
211+
size = numpy.prod(shape, dtype=int)
212+
a = numpy.random.uniform(low, high, size).astype(dtype)
203213
if numpy.issubdtype(a.dtype, numpy.complexfloating):
204-
numpy.random.seed(seed_value)
205-
a += 1j * numpy.random.randn(*shape)
214+
a += 1j * numpy.random.uniform(low, high, size)
206215

216+
a = a.reshape(shape)
207217
if hermitian and a.size > 0:
208218
if a.ndim > 2:
209219
orig_shape = a.shape

0 commit comments

Comments
 (0)