Skip to content

Commit

Permalink
Merge branch 'main' into feat/named_axes
Browse files Browse the repository at this point in the history
  • Loading branch information
pfackeldey committed Oct 3, 2024
2 parents 247c1e1 + cfe58f3 commit fd3c166
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
- name: Prepare build files
run: pipx run nox -s prepare

- uses: pypa/cibuildwheel@v2.20
- uses: pypa/cibuildwheel@v2.21
env:
CIBW_BUILD: "${{ matrix.build }}*"
CIBW_ARCHS: ${{ matrix.arch }}
Expand Down Expand Up @@ -157,7 +157,7 @@ jobs:

- uses: docker/setup-qemu-action@v3.2.0

- uses: pypa/cibuildwheel@v2.20
- uses: pypa/cibuildwheel@v2.21
env:
CIBW_BUILD: cp${{ matrix.python }}-*
CIBW_ARCHS: ${{ matrix.arch }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
with:
subject-path: "dist/awkward*cpp-*"

- uses: pypa/gh-action-pypi-publish@v1.10.1
- uses: pypa/gh-action-pypi-publish@v1.10.2
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh attestation verify dist/awkward-*.whl --repo ${{ github.repository }}

- uses: pypa/gh-action-pypi-publish@v1.10.1
- uses: pypa/gh-action-pypi-publish@v1.10.2

publish-headers:
name: "Publish header-only libraries alongside release"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/packaging-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ jobs:
- name: Prepare build files
run: pipx run nox -s prepare

- uses: pypa/cibuildwheel@v2.20
- uses: pypa/cibuildwheel@v2.21
env:
CIBW_ARCHS_MACOS: universal2
CIBW_BUILD: cp39-win_amd64 cp310-manylinux_x86_64 cp38-macosx_universal2
with:
config-file: cibuildwheel.toml
package-dir: awkward-cpp

- uses: pypa/cibuildwheel@v2.20
- uses: pypa/cibuildwheel@v2.21
if: matrix.os == 'ubuntu-latest'
env:
CIBW_BUILD: cp312-manylinux_x86_64
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upload-nightly-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
ls -l dist/
- name: Upload wheels to Anaconda Cloud as nightlies
uses: scientific-python/upload-nightly-action@b67d7fcc0396e1128a474d1ab2b48aa94680f9fc # 0.5.0
uses: scientific-python/upload-nightly-action@82396a2ed4269ba06c6b2988bb4fd568ef3c3d6b # 0.6.1
with:
artifacts_path: dist
anaconda_nightly_upload_token: ${{ secrets.ANACONDA_ORG_UPLOAD_TOKEN }}
54 changes: 24 additions & 30 deletions header-only/examples/pybind11/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,36 @@ using MyBuilder = RecordBuilder<
*/
template<typename T>
py::object snapshot_builder(const T &builder) {
// We need NumPy (to allocate arrays) and Awkward Array (ak.from_buffers).
// pybind11 will raise a ModuleNotFoundError if they aren't installed.
auto np = py::module::import("numpy");
auto ak = py::module::import("awkward");

auto dtype_u1 = np.attr("dtype")("u1");

// How much memory to allocate?
std::map <std::string, size_t> names_nbytes = {};
std::map<std::string, size_t> names_nbytes;
builder.buffer_nbytes(names_nbytes);

// Allocate memory
std::map<std::string, void *> buffers = {};
for (auto it: names_nbytes) {
uint8_t *ptr = new uint8_t[it.second];
buffers[it.first] = (void *) ptr;
}
// Ask NumPy to allocate memory and get pointers to the raw buffers.
py::dict py_container;
std::map<std::string, void*> cpp_container;
for (auto name_nbytes : names_nbytes) {
py::object array = np.attr("empty")(name_nbytes.second, dtype_u1);

// Write non-contiguous contents to memory
builder.to_buffers(buffers);
auto from_buffers = py::module::import("awkward").attr("from_buffers");

// Build Python dictionary containing arrays
// dtypes not important here as long as they match the underlying buffer
// as Awkward Array calls `frombuffer` to convert to the correct type
py::dict container;
for (auto it: buffers) {

py::capsule free_when_done(it.second, [](void *data) {
uint8_t *dataPtr = reinterpret_cast<uint8_t *>(data);
delete[] dataPtr;
});

uint8_t *data = reinterpret_cast<uint8_t *>(it.second);
container[py::str(it.first)] = py::array_t<uint8_t>(
{names_nbytes[it.first]},
{sizeof(uint8_t)},
data,
free_when_done
);
size_t pointer = py::cast<size_t>(array.attr("ctypes").attr("data"));
void* raw_data = (void*)pointer;

py::str py_name(name_nbytes.first);
py_container[py_name] = array;
cpp_container[name_nbytes.first] = raw_data;
}
return from_buffers(builder.form(), builder.length(), container);

// Write non-contiguous contents to memory.
builder.to_buffers(cpp_container);

// Build Python dictionary containing arrays.
return ak.attr("from_buffers")(builder.form(), builder.length(), py_container);
}


Expand Down

0 comments on commit fd3c166

Please sign in to comment.