From e6bab60902c76f9c2dc7ba3cd0d1e618689a0a91 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 1 Apr 2024 14:09:21 -0700 Subject: [PATCH 1/7] Improves `tile` docstring --- dpctl/tensor/_manipulation_functions.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/dpctl/tensor/_manipulation_functions.py b/dpctl/tensor/_manipulation_functions.py index eabd32efed..b66319e463 100644 --- a/dpctl/tensor/_manipulation_functions.py +++ b/dpctl/tensor/_manipulation_functions.py @@ -937,21 +937,28 @@ def tile(x, repetitions, /): `repetitions`. For `N` = len(`repetitions`) and `M` = len(`x.shape`): - - if `M < N`, `x` will have `N - M` new axes prepended to its shape - - if `M > N`, `repetitions` will have `M - N` new axes 1 prepended to it + + * If `M < N`, `x` will have `N - M` new axes prepended to its shape + * If `M > N`, `repetitions` will have `M - N` ones prepended to it Args: x (usm_ndarray): input array repetitions (Union[int, Tuple[int, ...]]): - The number of repetitions for each dimension. + The number of repetitions along each dimension of `x`. Returns: - usm_narray: - Array with tiled elements. - The returned array must have the same data type as `x`, - is created on the same device as `x` and has the same USM - allocation type as `x`. + usm_ndarray: + tiled output array. + + The returned array will have rank `max(M, N)`. If `S` is + the shape of `x` after prepending dimensions and `R` is + `repetitions` after prepending ones, then the shape of + the result will be `S[i] * R[i]` for each dimension `i`. + + The returned array will have the same data type as `x`. + The returned array will be located on the same device as + `x` and have the same USM allocation type as `x`. """ if not isinstance(x, dpt.usm_ndarray): raise TypeError(f"Expected usm_ndarray type, got {type(x)}.") From 21969769bbd5a047a79fd14880c0cf4d6314b7e8 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 1 Apr 2024 14:44:31 -0700 Subject: [PATCH 2/7] Improves `repeat` docstring --- dpctl/tensor/_manipulation_functions.py | 42 ++++++++++++++----------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/dpctl/tensor/_manipulation_functions.py b/dpctl/tensor/_manipulation_functions.py index b66319e463..27ad1327db 100644 --- a/dpctl/tensor/_manipulation_functions.py +++ b/dpctl/tensor/_manipulation_functions.py @@ -717,32 +717,38 @@ def swapaxes(X, axis1, axis2): def repeat(x, repeats, /, *, axis=None): """repeat(x, repeats, axis=None) - Repeat elements of an array. + Repeat elements of an array on a per-element basis. Args: x (usm_ndarray): input array repeats (Union[int, Sequence[int, ...], usm_ndarray]): The number of repetitions for each element. - `repeats` is broadcast to fit the shape of the given axis. + + `repeats` must be broadcast compatible with `N` where `N` is + `prod(x.shape)` if `axis` is `None` and `x.shape[axis]` + otherwise. + If `repeats` is an array, it must have an integer data type. - Otherwise, `repeats` must be a Python integer, tuple, list, or - range. + Otherwise, `repeats` must be a Python integer or sequence of + Python integers (i.e., a tuple, list, or range). axis (Optional[int]): The axis along which to repeat values. If `axis` is `None`, the - function repeats elements of the flattened array. - Default: `None`. + function repeats elements of the flattened array. Default: `None`. Returns: - usm_narray: - Array with repeated elements. - The returned array must have the same data type as `x`, is created - on the same device as `x` and has the same USM allocation type as - `x`. If `axis` is `None`, the returned array is one-dimensional, + usm_ndarray: + output array with repeated elements. + + If `axis` is `None`, the returned array is one-dimensional, otherwise, it has the same shape as `x`, except for the axis along which elements were repeated. + The returned array will have the same data type as `x`. + The returned array will be located on the same device as `x` and + have the same USM allocation type as `x`. + Raises: AxisError: if `axis` value is invalid. """ @@ -951,14 +957,14 @@ def tile(x, repetitions, /): usm_ndarray: tiled output array. - The returned array will have rank `max(M, N)`. If `S` is - the shape of `x` after prepending dimensions and `R` is - `repetitions` after prepending ones, then the shape of - the result will be `S[i] * R[i]` for each dimension `i`. - + The returned array will have rank `max(M, N)`. If `S` is the + shape of `x` after prepending dimensions and `R` is + `repetitions` after prepending ones, then the shape of the + result will be `S[i] * R[i]` for each dimension `i`. + The returned array will have the same data type as `x`. - The returned array will be located on the same device as - `x` and have the same USM allocation type as `x`. + The returned array will be located on the same device as `x` and + have the same USM allocation type as `x`. """ if not isinstance(x, dpt.usm_ndarray): raise TypeError(f"Expected usm_ndarray type, got {type(x)}.") From 0be4c0fa9a96cc18e515add7222599fae96eec20 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 1 Apr 2024 14:47:25 -0700 Subject: [PATCH 3/7] Fixed typos in `angle` and `reciprocal` docstrings --- dpctl/tensor/_elementwise_funcs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpctl/tensor/_elementwise_funcs.py b/dpctl/tensor/_elementwise_funcs.py index 526fb25462..5a47962bbd 100644 --- a/dpctl/tensor/_elementwise_funcs.py +++ b/dpctl/tensor/_elementwise_funcs.py @@ -2160,7 +2160,7 @@ Default: "K". Returns: - usm_narray: + usm_ndarray: An array containing the element-wise reciprocals. The returned array has a floating-point data type determined by the Type Promotion Rules. @@ -2195,7 +2195,7 @@ Default: "K". Returns: - usm_narray: + usm_ndarray: An array containing the element-wise phase angles. The returned array has a floating-point data type determined by the Type Promotion Rules. From c260762be04014d385f395aae5745a10487a765f Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 1 Apr 2024 14:48:49 -0700 Subject: [PATCH 4/7] Fixed typos in docstrings for `permute_dims, `moveaxis`, and `swapaxes` --- dpctl/tensor/_manipulation_functions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dpctl/tensor/_manipulation_functions.py b/dpctl/tensor/_manipulation_functions.py index 27ad1327db..107404ebcf 100644 --- a/dpctl/tensor/_manipulation_functions.py +++ b/dpctl/tensor/_manipulation_functions.py @@ -95,7 +95,7 @@ def permute_dims(X, /, axes): `(0,1,...,N-1)` where `N` is the number of axes (dimensions) of `x`. Returns: - usm_narray: + usm_ndarray: An array with permuted axes. The returned array must has the same data type as `x`, is created on the same device as `x` and has the same USM allocation @@ -646,7 +646,7 @@ def moveaxis(X, source, destination, /): in the half-open interval `[-N, N)`. Returns: - usm_narray: + usm_ndarray: Array with moved axes. The returned array must has the same data type as `x`, is created on the same device as `x` and has the same @@ -693,7 +693,7 @@ def swapaxes(X, axis1, axis2): a valid `axis` must be in the half-open interval `[-N, N)`. Returns: - usm_narray: + usm_ndarray: Array with swapped axes. The returned array must has the same data type as `x`, is created on the same device as `x` and has the same USM From a0f779a9fe7415292b9c67c6aab23cc652e64f01 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 1 Apr 2024 14:49:23 -0700 Subject: [PATCH 5/7] Fixes typo and grammar in `nonzero` docstring --- dpctl/tensor/_indexing_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpctl/tensor/_indexing_functions.py b/dpctl/tensor/_indexing_functions.py index 91c82a1849..65605ed626 100644 --- a/dpctl/tensor/_indexing_functions.py +++ b/dpctl/tensor/_indexing_functions.py @@ -326,7 +326,7 @@ def nonzero(arr): Return the indices of non-zero elements. - Returns the tuple of usm_narrays, one for each dimension + Returns a tuple of usm_ndarrays, one for each dimension of `arr`, containing the indices of the non-zero elements in that dimension. The values of `arr` are always tested in row-major, C-style order. From 79eac5bb126838365cd526937f34086641bec7f4 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 1 Apr 2024 14:50:01 -0700 Subject: [PATCH 6/7] Fixes a typo in `populate_params` in `blackscholes.pyx` example --- examples/cython/usm_memory/blackscholes/blackscholes.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/cython/usm_memory/blackscholes/blackscholes.pyx b/examples/cython/usm_memory/blackscholes/blackscholes.pyx index dbb64de154..b7d37993f3 100644 --- a/examples/cython/usm_memory/blackscholes/blackscholes.pyx +++ b/examples/cython/usm_memory/blackscholes/blackscholes.pyx @@ -135,7 +135,7 @@ def populate_params( """ populate_params(params, pl, ph, sl, sh, tl, th, rl, rh, vl, vh, seed) Args: - params: usm_narray + params: usm_ndarray Array of shape (n_opts, 5) to populate with price, strike, time to maturity, interest rate, volatility rate per option using uniform distribution with provided distribution parameters. From 6fe783eb5e77e545033ba90b0ec78123654ead34 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Mon, 1 Apr 2024 16:39:12 -0700 Subject: [PATCH 7/7] Change to `broadcast-compatible` per PR review by @oleksandr-pavlyk --- dpctl/tensor/_manipulation_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpctl/tensor/_manipulation_functions.py b/dpctl/tensor/_manipulation_functions.py index 107404ebcf..c3bb6bdc4b 100644 --- a/dpctl/tensor/_manipulation_functions.py +++ b/dpctl/tensor/_manipulation_functions.py @@ -725,7 +725,7 @@ def repeat(x, repeats, /, *, axis=None): repeats (Union[int, Sequence[int, ...], usm_ndarray]): The number of repetitions for each element. - `repeats` must be broadcast compatible with `N` where `N` is + `repeats` must be broadcast-compatible with `N` where `N` is `prod(x.shape)` if `axis` is `None` and `x.shape[axis]` otherwise.