Skip to content

Commit 8cb5656

Browse files
authored
Merge branch 'IntelPython:master' into feature-sparse-linalg-solvers
2 parents d9734d8 + def2ea1 commit 8cb5656

9 files changed

Lines changed: 47 additions & 9 deletions

File tree

.github/workflows/build-sphinx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ jobs:
197197
# Upload artifact for fork PRs
198198
- name: Upload docs artifact (Fork PRs)
199199
if: env.GH_EVENT_PR_OPEN == 'true' && steps.check_fork.outputs.is_fork == 'true'
200-
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
200+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
201201
with:
202202
name: pr-${{ github.event.number }}-docs
203203
path: ${{ env.PUBLISH_DIR }}

.github/workflows/openssf-scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ jobs:
7272

7373
# Upload the results to GitHub's code scanning dashboard.
7474
- name: "Upload to code-scanning"
75-
uses: github/codeql-action/upload-sarif@9e0d7b8d25671d64c341c19c0152d693099fb5ba # v4.35.5
75+
uses: github/codeql-action/upload-sarif@7211b7c8077ea37d8641b6271f6a365a22a5fbfa # v4.36.0
7676
with:
7777
sarif_file: results.sarif

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ repos:
6464
additional_dependencies:
6565
- tomli
6666
- repo: https://github.com/psf/black
67-
rev: 26.3.1
67+
rev: 26.5.1
6868
hooks:
6969
- id: black
7070
exclude: "dpnp/_version.py"
@@ -128,7 +128,7 @@ repos:
128128
hooks:
129129
- id: actionlint
130130
- repo: https://github.com/BlankSpruce/gersemi-pre-commit
131-
rev: 0.27.5
131+
rev: 0.27.6
132132
hooks:
133133
- id: gersemi
134134
exclude: "dpnp/backend/cmake/Modules/"

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ This release is compatible with NumPy 2.4.5.
3030
* Fixed incorrect `dpnp.tensor.acosh` result for `complex(±0, NaN)` special case to match the Python Array API specification [#2914](https://github.com/IntelPython/dpnp/pull/2914)
3131
* Fixed fork PR documentation workflow failures by implementing conditional publishing strategy: upstream PRs publish to GitHub Pages with comment, fork PRs upload artifacts [#2910](https://github.com/IntelPython/dpnp/pull/2910)
3232
* Fixed missing `libtensor` headers in the installed `dpnp` package [#2915](https://github.com/IntelPython/dpnp/pull/2915)
33+
* Fixed boolean mask indexing to raise `IndexError` when mask dimensions don't match the indexed array dimensions, aligning with NumPy behavior. Previously, incompatible boolean masks silently returned incorrect results instead of raising an error [#2929](https://github.com/IntelPython/dpnp/pull/2929)
34+
* Fixed a bug in `astype` where casting floating point types to unsigned integral types could cause an intermediate signed integral type to overflow, leading to incorrect results [#2930](https://github.com/IntelPython/dpnp/pull/2930)
3335

3436
### Security
3537

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ if(_use_onemath)
247247
FetchContent_Declare(
248248
onemath_library
249249
GIT_REPOSITORY https://github.com/uxlfoundation/oneMath.git
250-
GIT_TAG
251-
6ff3a43e555dbb20357017d48f0f6c6263259895 # v0.9
250+
GIT_TAG 6ff3a43e555dbb20357017d48f0f6c6263259895 # v0.9
252251
)
253252
endif()
254253

dpnp/tensor/_slicing.pxi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ cdef bint _is_boolean(object x) except *:
107107
return False
108108

109109

110+
cdef _check_mask_shape(sh : tuple, ma_sh : tuple, Py_ssize_t axis):
111+
cdef Py_ssize_t i, sh_i, ma_i
112+
for i, ma_i in enumerate(ma_sh):
113+
sh_i = sh[axis + i]
114+
if ma_i not in (0, sh_i):
115+
raise IndexError(
116+
"boolean index did not match indexed array along dimension "
117+
f"{axis + i}; dimension is {sh_i} but corresponding boolean "
118+
f"dimension is {ma_i}"
119+
)
120+
121+
110122
def _basic_slice_meta(ind, shape : tuple, strides : tuple, offset : int):
111123
"""
112124
Give basic slicing index `ind` and array layout information produce
@@ -353,6 +365,7 @@ def _basic_slice_meta(ind, shape : tuple, strides : tuple, offset : int):
353365
new_advanced_ind.append(ind_i)
354366
dt_k = ind_i.dtype.kind
355367
if dt_k == "b":
368+
_check_mask_shape(shape, ind_i.shape, k)
356369
k_new = k + ind_i.ndim
357370
else:
358371
k_new = k + 1

dpnp/tensor/libtensor/include/utils/type_utils.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,14 @@ dstTy convert_impl(const srcTy &v)
9999
else if constexpr (!std::is_integral_v<srcTy> &&
100100
!std::is_same_v<dstTy, bool> &&
101101
std::is_integral_v<dstTy> && std::is_unsigned_v<dstTy>) {
102-
// first cast to signed variant, the cast to unsigned one
103-
using signedT = typename std::make_signed_t<dstTy>;
104-
return static_cast<dstTy>(convert_impl<signedT, srcTy>(v));
102+
// for negative values, cast through signed integer to get two's
103+
// complement wrapping
104+
using intermediateT =
105+
std::conditional_t<sizeof(dstTy) < sizeof(std::int32_t),
106+
std::int32_t, std::int64_t>;
107+
return (v < srcTy{0})
108+
? static_cast<dstTy>(static_cast<intermediateT>(v))
109+
: static_cast<dstTy>(v);
105110
}
106111
else {
107112
return static_cast<dstTy>(v);

dpnp/tests/tensor/test_usm_ndarray_ctor.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,15 @@ def test_astype_gh_2121():
11001100
assert dpt.all(res == expected)
11011101

11021102

1103+
def test_astype_gh_2882():
1104+
get_queue_or_skip()
1105+
1106+
x = dpt.asarray([160.0, 120.0], dtype="f4")
1107+
r = dpt.astype(x, dpt.uint8)
1108+
expected = dpt.asarray([160, 120], dtype="u1")
1109+
assert dpt.all(r == expected)
1110+
1111+
11031112
def test_copy():
11041113
try:
11051114
X = dpt.usm_ndarray((5, 5), "i4")[2:4, 1:4]

dpnp/tests/tensor/test_usm_ndarray_indexing.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,3 +2052,13 @@ def test_getitem_impl_fn_invalid_inp():
20522052
no_array_inds = (2, 3)
20532053
with pytest.raises(TypeError):
20542054
_take_multi_index(x, no_array_inds, 0, 0)
2055+
2056+
2057+
def test_boolean_mask_validation():
2058+
x = dpt.reshape(dpt.arange(3**5, dtype="i4"), (3,) * 5)
2059+
ii = dpt.asarray(1)
2060+
i0 = dpt.asarray(0, dtype="?")
2061+
i1 = dpt.asarray(0, dtype="?")
2062+
2063+
with pytest.raises(IndexError):
2064+
x[ii, i0[dpt.newaxis], ii, i1[dpt.newaxis], :]

0 commit comments

Comments
 (0)