Skip to content

Commit

Permalink
Merge pull request #2227 from IntelPython/update-tests-part-2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vtavana authored Dec 11, 2024
2 parents c4997cc + a9e76ef commit d83ea3d
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 994 deletions.
24 changes: 17 additions & 7 deletions dpnp/tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def get_all_dtypes(


def generate_random_numpy_array(
shape, dtype=None, hermitian=False, seed_value=None
shape, dtype=None, hermitian=False, seed_value=None, low=-10, high=10
):
"""
Generate a random numpy array with the specified shape and dtype.
Expand All @@ -177,13 +177,19 @@ def generate_random_numpy_array(
dtype : str or dtype, optional
Desired data-type for the output array.
If not specified, data type will be determined by numpy.
Default : None
Default : ``None``
hermitian : bool, optional
If True, generates a Hermitian (symmetric if `dtype` is real) matrix.
Default : False
Default : ``False``
seed_value : int, optional
The seed value to initialize the random number generator.
Default : None
Default : ``None``
low : {int, float}, optional
Lower boundary of the generated samples from a uniform distribution.
Default : ``-10``.
high : {int, float}, optional
Upper boundary of the generated samples from a uniform distribution.
Default : ``10``.
Returns
-------
Expand All @@ -197,13 +203,17 @@ def generate_random_numpy_array(
"""

if seed_value is None:
seed_value = 42
numpy.random.seed(seed_value)

a = numpy.random.randn(*shape).astype(dtype)
# dtype=int is needed for 0d arrays
size = numpy.prod(shape, dtype=int)
a = numpy.random.uniform(low, high, size).astype(dtype)
if numpy.issubdtype(a.dtype, numpy.complexfloating):
numpy.random.seed(seed_value)
a += 1j * numpy.random.randn(*shape)
a += 1j * numpy.random.uniform(low, high, size)

a = a.reshape(shape)
if hermitian and a.size > 0:
if a.ndim > 2:
orig_shape = a.shape
Expand Down
Loading

0 comments on commit d83ea3d

Please sign in to comment.