Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating tests - Part2 #2227

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading