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

fix: added kernel specializations for awkward_ListOffsetArray_reduce_local_nextparents_64 #2572

Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion awkward-cpp/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "scikit_build_core.build"

[project]
name = "awkward_cpp"
version = "20"
version = "21"
dependencies = [
"numpy>=1.18.0"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,45 @@

#include "awkward/kernels.h"

template <typename C>
ERROR awkward_ListOffsetArray_reduce_local_nextparents_64(
int64_t* nextparents,
const int64_t* offsets,
const C* offsets,
int64_t length) {
int64_t initialoffset = offsets[0];
int64_t initialoffset = (int64_t)(offsets[0]);
for (int64_t i = 0; i < length; i++) {
for (int64_t j = offsets[i] - initialoffset;
for (int64_t j = (int64_t)(offsets[i]) - initialoffset;
j < offsets[i + 1] - initialoffset;
j++) {
nextparents[j] = i;
}
}
return success();
}
ERROR awkward_ListOffsetArray32_reduce_local_nextparents_64(
int64_t* nextparents,
const int32_t* offsets,
int64_t length) {
return awkward_ListOffsetArray_reduce_local_nextparents_64(
nextparents,
offsets,
length);
}
ERROR awkward_ListOffsetArrayU32_reduce_local_nextparents_64(
int64_t* nextparents,
const uint32_t* offsets,
int64_t length) {
return awkward_ListOffsetArray_reduce_local_nextparents_64(
nextparents,
offsets,
length);
}
ERROR awkward_ListOffsetArray64_reduce_local_nextparents_64(
int64_t* nextparents,
const int64_t* offsets,
int64_t length) {
return awkward_ListOffsetArray_reduce_local_nextparents_64(
nextparents,
offsets,
length);
}
12 changes: 11 additions & 1 deletion kernel-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2217,11 +2217,21 @@ kernels:

- name: awkward_ListOffsetArray_reduce_local_nextparents_64
specializations:
- name: awkward_ListOffsetArray_reduce_local_nextparents_64
- name: awkward_ListOffsetArray32_reduce_local_nextparents_64
args:
- {name: nextparents, type: "List[int64_t]", dir: out}
- {name: offsets, type: "Const[List[int32_t]]", dir: in, role: reducer-offsets}
- {name: length, type: "int64_t", dir: in, role: reducer-length}
- name: awkward_ListOffsetArray64_reduce_local_nextparents_64
args:
- {name: nextparents, type: "List[int64_t]", dir: out}
- {name: offsets, type: "Const[List[int64_t]]", dir: in, role: reducer-offsets}
- {name: length, type: "int64_t", dir: in, role: reducer-length}
- name: awkward_ListOffsetArrayU32_reduce_local_nextparents_64
args:
- {name: nextparents, type: "List[int64_t]", dir: out}
- {name: offsets, type: "Const[List[uint32_t]]", dir: in, role: reducer-offsets}
- {name: length, type: "int64_t", dir: in, role: reducer-length}
description: null
definition: |
def awkward_ListOffsetArray_reduce_local_nextparents_64(nextparents, offsets, length):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ classifiers = [
"Topic :: Utilities",
]
dependencies = [
"awkward_cpp==20",
"awkward_cpp==21",
"importlib_resources;python_version < \"3.9\"",
"numpy>=1.18.0",
"packaging",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE

import numpy as np
import pytest

import awkward as ak


@pytest.mark.parametrize(
"indextype", [ak.index.Index32, ak.index.IndexU32, ak.index.Index64]
)
def test(indextype):
array = ak.Array(
ak.contents.ListOffsetArray(
indextype(np.array([0, 3, 3, 5, 6, 9])),
ak.contents.NumpyArray(np.array([6, 9, 9, 4, 4, 2, 5, 2, 7], np.int64)),
)
)
if indextype is ak.index.Index32:
assert array.layout.offsets.data.dtype == np.dtype(np.int32)
elif indextype is ak.index.IndexU32:
assert array.layout.offsets.data.dtype == np.dtype(np.uint32)
elif indextype is ak.index.Index64:
assert array.layout.offsets.data.dtype == np.dtype(np.int64)

assert ak.argsort(array).tolist() == [[0, 1, 2], [], [0, 1], [0], [1, 0, 2]]