3#ifndef AWKWARDPY_CONTENT_H_
4#define AWKWARDPY_CONTENT_H_
6#include <pybind11/numpy.h>
7#include <pybind11/pybind11.h>
8#include <pybind11/stl.h>
13namespace py = pybind11;
18py::class_<ak::ArrayBuilder>
24 py::dict container() {
29 empty_buffer(
const std::string& name, int64_t num_bytes)
override {
30 py::object pyarray = py::module::import(
"numpy").attr(
"empty")(num_bytes,
"u1");
31 py::array_t<uint8_t> rawarray = pyarray.cast<py::array_t<uint8_t>>();
32 py::buffer_info rawinfo = rawarray.request();
33 container_[py::str(name)] = pyarray;
38 copy_buffer(
const std::string& name,
const void* source, int64_t num_bytes)
override {
39 py::object pyarray = py::module::import(
"numpy").attr(
"empty")(num_bytes,
"u1");
40 py::array_t<uint8_t> rawarray = pyarray.cast<py::array_t<uint8_t>>();
41 py::buffer_info rawinfo = rawarray.request();
42 std::memcpy(rawinfo.ptr, source, num_bytes);
43 container_[py::str(name)] = pyarray;
47 full_buffer(
const std::string& name, int64_t length, int64_t value,
const std::string& dtype)
override {
48 py::object pyarray = py::module::import(
"numpy").attr(
"full")(py::int_(length), py::int_(value), py::str(dtype));
49 container_[py::str(name)] = pyarray;
59 empty_buffer(
const std::string& , int64_t )
override {
64 copy_buffer(
const std::string& ,
const void* , int64_t )
override { }
67 full_buffer(
const std::string& , int64_t , int64_t ,
const std::string& )
override { }
Abstract class to represent the output of ak.to_buffers. In Python, this would be a dict of NumPy arr...
Definition Builder.h:20
py::class_< ak::ArrayBuilder > make_ArrayBuilder(const py::handle &m, const std::string &name)
Makes an ArrayBuilder class in Python that mirrors the one in C++.
Definition ArrayBuilder.h:14