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>
29namespace py = pybind11;
33box(
const std::shared_ptr<ak::Content>& content);
35std::shared_ptr<ak::Content>
41 return self.tostring();
64py::class_<ak::ArrayBuilder>
68template <
typename T,
typename I>
69py::class_<ak::LayoutBuilder<T, I>>
73py::class_<ak::Iterator, std::shared_ptr<ak::Iterator>>
79 py::dict container() {
84 empty_buffer(
const std::string& name, int64_t num_bytes)
override {
85 py::object pyarray = py::module::import(
"numpy").attr(
"empty")(num_bytes,
"u1");
86 py::array_t<uint8_t> rawarray = pyarray.cast<py::array_t<uint8_t>>();
87 py::buffer_info rawinfo = rawarray.request();
88 container_[py::str(name)] = pyarray;
93 copy_buffer(
const std::string& name,
const void* source, int64_t num_bytes)
override {
94 py::object pyarray = py::module::import(
"numpy").attr(
"empty")(num_bytes,
"u1");
95 py::array_t<uint8_t> rawarray = pyarray.cast<py::array_t<uint8_t>>();
96 py::buffer_info rawinfo = rawarray.request();
97 std::memcpy(rawinfo.ptr, source, num_bytes);
98 container_[py::str(name)] = pyarray;
102 full_buffer(
const std::string& name, int64_t length, int64_t value,
const std::string& dtype)
override {
103 py::object pyarray = py::module::import(
"numpy").attr(
"full")(py::int_(length), py::int_(value), py::str(dtype));
104 container_[py::str(name)] = pyarray;
114 empty_buffer(
const std::string& name, int64_t num_bytes)
override {
119 copy_buffer(
const std::string& name,
const void* source, int64_t num_bytes)
override { }
122 full_buffer(
const std::string& name, int64_t length, int64_t value,
const std::string& dtype)
override { }
136 ::NumpyBuffersContainer container;
137 int64_t form_key_id = 0;
138 std::string form = builder.get()->to_buffers(container, form_key_id);
140 kwargs[py::str(
"form")] = py::str(form);
141 kwargs[py::str(
"length")] = py::int_(builder.get()->length());
142 kwargs[py::str(
"container")] = container.container();
143 kwargs[py::str(
"key_format")] = py::str(
"{form_key}-{attribute}");
144 kwargs[py::str(
"highlevel")] = py::bool_(
false);
145 return py::module::import(
"awkward").attr(
"from_buffers")(**kwargs);
170 const std::shared_ptr<ak::Content> ptr_;
175py::class_<PersistentSharedPtr>
180py::class_<ak::Content, std::shared_ptr<ak::Content>>
184py::class_<ak::EmptyArray, std::shared_ptr<ak::EmptyArray>,
ak::Content>
190template <
typename T,
bool ISOPTION>
191py::class_<ak::IndexedArrayOf<T, ISOPTION>,
192 std::shared_ptr<ak::IndexedArrayOf<T, ISOPTION>>,
198 std::shared_ptr<ak::ByteMaskedArray>,
204 std::shared_ptr<ak::BitMaskedArray>,
210 std::shared_ptr<ak::UnmaskedArray>,
217py::class_<ak::ListArrayOf<T>,
218 std::shared_ptr<ak::ListArrayOf<T>>,
225py::class_<ak::ListOffsetArrayOf<T>,
226 std::shared_ptr<ak::ListOffsetArrayOf<T>>,
231py::class_<ak::NumpyArray, std::shared_ptr<ak::NumpyArray>,
ak::Content>
240py::class_<ak::Record, std::shared_ptr<ak::Record>>
244py::class_<ak::RecordArray, std::shared_ptr<ak::RecordArray>,
ak::Content>
248py::class_<ak::RegularArray, std::shared_ptr<ak::RegularArray>,
ak::Content>
253template <
typename T,
typename I>
254py::class_<ak::UnionArrayOf<T, I>,
255 std::shared_ptr<ak::UnionArrayOf<T, I>>,
260py::class_<ak::VirtualArray, std::shared_ptr<ak::VirtualArray>,
ak::Content>
Array nodes are frequently copied, but for some applications (one in Numba) it's better to keep a per...
Definition: content.h:153
PersistentSharedPtr(const std::shared_ptr< ak::Content > &ptr)
Creates a PersistentSharedPtr from a std::shared_ptr to a Content array.
py::object layout() const
Returns a layout object (Content in Python) from this ptr.
size_t ptr() const
Returns a raw pointer to the persistent std::shared_ptr (a raw pointer to a smart pointer).
Represents potentially missing data by overlaying a bit mask over its content.
Definition: BitMaskedArray.h:127
Abstract class to represent the output of ak.to_buffers. In Python, this would be a dict of NumPy arr...
Definition: Builder.h:20
Represents potentially missing data by overlaying a byte mask over its content.
Definition: ByteMaskedArray.h:117
Abstract superclass of all array node types (flat hierarchy). Any Content can be nested within any ot...
Definition: Content.h:276
A sequence of SliceItem objects representing a tuple passed to Python's __getitem__.
Definition: Slice.h:585
Converts content of any type into an OptionType in which all values happen to be valid.
Definition: UnmaskedArray.h:107
std::shared_ptr< ak::Content > unbox_content(const py::handle &obj)
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++.
py::class_< ak::ListOffsetArrayOf< T >, std::shared_ptr< ak::ListOffsetArrayOf< T > >, ak::Content > make_ListOffsetArrayOf(const py::handle &m, const std::string &name)
Makes ListOffsetArray32, ListOffsetArrayU32, and ListOffsetArray64 classes in Python that mirror List...
py::class_< ak::BitMaskedArray, std::shared_ptr< ak::BitMaskedArray >, ak::Content > make_BitMaskedArray(const py::handle &m, const std::string &name)
Makes a BitMaskedArray in Python that mirrors the one in C++.
py::class_< ak::UnionArrayOf< T, I >, std::shared_ptr< ak::UnionArrayOf< T, I > >, ak::Content > make_UnionArrayOf(const py::handle &m, const std::string &name)
Makes UnionArray8_32, UnionArray8_U32, and UnionArray8_64 classes in Python that mirror UnionArrayOf ...
py::class_< ak::ListArrayOf< T >, std::shared_ptr< ak::ListArrayOf< T > >, ak::Content > make_ListArrayOf(const py::handle &m, const std::string &name)
Makes ListArray32, ListArrayU32, and ListArray64 classes in Python that mirror ListArrayOf in C++.
py::class_< ak::EmptyArray, std::shared_ptr< ak::EmptyArray >, ak::Content > make_EmptyArray(const py::handle &m, const std::string &name)
Makes an EmptyArray in Python that mirrors the one in C++.
py::object box(const std::shared_ptr< ak::Content > &content)
py::class_< ak::Content, std::shared_ptr< ak::Content > > make_Content(const py::handle &m, const std::string &name)
Makes an abstract Content class in Python that mirrors the one in C++.
ak::util::Parameters dict2parameters(const py::object &in)
py::class_< ak::Record, std::shared_ptr< ak::Record > > make_Record(const py::handle &m, const std::string &name)
Makes a Record in Python that mirrors the one in C++.
py::class_< ak::NumpyArray, std::shared_ptr< ak::NumpyArray >, ak::Content > make_NumpyArray(const py::handle &m, const std::string &name)
Makes a NumpyArray in Python that mirrors the one in C++.
py::class_< PersistentSharedPtr > make_PersistentSharedPtr(const py::handle &m, const std::string &name)
Makes a PersistentSharedPtr class in Python that mirrors the one in C++.
py::class_< ak::Iterator, std::shared_ptr< ak::Iterator > > make_Iterator(const py::handle &m, const std::string &name)
Makes an Iterator class in Python that mirrors the one in C++.
py::class_< ak::RecordArray, std::shared_ptr< ak::RecordArray >, ak::Content > make_RecordArray(const py::handle &m, const std::string &name)
Makes a RecordArray in Python that mirrors the one in C++.
py::class_< ak::LayoutBuilder< T, I > > make_LayoutBuilder(const py::handle &m, const std::string &name)
Makes a LayoutBuilder class in Python that mirrors the one in C++.
py::class_< ak::IndexedArrayOf< T, ISOPTION >, std::shared_ptr< ak::IndexedArrayOf< T, ISOPTION > >, ak::Content > make_IndexedArrayOf(const py::handle &m, const std::string &name)
Makes IndexedArray32, IndexedArrayU32, IndexedArray64, IndexedOptionArray32, and IndexedOptionArray64...
int64_t len(const T &self)
Definition: content.h:46
py::class_< ak::RegularArray, std::shared_ptr< ak::RegularArray >, ak::Content > make_RegularArray(const py::handle &m, const std::string &name)
Makes a RegularArray in Python that mirrors the one in C++.
py::class_< ak::VirtualArray, std::shared_ptr< ak::VirtualArray >, ak::Content > make_VirtualArray(const py::handle &m, const std::string &name)
Makes a VirtualArray in Python that mirrors the one in C++.
int64_t check_maxdecimals(const py::object &maxdecimals)
py::class_< ak::ByteMaskedArray, std::shared_ptr< ak::ByteMaskedArray >, ak::Content > make_ByteMaskedArray(const py::handle &m, const std::string &name)
Makes a ByteMaskedArray in Python that mirrors the one in C++.
py::dict parameters2dict(const ak::util::Parameters &in)
py::class_< ak::UnmaskedArray, std::shared_ptr< ak::UnmaskedArray >, ak::Content > make_UnmaskedArray(const py::handle &m, const std::string &name)
Makes a UnmaskedArray in Python that mirrors the one in C++.
ak::Slice toslice(py::object obj)
Converts Python objects in a slice into a C++ Slice.
std::string repr(const T &self)
Definition: content.h:40
Definition: BitMaskedArray.h:15
std::shared_ptr< Builder > BuilderPtr
Definition: ArrayBuilder.h:16