Update implementation of dpnp.putmask - #3014
Conversation
|
View rendered docs @ https://intelpython.github.io/dpnp/pull/3014/index.html |
|
Array API standard conformance tests for dpnp=0.21.0dev3=py314h509198e_43 ran successfully. |
| # -*- coding: utf-8 -*- | ||
| # ***************************************************************************** | ||
| # Copyright (c) 2025, Intel Corporation | ||
| # Copyright (c) 2026, Intel Corporation |
There was a problem hiding this comment.
It's year when file was created, no need to update
| # Copyright (c) 2026, Intel Corporation | |
| # Copyright (c) 2025, Intel Corporation |
| # values must always be flattened in C-order. | ||
| values_1d = values.ravel(order="C") | ||
| if a.dtype != values_1d.dtype: | ||
| values_1d = dpnp.astype( |
There was a problem hiding this comment.
Seems no test is covering that
| @@ -1,5 +1,5 @@ | |||
| //***************************************************************************** | |||
| // Copyright (c) 2025, Intel Corporation | |||
| // Copyright (c) 2026, Intel Corporation | |||
There was a problem hiding this comment.
| // Copyright (c) 2026, Intel Corporation | |
| // Copyright (c) 2025, Intel Corporation |
| array([[ 0, 1, 2], | ||
| [ 9, 16, 25]]) | ||
|
|
||
| If `values` is smaller than `x1` it is repeated: |
There was a problem hiding this comment.
| If `values` is smaller than `x1` it is repeated: | |
| If `values` is smaller than `a` it is repeated: |
| :obj:`dpnp.take` : Take elements from an array along an axis. | ||
| :obj:`dpnp.copyto` : Copies values from one array to another. | ||
|
|
||
|
|
There was a problem hiding this comment.
Double blank like:
| for xp in (numpy, cupy): | ||
| a = xp.array([1, 2, 3]) | ||
| mask = xp.array([True, False]) | ||
| with pytest.raises((ValueError, IndexError)): |
There was a problem hiding this comment.
Can be aligned now:
| with pytest.raises(ValueError): |
| const std::size_t values_size = values.get_size(); | ||
|
|
||
| // the contig kernel cycles `values` by the memory-linear index, which | ||
| // matches numpy's C-order `values.flat` only for C-contiguous data |
There was a problem hiding this comment.
but no check here that values.is_c_contiguous() has to be true
| std::size_t nelems, | ||
| std::size_t val_size) |
There was a problem hiding this comment.
| std::size_t nelems, | |
| std::size_t val_size) | |
| const std::size_t nelems, | |
| const std::size_t val_size) |
| elems_per_wi * (ndit.get_group(0) * ndit.get_local_range(0) + | ||
| sg.get_group_id()[0] * sgSize); | ||
|
|
||
| const bool values_no_repeat = (val_size_ >= nelems_); |
There was a problem hiding this comment.
can be moved away of if-else block to reduce duplication
| #pragma unroll | ||
| for (std::uint8_t vec_id = 0; vec_id < vec_sz; ++vec_id) { | ||
| out_vec[vec_id] = | ||
| (mask_vec[vec_id] != static_cast<std::uint8_t>(0)) |
There was a problem hiding this comment.
for consistency with other places in the kernel:
| (mask_vec[vec_id] != static_cast<std::uint8_t>(0)) | |
| (mask_vec[vec_id]) |
This PR proposes a new implementation of
dpnp.putmaskreplacing the legacydpnp_putmaskimplementation with dedicated SYCL kernels : a vectorized contiguous kernel and a strided kernel for F-contiguous/transposed arrays.It also fully reworks the
putmasktests by addingTestPutMaskPerformance results on PVC are below: