Awkward Array: include/awkward/python/virtual.h Source File

Loading...
Searching...
No Matches
virtual.h
Go to the documentation of this file.
1// BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
2
3#ifndef AWKWARDPY_VIRTUAL_H_
4#define AWKWARDPY_VIRTUAL_H_
5
6#include <pybind11/pybind11.h>
7
8#include "awkward/virtual/ArrayGenerator.h"
9#include "awkward/virtual/ArrayCache.h"
10
11namespace py = pybind11;
12namespace ak = awkward;
13
15
16 class PyArrayGenerator: public ak::ArrayGenerator {
17public:
18 PyArrayGenerator(const ak::FormPtr& form,
19 int64_t length,
20 const py::object& callable,
21 const py::tuple& args,
22 const py::dict& kwargs);
23
24 const py::object
25 callable() const;
26
27 const py::tuple
28 args() const;
29
30 const py::dict
31 kwargs() const;
32
33 const ak::ContentPtr
34 generate() const override;
35
36 void
37 caches(std::vector<ak::ArrayCachePtr>& out) const override;
38
39 const std::string
40 tostring_part(const std::string& indent,
41 const std::string& pre,
42 const std::string& post) const override;
43
44 const std::shared_ptr<ak::ArrayGenerator>
45 shallow_copy() const override;
46
47 const std::shared_ptr<ak::ArrayGenerator>
48 with_form(const ak::FormPtr& form) const override;
49
50 const std::shared_ptr<ak::ArrayGenerator>
51 with_length(int64_t length) const override;
52
53 const std::shared_ptr<ak::ArrayGenerator>
54 with_callable(const py::object& callable) const;
55
56 const std::shared_ptr<ak::ArrayGenerator>
57 with_args(const py::tuple& args) const;
58
59 const std::shared_ptr<ak::ArrayGenerator>
60 with_kwargs(const py::dict& kwargs) const;
61
62 virtual bool
63 referentially_equal(const ak::ArrayGeneratorPtr& other) const override;
64
65private:
66 const py::object callable_;
67 const py::tuple args_;
68 const py::dict kwargs_;
69};
70
71py::class_<PyArrayGenerator, std::shared_ptr<PyArrayGenerator>>
72make_PyArrayGenerator(const py::handle& m, const std::string& name);
73
75
76py::class_<ak::SliceGenerator, std::shared_ptr<ak::SliceGenerator>>
77make_SliceGenerator(const py::handle& m, const std::string& name);
78
80
81 class PyArrayCache: public ak::ArrayCache {
82public:
83 PyArrayCache(const py::object& mutablemapping);
84
85 const py::object
86 mutablemapping() const;
87
88 ak::ContentPtr
89 get(const std::string& key) const override;
90
91 void
92 set(const std::string& key, const ak::ContentPtr& value) override;
93
94 bool
95 is_broken() const override;
96
97 const std::string
98 tostring_part(const std::string& indent,
99 const std::string& pre,
100 const std::string& post) const override;
101
102private:
103 const py::object mutablemapping_;
104};
105
106py::class_<PyArrayCache, std::shared_ptr<PyArrayCache>>
107make_PyArrayCache(const py::handle& m, const std::string& name);
108
109#endif // AWKWARDPY_VIRTUAL_H_
ArrayCache.h
ArrayGenerator.h
PyArrayCache
Definition: virtual.h:81
PyArrayCache::set
void set(const std::string &key, const ak::ContentPtr &value) override
Writes or overwrites an array at key.
PyArrayCache::get
ak::ContentPtr get(const std::string &key) const override
Attempts to get an array; may be nullptr if not available.
PyArrayCache::mutablemapping
const py::object mutablemapping() const
PyArrayCache::tostring_part
const std::string tostring_part(const std::string &indent, const std::string &pre, const std::string &post) const override
PyArrayCache::is_broken
bool is_broken() const override
Returns true if the cache cannot be used for any reason.
PyArrayCache::PyArrayCache
PyArrayCache(const py::object &mutablemapping)
PyArrayGenerator
Definition: virtual.h:16
PyArrayGenerator::with_args
const std::shared_ptr< ak::ArrayGenerator > with_args(const py::tuple &args) const
PyArrayGenerator::callable
const py::object callable() const
PyArrayGenerator::referentially_equal
virtual bool referentially_equal(const ak::ArrayGeneratorPtr &other) const override
Returns true if this generator has all the same buffers and parameters as other; false otherwise.
PyArrayGenerator::with_kwargs
const std::shared_ptr< ak::ArrayGenerator > with_kwargs(const py::dict &kwargs) const
PyArrayGenerator::PyArrayGenerator
PyArrayGenerator(const ak::FormPtr &form, int64_t length, const py::object &callable, const py::tuple &args, const py::dict &kwargs)
PyArrayGenerator::shallow_copy
const std::shared_ptr< ak::ArrayGenerator > shallow_copy() const override
Copies this ArrayGenerator, referencing any contents.
PyArrayGenerator::caches
void caches(std::vector< ak::ArrayCachePtr > &out) const override
Accumulates all the unique #ArrayCache objects from nested #VirtualArray nodes. (Uniqueness is determ...
PyArrayGenerator::with_length
const std::shared_ptr< ak::ArrayGenerator > with_length(int64_t length) const override
Return a copy of this ArrayGenerator with a different length (or a now-known length,...
PyArrayGenerator::tostring_part
const std::string tostring_part(const std::string &indent, const std::string &pre, const std::string &post) const override
Returns a string representation of this ArrayGenerator.
PyArrayGenerator::args
const py::tuple args() const
PyArrayGenerator::with_callable
const std::shared_ptr< ak::ArrayGenerator > with_callable(const py::object &callable) const
PyArrayGenerator::with_form
const std::shared_ptr< ak::ArrayGenerator > with_form(const ak::FormPtr &form) const override
Return a copy of this ArrayGenerator with a different form (or a now-known form, whereas it might hav...
PyArrayGenerator::kwargs
const py::dict kwargs() const
PyArrayGenerator::generate
const ak::ContentPtr generate() const override
Creates an array but does not check it against the form.
awkward::ArrayCache
Abstract superclass of cache for VirtualArray, defining the interface.
Definition: ArrayCache.h:17
awkward::ArrayGenerator
Abstract superclass to generate arrays for VirtualArray, defining the interface.
Definition: ArrayGenerator.h:24
awkward::ArrayGenerator::form
const FormPtr form() const
The Form the generated array is expected to take; may be nullptr.
awkward::ArrayGenerator::length
int64_t length() const
The length the generated array is expected to have; may be negative to indicate that the length is un...
awkward
Definition: BitMaskedArray.h:15
awkward::ArrayGeneratorPtr
std::shared_ptr< ArrayGenerator > ArrayGeneratorPtr
Definition: ArrayGenerator.h:14
awkward::ContentPtr
std::shared_ptr< Content > ContentPtr
Definition: Content.h:15
awkward::FormPtr
std::shared_ptr< Form > FormPtr
Definition: Content.h:18
make_PyArrayGenerator
py::class_< PyArrayGenerator, std::shared_ptr< PyArrayGenerator > > make_PyArrayGenerator(const py::handle &m, const std::string &name)
make_SliceGenerator
py::class_< ak::SliceGenerator, std::shared_ptr< ak::SliceGenerator > > make_SliceGenerator(const py::handle &m, const std::string &name)
make_PyArrayCache
py::class_< PyArrayCache, std::shared_ptr< PyArrayCache > > make_PyArrayCache(const py::handle &m, const std::string &name)