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

Add new tests for dpnp.einsum and adopt it with NumPy-2.0.0 #2012

Merged
merged 6 commits into from
Aug 27, 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
6 changes: 3 additions & 3 deletions dpnp/dpnp_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,14 +930,14 @@ def flatten(self, order="C"):
Read the elements using this index order, and place the elements
into the reshaped array using this index order.

- "C" means to read / write the elements using C-like index
- ``"C"`` means to read / write the elements using C-like index
order, with the last axis index changing fastest, back to the
first axis index changing slowest.
- "F" means to read / write the elements using Fortran-like
- ``"F"`` means to read / write the elements using Fortran-like
index order, with the first index changing fastest, and the
last index changing slowest.

The default is ``"C"``.
Default: ``"C"``.

Returns
-------
Expand Down
59 changes: 37 additions & 22 deletions dpnp/dpnp_iface_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def array(
Default: ``True``.
order : {"C", "F", "A", "K"}, optional
Memory layout of the newly output array.
Default: "K".
Default: ``"K"``.
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where the output array is created.
The `device` can be ``None`` (the default), an OneAPI filter selector
Expand Down Expand Up @@ -366,7 +366,8 @@ def asanyarray(
used that can represent the values (by considering Promotion Type Rule
and device capabilities when necessary).
order : {None, "C", "F", "A", "K"}, optional
Memory layout of the newly output array. Default: "K".
Memory layout of the newly output array.
Default: ``"K"``.
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where the output array is created.
The `device` can be ``None`` (the default), an OneAPI filter selector
Expand Down Expand Up @@ -470,7 +471,7 @@ def asarray(
Default: ``None``.
order : {None, "C", "F", "A", "K"}, optional
Memory layout of the newly output array.
Default: "K".
Default: ``"K"``.
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where the output array is created.
The `device` can be ``None`` (the default), an OneAPI filter selector
Expand Down Expand Up @@ -916,8 +917,9 @@ def diag(v, /, k=0, *, device=None, usm_type=None, sycl_queue=None):
default values, returns a read/write view of its k-th diagonal.
- Otherwise, returns a copy of its k-th diagonal.
k : int, optional
Diagonal in question. The default is 0. Use k > 0 for diagonals above
Diagonal in question. Use k > 0 for diagonals above
the main diagonal, and k < 0 for diagonals below the main diagonal.
Default: ``0``.
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where the output array is created.
The `device` can be ``None`` (the default), an OneAPI filter selector
Expand Down Expand Up @@ -1123,7 +1125,8 @@ def empty(
Default is the default floating point data type for the device where
input array is allocated.
order : {None, "C", "F"}, optional
Memory layout of the newly output array. Default: "C".
Memory layout of the newly output array.
Default: ``"C"``.
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where the output array is created.
The `device` can be ``None`` (the default), an OneAPI filter selector
Expand Down Expand Up @@ -1225,7 +1228,8 @@ def empty_like(
Default is the default floating point data type for the device where
input array is allocated.
order : {None, "C", "F"}, optional
Memory layout of the newly output array. Default: "C".
Memory layout of the newly output array.
Default: ``"C"``.
shape : {None, int, sequence of ints}
Overrides the shape of the result.
device : {None, string, SyclDevice, SyclQueue}, optional
Expand Down Expand Up @@ -1342,7 +1346,8 @@ def eye(
Default is the default floating point data type for the device where
input array is allocated.
order : {None, "C", "F"}, optional
Memory layout of the newly output array. Default: "C".
Memory layout of the newly output array.
Default: ``"C"``.
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where the output array is created.
The `device` can be ``None`` (the default), an OneAPI filter selector
Expand Down Expand Up @@ -1453,7 +1458,8 @@ def frombuffer(
count : int, optional
Number of items to read. ``-1`` means all data in the buffer.
offset : int, optional
Start reading the buffer from this offset (in bytes); default: 0.
Start reading the buffer from this offset (in bytes).
Default: ``0``.
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where the output array is created.
The `device` can be ``None`` (the default), an OneAPI filter selector
Expand Down Expand Up @@ -1981,7 +1987,8 @@ def full(
Default is the default floating point data type for the device where
input array is allocated.
order : {None, "C", "F"}, optional
Memory layout of the newly output array. Default: "C".
Memory layout of the newly output array.
Default: ``"C"``.
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where the output array is created.
The `device` can be ``None`` (the default), an OneAPI filter selector
Expand Down Expand Up @@ -2086,7 +2093,8 @@ def full_like(
Default is the default floating point data type for the device where
input array is allocated.
order : {None, "C", "F"}, optional
Memory layout of the newly output array. Default: "C".
Memory layout of the newly output array.
Default: ``"C"``.
shape : {None, int, sequence of ints}
Overrides the shape of the result.
device : {None, string, SyclDevice, SyclQueue}, optional
Expand Down Expand Up @@ -2202,7 +2210,8 @@ def geomspace(
``num + 1`` values are spaced over the interval in log-space, of which
all but the last (a sequence of length `num`) are returned.
num : int, optional
Number of samples to generate. Default is 50.
Number of samples to generate.
Default: ``50``.
dtype : {None, dtype}, optional
The desired dtype for the array. If not given, a default dtype will be
used that can represent the values (by considering Promotion Type Rule
Expand All @@ -2221,7 +2230,7 @@ def geomspace(
A SYCL queue to use for output array allocation and copying.
endpoint : bool, optional
If ``True``, `stop` is the last sample. Otherwise, it is not included.
Default is ``True``.
Default: ``True``.
axis : int, optional
The axis in the result to store the samples. Relevant only if start or
stop are array-like. By default (0), the samples will be along a new
Expand Down Expand Up @@ -2446,7 +2455,7 @@ def linspace(
A SYCL queue to use for output array allocation and copying.
endpoint : bool, optional
If ``True``, `stop` is the last sample. Otherwise, it is not included.
Default is ``True``.
Default: ``True``.
retstep : bool, optional
If ``True``, return (samples, step), where step is the spacing between
samples.
Expand Down Expand Up @@ -2653,7 +2662,8 @@ def logspace(
values are spaced over the interval in log-space, of which all but
the last (a sequence of length `num`) are returned.
num : int, optional
Number of samples to generate. Default is 50.
Number of samples to generate.
Default: ``50``.
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where the output array is created.
The `device` can be ``None`` (the default), an OneAPI filter selector
Expand All @@ -2668,15 +2678,16 @@ def logspace(
A SYCL queue to use for output array allocation and copying.
endpoint : {bool}, optional
If ``True``, stop is the last sample. Otherwise, it is not included.
Default is ``True``.
Default: ``True``.
base : {array_like}, optional
Input data, in any form that can be converted to an array. This
includes scalars, lists, lists of tuples, tuples, tuples of tuples,
tuples of lists, and ndarrays. The base of the log space, in any form
that can be converted to an array.This includes scalars, lists, lists
of tuples, tuples, tuples of tuples, tuples of lists, and ndarrays.
The `step` size between the elements in ``ln(samples) / ln(base)``
(or log_base(samples)) is uniform. Default is 10.0.
(or log_base(samples)) is uniform.
Default: ``10.0``.
dtype : {None, dtype}, optional
The desired dtype for the array. If not given, a default dtype will be
used that can represent the values (by considering Promotion Type Rule
Expand Down Expand Up @@ -3020,7 +3031,8 @@ def ones(
Default is the default floating point data type for the device where
input array is allocated.
order : {None, "C", "F"}, optional
Memory layout of the newly output array. Default: "C".
Memory layout of the newly output array.
Default: ``"C"``.
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where the output array is created.
The `device` can be ``None`` (the default), an OneAPI filter selector
Expand Down Expand Up @@ -3128,7 +3140,8 @@ def ones_like(
Default is the default floating point data type for the device where
input array is allocated.
order : {None, "C", "F"}, optional
Memory layout of the newly output array. Default: "C".
Memory layout of the newly output array.
Default: ``"C"``.
shape : {None, int, sequence of ints}
Overrides the shape of the result.
device : {None, string, SyclDevice, SyclQueue}, optional
Expand Down Expand Up @@ -3300,7 +3313,7 @@ def tri(
k : int, optional
The sub-diagonal at and below which the array is filled. k = 0 is
the main diagonal, while k < 0 is below it, and k > 0 is above.
The default is 0.
Default: ``0``.
dtype : {None, dtype}, optional
The desired dtype for the array, e.g., dpnp.int32.
Default is the default floating point data type for the device where
Expand Down Expand Up @@ -3663,11 +3676,12 @@ def zeros(
shape : {int, sequence of ints}
Shape of the new array, e.g., (2, 3) or 2.
dtype : {None, dtype}, optional
The desired dtype for the array, e.g., dpnp.int32.
The desired dtype for the array, e.g., `dpnp.int32`.
Default is the default floating point data type for the device where
input array is allocated.
order : {None, "C", "F"}, optional
Memory layout of the newly output array. Default: "C".
Memory layout of the newly output array.
Default: ``"C"``.
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where the output array is created.
The `device` can be ``None`` (the default), an OneAPI filter selector
Expand Down Expand Up @@ -3775,7 +3789,8 @@ def zeros_like(
Default is the default floating point data type for the device where
input array is allocated.
order : {None, "C", "F"}, optional
Memory layout of the newly output array. Default: "C".
Memory layout of the newly output array.
Default: ``"C"``.
shape : {None, int, sequence of ints}
Overrides the shape of the result.
device : {None, string, SyclDevice, SyclQueue}, optional
Expand Down
32 changes: 22 additions & 10 deletions dpnp/dpnp_iface_linearalgebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,16 @@ def dot(a, b, out=None):


def einsum(
*operands, out=None, dtype=None, order="K", casting="safe", optimize=False
*operands,
out=None,
dtype=None,
order="K",
casting="same_kind",
optimize=False,
):
"""
einsum(subscripts, *operands, out=None, dtype=None, order="K", \
casting="safe", optimize=False)
casting="same_kind", optimize=False)

Evaluates the Einstein summation convention on the operands.

Expand All @@ -186,14 +191,14 @@ def einsum(
If provided, the calculation is done into this array.
dtype : {dtype, None}, optional
If provided, forces the calculation to use the data type specified.
Default is ``None``.
Default: ``None``.
order : {"C", "F", "A", "K"}, optional
Controls the memory layout of the output. ``"C"`` means it should be
C-contiguous. ``"F"`` means it should be F-contiguous, ``"A"`` means
it should be ``"F"`` if the inputs are all ``"F"``, ``"C"`` otherwise.
``"K"`` means it should be as close to the layout as the inputs as
is possible, including arbitrarily permuted axes.
Default is ``"K"``.
Default: ``"K"``.
casting : {"no", "equiv", "safe", "same_kind", "unsafe"}, optional
Controls what kind of data casting may occur. Setting this to
``"unsafe"`` is not recommended, as it can adversely affect
Expand All @@ -206,12 +211,17 @@ def einsum(
like float64 to float32, are allowed.
* ``"unsafe"`` means any data conversions may be done.

Default is ``"safe"``.
Please note that, in contrast to NumPy, the default setting here is
``"same_kind"``. This is to prevent errors that may occur when data
needs to be converted to `float64`, but the device does not support it.
In such cases, the data is instead converted to `float32`.
Default: ``"same_kind"``.
optimize : {False, True, "greedy", "optimal"}, optional
Controls if intermediate optimization should occur. No optimization
will occur if ``False`` and ``True`` will default to the ``"greedy"``
algorithm. Also accepts an explicit contraction list from the
:obj:`dpnp.einsum_path` function. Default is ``False``.
:obj:`dpnp.einsum_path` function.
Default: ``False``.

Returns
-------
Expand Down Expand Up @@ -453,7 +463,7 @@ def einsum_path(*operands, optimize="greedy", einsum_call=False):
the number of terms in the contraction. Equivalent to the
``"optimal"`` path for most contractions.

Default is ``"greedy"``.
Default: ``"greedy"``.

Returns
-------
Expand Down Expand Up @@ -736,16 +746,18 @@ def matmul(
out : {None, dpnp.ndarray, usm_ndarray}, optional
Alternative output array in which to place the result. It must have
a shape that matches the signature `(n,k),(k,m)->(n,m)` but the type
(of the calculated values) will be cast if necessary. Default: ``None``.
(of the calculated values) will be cast if necessary.
Default: ``None``.
dtype : {None, dtype}, optional
Type to use in computing the matrix product. By default, the returned
array will have data type that is determined by considering
Promotion Type Rule and device capabilities.
casting : {"no", "equiv", "safe", "same_kind", "unsafe"}, optional
Controls what kind of data casting may occur. Default: ``"same_kind"``.
Controls what kind of data casting may occur.
Default: ``"same_kind"``.
order : {"C", "F", "A", "K", None}, optional
Memory layout of the newly output array, if parameter `out` is ``None``.
Default: "K".
Default: ``"K"``.
axes : {list of tuples}, optional
A list of tuples with indices of axes the matrix product should operate
on. For instance, for the signature of ``(i,j),(j,k)->(i,k)``, the base
Expand Down
3 changes: 2 additions & 1 deletion dpnp/dpnp_iface_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,8 @@ def concatenate(
corresponding to axis (the first, by default).
axis : int, optional
The axis along which the arrays will be joined. If axis is ``None``,
arrays are flattened before use. Default is 0.
arrays are flattened before use.
Default: ``0``.
out : dpnp.ndarray, optional
If provided, the destination to place the result. The shape must be
correct, matching that of what concatenate would have returned
Expand Down
14 changes: 7 additions & 7 deletions dpnp/dpnp_iface_searching.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,17 @@ def searchsorted(a, v, side="left", sorter=None):
sort it.
v : {dpnp.ndarray, usm_ndarray, scalar}
Values to insert into `a`.
side : {'left', 'right'}, optional
If ``'left'``, the index of the first suitable location found is given.
If ``'right'``, return the last such index. If there is no suitable
side : {"left", "right"}, optional
If ``"left"``, the index of the first suitable location found is given.
If ``"right"``, return the last such index. If there is no suitable
index, return either 0 or N (where N is the length of `a`).
Default is ``'left'``.
Default: ``"left"``.
sorter : {dpnp.ndarray, usm_ndarray}, optional
Optional 1-D array of integer indices that sort array a into ascending
order. They are typically the result of :obj:`dpnp.argsort`.
Out of bound index values of `sorter` array are treated using `"wrap"`
mode documented in :py:func:`dpnp.take`.
Default is ``None``.
Out of bound index values of `sorter` array are treated using
``"wrap"`` mode documented in :py:func:`dpnp.take`.
Default: ``None``.

Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion dpnp/dpnp_iface_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def argsort(a, axis=-1, kind=None, order=None):
sorting. The default is -1, which sorts along the last axis.
kind : {None, "stable"}, optional
Default is ``None``, which is equivalent to `"stable"`.
Unlike in NumPy any other options are not accepted here.
Unlike NumPy, no other option is accepted here.

Returns
-------
Expand Down
12 changes: 7 additions & 5 deletions dpnp/dpnp_iface_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,18 @@ def average(a, axis=None, weights=None, returned=False, *, keepdims=False):

The only constraint on `weights` is that `sum(weights)` must not be 0.
returned : {bool}, optional
Default is ``False``. If ``True``, the tuple (`average`,
`sum_of_weights`) is returned, otherwise only the average is returned.
If `weights=None`, `sum_of_weights` is equivalent to the number of
elements over which the average is taken.
If ``True``, the tuple (`average`, `sum_of_weights`) is returned,
otherwise only the average is returned. If `weights=None`,
`sum_of_weights` is equivalent to the number of elements over which
the average is taken.
Default: ``False``.
keepdims : {None, bool}, optional
If ``True``, the reduced axes (dimensions) are included in the result
as singleton dimensions, so that the returned array remains
compatible with the input array according to Array Broadcasting
rules. Otherwise, if ``False``, the reduced axes are not included in
the returned array. Default: ``False``.
the returned array.
Default: ``False``.

Returns
-------
Expand Down
8 changes: 4 additions & 4 deletions dpnp/dpnp_iface_trigonometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -2206,10 +2206,10 @@ def unwrap(p, discont=None, axis=-1, *, period=2 * dpnp.pi):
p : {dpnp.ndarray, usm_ndarray}
Input array.
discont : {float, None}, optional
Maximum discontinuity between values, default is ``period / 2``. Values
below ``period / 2`` are treated as if they were ``period / 2``. To
have an effect different from the default, `discont` should be larger
than ``period / 2``.
Maximum discontinuity between values, default is ``None`` which is an
alias for ``period / 2``. Values below ``period / 2`` are treated as if
they were ``period / 2``. To have an effect different from the default,
`discont` should be larger than ``period / 2``.
Default: ``None``.
axis : int, optional
Axis along which unwrap will operate, default is the last axis.
Expand Down
Loading
Loading