Skip to content

Commit 4d5d49a

Browse files
ManasviGoyalianna
andauthored
fix: index access issue in argmin and argmax complex (#3176)
Co-authored-by: Ianna Osborne <[email protected]>
1 parent a9e48eb commit 4d5d49a

4 files changed

+154
-12
lines changed

awkward-cpp/src/cpu-kernels/awkward_reduce_argmax_complex.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ ERROR awkward_reduce_argmax_complex(
1717
for (int64_t i = 0; i < lenparents; i++) {
1818
int64_t parent = parents[i];
1919
if (toptr[parent] == -1 ||
20-
(fromptr[i * 2] > fromptr[toptr[parent * 2]] ||
21-
(fromptr[i * 2] == fromptr[toptr[parent * 2]] &&
22-
fromptr[i * 2 + 1] > fromptr[toptr[parent * 2 + 1]]))) {
20+
(fromptr[i * 2] > fromptr[toptr[parent] * 2] ||
21+
(fromptr[i * 2] == fromptr[toptr[parent] * 2] &&
22+
fromptr[i * 2 + 1] > fromptr[toptr[parent] * 2 + 1]))) {
2323
toptr[parent] = i;
2424
}
2525
}

awkward-cpp/src/cpu-kernels/awkward_reduce_argmin_complex.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ ERROR awkward_reduce_argmin_complex(
1717
for (int64_t i = 0; i < lenparents; i++) {
1818
int64_t parent = parents[i];
1919
if (toptr[parent] == -1 ||
20-
(fromptr[i * 2] < fromptr[toptr[parent * 2]] ||
21-
(fromptr[i * 2] == fromptr[toptr[parent * 2]] &&
22-
fromptr[i * 2 + 1] < fromptr[toptr[parent * 2 + 1]]))) {
20+
(fromptr[i * 2] < fromptr[toptr[parent] * 2] ||
21+
(fromptr[i * 2] == fromptr[toptr[parent] * 2] &&
22+
fromptr[i * 2 + 1] < fromptr[toptr[parent] * 2 + 1]))) {
2323
toptr[parent] = i;
2424
}
2525
}

kernel-specification.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -4038,9 +4038,9 @@ kernels:
40384038
toptr[k] = -1
40394039
for i in range(lenparents):
40404040
parent = parents[i]
4041-
if (toptr[parent] == -1 or (fromptr[i * 2] > fromptr[toptr[parent * 2]] or
4042-
(fromptr[i * 2] == fromptr[toptr[parent * 2]] and
4043-
fromptr[i * 2 + 1] > fromptr[toptr[parent * 2 + 1]]))):
4041+
if (toptr[parent] == -1 or (fromptr[i * 2] > fromptr[toptr[parent] * 2] or
4042+
(fromptr[i * 2] == fromptr[toptr[parent] * 2] and
4043+
fromptr[i * 2 + 1] > fromptr[toptr[parent] * 2 + 1]))):
40444044
toptr[parent] = i
40454045
automatic-tests: false
40464046

@@ -4150,9 +4150,9 @@ kernels:
41504150
toptr[k] = -1
41514151
for i in range(lenparents):
41524152
parent = parents[i]
4153-
if (toptr[parent] == -1 or (fromptr[i * 2] < fromptr[toptr[parent * 2]] or
4154-
(fromptr[i * 2] == fromptr[toptr[parent * 2]] and
4155-
fromptr[i * 2 + 1] < fromptr[toptr[parent * 2 + 1]]))):
4153+
if (toptr[parent] == -1 or (fromptr[i * 2] < fromptr[toptr[parent] * 2] or
4154+
(fromptr[i * 2] == fromptr[toptr[parent] * 2] and
4155+
fromptr[i * 2 + 1] < fromptr[toptr[parent] * 2 + 1]))):
41564156
toptr[parent] = i
41574157
automatic-tests: false
41584158

kernel-test-data.json

+142
Original file line numberDiff line numberDiff line change
@@ -23992,6 +23992,148 @@
2399223992
}
2399323993
]
2399423994
},
23995+
{
23996+
"name": "awkward_reduce_argmin_complex",
23997+
"status": true,
23998+
"tests": [
23999+
{
24000+
"error": false,
24001+
"message": "",
24002+
"inputs": {
24003+
"fromptr": [],
24004+
"lenparents": 0,
24005+
"outlength": 0,
24006+
"parents": []
24007+
},
24008+
"outputs": {
24009+
"toptr": []
24010+
}
24011+
},
24012+
{
24013+
"error": false,
24014+
"message": "",
24015+
"inputs": {
24016+
"fromptr": [0, 0],
24017+
"lenparents": 1,
24018+
"outlength": 1,
24019+
"parents": [0]
24020+
},
24021+
"outputs": {
24022+
"toptr": [0]
24023+
}
24024+
},
24025+
{
24026+
"error": false,
24027+
"message": "",
24028+
"inputs": {
24029+
"fromptr": [1, 0, 0, 1],
24030+
"lenparents": 2,
24031+
"outlength": 1,
24032+
"parents": [0, 0]
24033+
},
24034+
"outputs": {
24035+
"toptr": [1]
24036+
}
24037+
},
24038+
{
24039+
"error": false,
24040+
"message": "",
24041+
"inputs": {
24042+
"fromptr": [2, 2, 3, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23],
24043+
"lenparents": 9,
24044+
"outlength": 6,
24045+
"parents": [0, 0, 0, 2, 2, 3, 4, 4, 5]
24046+
},
24047+
"outputs": {
24048+
"toptr": [0, -1, 3, 5, 6, 8]
24049+
}
24050+
},
24051+
{
24052+
"error": false,
24053+
"message": "",
24054+
"inputs": {
24055+
"fromptr": [1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1],
24056+
"lenparents": 6,
24057+
"outlength": 4,
24058+
"parents": [0, 0, 0, 2, 2, 3]
24059+
},
24060+
"outputs": {
24061+
"toptr": [2, -1, 4, 5]
24062+
}
24063+
}
24064+
]
24065+
},
24066+
{
24067+
"name": "awkward_reduce_argmax_complex",
24068+
"status": true,
24069+
"tests": [
24070+
{
24071+
"error": false,
24072+
"message": "",
24073+
"inputs": {
24074+
"fromptr": [],
24075+
"lenparents": 0,
24076+
"outlength": 0,
24077+
"parents": []
24078+
},
24079+
"outputs": {
24080+
"toptr": []
24081+
}
24082+
},
24083+
{
24084+
"error": false,
24085+
"message": "",
24086+
"inputs": {
24087+
"fromptr": [0, 0],
24088+
"lenparents": 1,
24089+
"outlength": 1,
24090+
"parents": [0]
24091+
},
24092+
"outputs": {
24093+
"toptr": [0]
24094+
}
24095+
},
24096+
{
24097+
"error": false,
24098+
"message": "",
24099+
"inputs": {
24100+
"fromptr": [1, 0, 0, 1],
24101+
"lenparents": 2,
24102+
"outlength": 1,
24103+
"parents": [0, 0]
24104+
},
24105+
"outputs": {
24106+
"toptr": [0]
24107+
}
24108+
},
24109+
{
24110+
"error": false,
24111+
"message": "",
24112+
"inputs": {
24113+
"fromptr": [2, 2, 3, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23],
24114+
"lenparents": 9,
24115+
"outlength": 6,
24116+
"parents": [0, 0, 0, 2, 2, 3, 4, 4, 5]
24117+
},
24118+
"outputs": {
24119+
"toptr": [2, -1, 4, 5, 7, 8]
24120+
}
24121+
},
24122+
{
24123+
"error": false,
24124+
"message": "",
24125+
"inputs": {
24126+
"fromptr": [1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1],
24127+
"lenparents": 6,
24128+
"outlength": 4,
24129+
"parents": [0, 0, 0, 2, 2, 3]
24130+
},
24131+
"outputs": {
24132+
"toptr": [0, -1, 3, 5]
24133+
}
24134+
}
24135+
]
24136+
},
2399524137
{
2399624138
"name": "awkward_reduce_max",
2399724139
"status": true,

0 commit comments

Comments
 (0)