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> 29 namespace py = pybind11;
33 box(
const std::shared_ptr<ak::Content>& content);
35 std::shared_ptr<ak::Content>
41 return self.tostring();
64 py::class_<ak::ArrayBuilder>
68 template <
typename T,
typename I>
69 py::class_<ak::LayoutBuilder<T, I>>
73 py::class_<ak::Iterator, std::shared_ptr<ak::Iterator>>
79 py::dict container() {
84 copy_buffer(
const std::string&
name,
const void* source, 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 std::memcpy(rawinfo.ptr, source, num_bytes);
89 container_[py::str(name)] = pyarray;
93 full_buffer(
const std::string& name, int64_t length, int64_t
value,
const std::string&
dtype)
override {
94 py::object pyarray = py::module::import(
"numpy").attr(
"full")(py::int_(length), py::int_(value), py::str(dtype));
95 container_[py::str(name)] = pyarray;
105 copy_buffer(
const std::string&
name,
const void* source, int64_t num_bytes)
override { }
108 full_buffer(
const std::string& name, int64_t length, int64_t
value,
const std::string&
dtype)
override { }
122 ::NumpyBuffersContainer container;
123 int64_t form_key_id = 0;
124 std::string form = builder.get()->to_buffers(container, form_key_id);
126 kwargs[py::str(
"form")] = py::str(form);
127 kwargs[py::str(
"length")] = py::int_(builder.get()->length());
128 kwargs[py::str(
"container")] = container.container();
129 kwargs[py::str(
"key_format")] = py::str(
"{form_key}-{attribute}");
130 kwargs[py::str(
"highlevel")] = py::bool_(
false);
131 return py::module::import(
"awkward").attr(
"from_buffers")(**kwargs);
156 const std::shared_ptr<ak::Content> ptr_;
161 py::class_<PersistentSharedPtr>
166 py::class_<ak::Content, std::shared_ptr<ak::Content>>
170 py::class_<ak::EmptyArray, std::shared_ptr<ak::EmptyArray>,
ak::Content>
176 template <
typename T,
bool ISOPTION>
177 py::class_<ak::IndexedArrayOf<T, ISOPTION>,
178 std::shared_ptr<ak::IndexedArrayOf<T, ISOPTION>>,
184 std::shared_ptr<ak::ByteMaskedArray>,
190 std::shared_ptr<ak::BitMaskedArray>,
196 std::shared_ptr<ak::UnmaskedArray>,
202 template <
typename T>
203 py::class_<ak::ListArrayOf<T>,
204 std::shared_ptr<ak::ListArrayOf<T>>,
210 template <
typename T>
211 py::class_<ak::ListOffsetArrayOf<T>,
212 std::shared_ptr<ak::ListOffsetArrayOf<T>>,
217 py::class_<ak::NumpyArray, std::shared_ptr<ak::NumpyArray>,
ak::Content>
226 py::class_<ak::Record, std::shared_ptr<ak::Record>>
230 py::class_<ak::RecordArray, std::shared_ptr<ak::RecordArray>,
ak::Content>
234 py::class_<ak::RegularArray, std::shared_ptr<ak::RegularArray>,
ak::Content>
239 template <
typename T,
typename I>
240 py::class_<ak::UnionArrayOf<T, I>,
241 std::shared_ptr<ak::UnionArrayOf<T, I>>,
246 py::class_<ak::VirtualArray, std::shared_ptr<ak::VirtualArray>,
ak::Content>
249 #endif // AWKWARDPY_CONTENT_H_ 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++.
Abstract superclass of all array node types (flat hierarchy). Any Content can be nested within any ot...
Definition: Content.h:276
Definition: BitMaskedArray.h:15
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++.
Abstract class to represent the output of ak.to_buffers. In Python, this would be a dict of NumPy arr...
Definition: Builder.h:22
int64_t len(const T &self)
Definition: content.h:46
std::string name(Mapping a, V value)
Definition: datetime_util.h:39
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::dict parameters2dict(const ak::util::Parameters &in)
std::string repr(const T &self)
Definition: content.h:40
ak::Slice toslice(py::object obj)
Converts Python objects in a slice into a C++ Slice.
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::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++.
std::shared_ptr< ak::Content > unbox_content(const py::handle &obj)
Array nodes are frequently copied, but for some applications (one in Numba) it's better to keep a per...
Definition: content.h:139
ak::util::Parameters dict2parameters(const py::object &in)
dtype
NumPy dtypes that can be interpreted within Awkward C++ (only the primitive, fixed-width types)...
Definition: util.h:26
std::map< std::string, std::string > Parameters
Definition: util.h:165
py::object box(const std::shared_ptr< ak::Content > &content)
int64_t check_maxdecimals(const py::object &maxdecimals)
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++.
Mapping::value_type::value_type value(Mapping a, const std::string &name)
Definition: datetime_util.h:49
A sequence of SliceItem objects representing a tuple passed to Python's __getitem__.
Definition: Slice.h:585
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::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++.
std::shared_ptr< Builder > BuilderPtr
Definition: ArrayBuilder.h:19
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++.
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::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::ArrayBuilder > make_ArrayBuilder(const py::handle &m, const std::string &name)
Makes an ArrayBuilder class in Python that mirrors the one in C++.
Represents potentially missing data by overlaying a bit mask over its content.
Definition: BitMaskedArray.h:127
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::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...
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::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::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++...
Represents potentially missing data by overlaying a byte mask over its content.
Definition: ByteMaskedArray.h:117
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++.
Converts content of any type into an OptionType in which all values happen to be valid.
Definition: UnmaskedArray.h:107