Skip to content

Commit cdc9bcd

Browse files
FIX: random.chisquare fallback (#356)
* update fallback
1 parent a61cce9 commit cdc9bcd

File tree

1 file changed

+16
-39
lines changed

1 file changed

+16
-39
lines changed

dpnp/random/dpnp_iface_random.py

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -215,31 +215,13 @@ def chisquare(df, size=None):
215215
216216
Draw samples from a chi-square distribution.
217217
218-
When `df` independent random variables, each with standard normal
219-
distributions (mean 0, variance 1), are squared and summed, the
220-
resulting distribution is chi-square (see Notes). This distribution
221-
is often used in hypothesis testing.
218+
For full documentation refer to :obj:`numpy.random.chisquare`.
222219
223-
Parameters
224-
----------
225-
df : float
226-
Number of degrees of freedom, must be > 0.
227-
size : int or tuple of ints, optional
228-
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
229-
``m * n * k`` samples are drawn. If size is ``None`` (default),
230-
a single value is returned if ``df`` is a scalar. Otherwise,
231-
``np.array(df).size`` samples are drawn.
232-
233-
Returns
234-
-------
235-
out : ndarray or scalar
236-
Drawn samples from the parameterized chi-square distribution.
237-
238-
Raises
239-
------
240-
ValueError
241-
When `df` <= 0 or when an inappropriate `size` (e.g. ``size=-1``)
242-
is given.
220+
Limitations
221+
-----------
222+
Parameter ``df`` is supported as a scalar.
223+
Otherwise, :obj:`numpy.random.chisquare(df, size)` samples are drawn.
224+
Output array data type is :obj:`dpnp.float64`.
243225
244226
Examples
245227
--------
@@ -249,23 +231,18 @@ def chisquare(df, size=None):
249231
"""
250232

251233
if not use_origin_backend(df) and dpnp_queue_is_cpu():
252-
if size is None:
253-
size = 1
254-
elif isinstance(size, tuple):
255-
for dim in size:
256-
if not isinstance(dim, int):
257-
checker_throw_value_error("chisquare", "type(dim)", type(dim), int)
258-
elif not isinstance(size, int):
259-
checker_throw_value_error("chisquare", "type(size)", type(size), int)
260-
261234
# TODO:
262235
# array_like of floats for `df`
263-
# add check for df array like, after adding array-like interface for df param
264-
if df <= 0:
265-
checker_throw_value_error("chisquare", "df", df, "positive")
266-
# TODO:
267-
# float to int, safe
268-
return dpnp_chisquare(int(df), size)
236+
if not dpnp.isscalar(df):
237+
pass
238+
elif df <= 0:
239+
pass
240+
else:
241+
if size is None:
242+
size = 1
243+
# TODO:
244+
# float to int, safe
245+
return dpnp_chisquare(int(df), size)
269246

270247
return call_origin(numpy.random.chisquare, df, size)
271248

0 commit comments

Comments
 (0)