RecordArray.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 AWKWARD_RECORDARRAY_H_
4 #define AWKWARD_RECORDARRAY_H_
5 
6 #include <memory>
7 #include <string>
8 #include <unordered_map>
9 
10 #include "awkward/common.h"
11 #include "awkward/Identities.h"
12 #include "awkward/Content.h"
13 
14 namespace awkward {
19  public:
22  RecordForm(bool has_identities,
23  const util::Parameters& parameters,
24  const FormKey& form_key,
25  const util::RecordLookupPtr& recordlookup,
26  const std::vector<FormPtr>& contents);
27 
29  recordlookup() const;
30 
31  const std::vector<FormPtr>
32  contents() const;
33 
34  bool
35  istuple() const;
36 
37  const FormPtr
38  content(int64_t fieldindex) const;
39 
40  const FormPtr
41  content(const std::string& key) const;
42 
43  const std::vector<std::pair<std::string, FormPtr>>
44  items() const;
45 
46  const TypePtr
47  type(const util::TypeStrs& typestrs) const override;
48 
49  void
50  tojson_part(ToJson& builder, bool verbose) const override;
51 
52  const FormPtr
53  shallow_copy() const override;
54 
55  const FormPtr
56  with_form_key(const FormKey& form_key) const override;
57 
58  const std::string
59  purelist_parameter(const std::string& key) const override;
60 
61  bool
62  purelist_isregular() const override;
63 
64  int64_t
65  purelist_depth() const override;
66 
67  bool
68  dimension_optiontype() const override;
69 
70  const std::pair<int64_t, int64_t>
71  minmax_depth() const override;
72 
73  const std::pair<bool, int64_t>
74  branch_depth() const override;
75 
76  int64_t
77  numfields() const override;
78 
79  int64_t
80  fieldindex(const std::string& key) const override;
81 
82  const std::string
83  key(int64_t fieldindex) const override;
84 
85  bool
86  haskey(const std::string& key) const override;
87 
88  const std::vector<std::string>
89  keys() const override;
90 
91  bool
92  equal(const FormPtr& other,
93  bool check_identities,
94  bool check_parameters,
95  bool check_form_key,
96  bool compatibility_check) const override;
97 
98  const FormPtr
99  getitem_field(const std::string& key) const override;
100 
101  const FormPtr
102  getitem_fields(const std::vector<std::string>& keys) const override;
103 
104  private:
105  const util::RecordLookupPtr recordlookup_;
106  const std::vector<FormPtr> contents_;
107  };
108 
123  public Content,
124  public std::enable_shared_from_this<RecordArray> {
125  public:
144  RecordArray(const IdentitiesPtr& identities,
145  const util::Parameters& parameters,
146  const ContentPtrVec& contents,
147  const util::RecordLookupPtr& recordlookup,
148  int64_t length,
149  const std::vector<ArrayCachePtr>& caches);
150 
153  RecordArray(const IdentitiesPtr& identities,
154  const util::Parameters& parameters,
155  const ContentPtrVec& contents,
156  const util::RecordLookupPtr& recordlookup,
157  int64_t length);
158 
161  RecordArray(const IdentitiesPtr& identities,
162  const util::Parameters& parameters,
163  const ContentPtrVec& contents,
164  const util::RecordLookupPtr& recordlookup);
165 
168  const ContentPtrVec
169  contents() const;
170 
176  recordlookup() const;
177 
179  bool
180  istuple() const;
181 
187  const ContentPtr
188  setitem_field(int64_t where, const ContentPtr& what) const;
189 
195  const ContentPtr
196  setitem_field(const std::string& where, const ContentPtr& what) const;
197 
199  const std::string
200  classname() const override;
201 
202  void
203  setidentities() override;
204 
205  void
206  setidentities(const IdentitiesPtr& identities) override;
207 
208  const FormPtr
209  form(bool materialize) const override;
210 
212  kernels() const override;
213 
214  void
215  caches(std::vector<ArrayCachePtr>& out) const override;
216 
217  const std::string
218  tostring_part(const std::string& indent,
219  const std::string& pre,
220  const std::string& post) const override;
221 
222  const TypePtr
223  type(const util::TypeStrs& typestrs) const override;
224 
225  void
226  tojson_part(ToJson& builder, bool include_beginendlist) const override;
227 
228  void
229  nbytes_part(std::map<size_t, int64_t>& largest) const override;
230 
234  int64_t
235  length() const override;
236 
237  const ContentPtr
238  shallow_copy() const override;
239 
240  const ContentPtr
241  deep_copy(bool copyarrays,
242  bool copyindexes,
243  bool copyidentities) const override;
244 
245  void
246  check_for_iteration() const override;
247 
248  const ContentPtr
249  getitem_nothing() const override;
250 
251  const ContentPtr
252  getitem_at(int64_t at) const override;
253 
254  const ContentPtr
255  getitem_at_nowrap(int64_t at) const override;
256 
257  const ContentPtr
258  getitem_range(int64_t start, int64_t stop) const override;
259 
260  const ContentPtr
261  getitem_range_nowrap(int64_t start, int64_t stop) const override;
262 
263  const ContentPtr
264  getitem_field(const std::string& key) const override;
265 
266  const ContentPtr
267  getitem_field(const std::string& key,
268  const Slice& only_fields) const override;
269 
270  const ContentPtr
271  getitem_fields(const std::vector<std::string>& keys) const override;
272 
273  const ContentPtr
274  getitem_fields(const std::vector<std::string>& keys,
275  const Slice& only_fields) const override;
276 
277  const ContentPtr
278  getitem_next(const SliceItemPtr& head,
279  const Slice& tail,
280  const Index64& advanced) const override;
281 
282  const ContentPtr
283  carry(const Index64& carry, bool allow_lazy) const override;
284 
285  int64_t
286  purelist_depth() const override;
287 
288  const std::pair<int64_t, int64_t>
289  minmax_depth() const override;
290 
291  const std::pair<bool, int64_t>
292  branch_depth() const override;
293 
294  int64_t
295  numfields() const override;
296 
297  int64_t
298  fieldindex(const std::string& key) const override;
299 
300  const std::string
301  key(int64_t fieldindex) const override;
302 
303  bool
304  haskey(const std::string& key) const override;
305 
306  const std::vector<std::string>
307  keys() const override;
308 
309  // operations
310  const std::string
311  validityerror(const std::string& path) const override;
312 
316  const ContentPtr
317  shallow_simplify() const override;
318 
319  const ContentPtr
320  num(int64_t axis, int64_t depth) const override;
321 
322  const std::pair<Index64, ContentPtr>
323  offsets_and_flattened(int64_t axis, int64_t depth) const override;
324 
325  bool
326  mergeable(const ContentPtr& other, bool mergebool) const override;
327 
328  bool
329  referentially_equal(const ContentPtr& other) const override;
330 
331  const ContentPtr
332  mergemany(const ContentPtrVec& others) const override;
333 
334  const SliceItemPtr
335  asslice() const override;
336 
337  const ContentPtr
338  fillna(const ContentPtr& value) const override;
339 
340  const ContentPtr
341  rpad(int64_t target, int64_t axis, int64_t depth) const override;
342 
343  const ContentPtr
344  rpad_and_clip(int64_t target,
345  int64_t axis,
346  int64_t depth) const override;
347 
348  const ContentPtr
349  reduce_next(const Reducer& reducer,
350  int64_t negaxis,
351  const Index64& starts,
352  const Index64& shifts,
353  const Index64& parents,
354  int64_t outlength,
355  bool mask,
356  bool keepdims) const override;
357 
358  const ContentPtr
359  sort_next(int64_t negaxis,
360  const Index64& starts,
361  const Index64& parents,
362  int64_t outlength,
363  bool ascending,
364  bool stable) const override;
365 
366  const ContentPtr
367  argsort_next(int64_t negaxis,
368  const Index64& starts,
369  const Index64& shifts,
370  const Index64& parents,
371  int64_t outlength,
372  bool ascending,
373  bool stable) const override;
374 
375  const ContentPtr
376  localindex(int64_t axis, int64_t depth) const override;
377 
378  const ContentPtr
379  combinations(int64_t n,
380  bool replacement,
381  const util::RecordLookupPtr& recordlookup,
382  const util::Parameters& parameters,
383  int64_t axis,
384  int64_t depth) const override;
385 
390  const ContentPtr
391  field(int64_t fieldindex) const;
392 
397  const ContentPtr
398  field(const std::string& key) const;
399 
404  const ContentPtrVec
405  fields() const;
406 
409  const std::vector<std::pair<std::string, ContentPtr>>
410  fielditems() const;
411 
414  const std::shared_ptr<RecordArray>
415  astuple() const;
416 
417  const ContentPtr
418  getitem_next(const SliceAt& at,
419  const Slice& tail,
420  const Index64& advanced) const override;
421 
422  const ContentPtr
423  getitem_next(const SliceRange& range,
424  const Slice& tail,
425  const Index64& advanced) const override;
426 
427  const ContentPtr
428  getitem_next(const SliceArray64& array,
429  const Slice& tail,
430  const Index64& advanced) const override;
431 
432  const ContentPtr
433  getitem_next(const SliceField& field,
434  const Slice& tail,
435  const Index64& advanced) const override;
436 
437  const ContentPtr
438  getitem_next(const SliceFields& fields,
439  const Slice& tail,
440  const Index64& advanced) const override;
441 
442  const ContentPtr
443  getitem_next(const SliceJagged64& jagged,
444  const Slice& tail,
445  const Index64& advanced) const override;
446 
447  const ContentPtr
448  getitem_next_jagged(const Index64& slicestarts,
449  const Index64& slicestops,
450  const SliceArray64& slicecontent,
451  const Slice& tail) const override;
452 
453  const ContentPtr
454  getitem_next_jagged(const Index64& slicestarts,
455  const Index64& slicestops,
456  const SliceMissing64& slicecontent,
457  const Slice& tail) const override;
458 
459  const ContentPtr
460  getitem_next_jagged(const Index64& slicestarts,
461  const Index64& slicestops,
462  const SliceJagged64& slicecontent,
463  const Slice& tail) const override;
464 
465  const ContentPtr
466  copy_to(kernel::lib ptr_lib) const override;
467 
468  const ContentPtr
469  numbers_to_type(const std::string& name) const override;
470 
472  bool
473  is_unique() const override;
474 
476  const ContentPtr
477  unique() const override;
478 
480  bool
481  is_subrange_equal(const Index64& start, const Index64& stop) const override;
482 
483  protected:
484  template <typename S>
485  const ContentPtr
486  getitem_next_jagged_generic(const Index64& slicestarts,
487  const Index64& slicestops,
488  const S& slicecontent,
489  const Slice& tail) const;
490 
491  private:
493  const ContentPtrVec contents_;
495  const util::RecordLookupPtr recordlookup_;
497  int64_t length_;
499  const std::vector<ArrayCachePtr> caches_;
500  };
501 }
502 
503 #endif // AWKWARD_RECORDARRAY_H_
Represents a Python slice object (usual syntax: array[start:stop:step]).
Definition: Slice.h:93
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
const std::string key(const RecordLookupPtr &recordlookup, int64_t fieldindex, int64_t numfields)
Returns the key associated with a field index, given a RecordLookup and a number of fields...
Abstract superclass of all array node types (flat hierarchy). Any Content can be nested within any ot...
Definition: Content.h:276
Definition: json.h:19
Definition: BitMaskedArray.h:15
A contiguous, one-dimensional array of integers used to represent data structures, rather than numerical data in the arrays themselves.
Definition: Index.h:16
std::string name(Mapping a, V value)
Definition: datetime_util.h:39
Represents an array of tuples or records, in which a tuple has a fixed number of differently typed fi...
Definition: RecordArray.h:122
Definition: Slice.h:384
Represents a SliceArrayOf, SliceMissingOf, or SliceJaggedOf with missing values: None (no equivalent ...
Definition: Slice.h:431
Form describing RecordArray (not a Record).
Definition: RecordArray.h:18
Represents a single string in a slice tuple, indicating that a RecordArray should be replaced by one ...
Definition: Slice.h:340
Abstract class for all reducer algorithms.
Definition: Reducer.h:20
ERROR combinations(kernel::lib ptr_lib, T *toindex, int64_t n, bool replacement, int64_t singlelen)
const std::vector< std::string > keys(const RecordLookupPtr &recordlookup, int64_t numfields)
Returns a given RecordLookup as keys or generate anonymous ones form a number of fields.
std::shared_ptr< std::string > FormKey
Definition: Content.h:19
ERROR unique(kernel::lib ptr_lib, T *toptr, int64_t length, int64_t *tolength)
Represents an array of integers in a slice (possibly converted from an array of booleans).
Definition: Slice.h:225
std::map< std::string, std::string > Parameters
Definition: util.h:165
ERROR copy_to(kernel::lib to_lib, kernel::lib from_lib, void *to_ptr, void *from_ptr, int64_t bytelength)
Internal Function an array buffer from library FROM to library TO, usually between main memory and a ...
std::shared_ptr< Form > FormPtr
Definition: Content.h:18
int64_t fieldindex(const RecordLookupPtr &recordlookup, const std::string &key, int64_t numfields)
Returns the field index associated with a key, given a RecordLookup and a number of fields...
Represents an array of nested lists, where the content may be SliceArrayOf, SliceMissingOf, or SliceJaggedOf (no equivalent in NumPy).
Definition: Slice.h:511
std::vector< std::shared_ptr< Content > > ContentPtrVec
Definition: Content.h:16
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&#39;s __getitem__.
Definition: Slice.h:585
bool haskey(const RecordLookupPtr &recordlookup, const std::string &key, int64_t numfields)
Returns true if a RecordLookup has a given key; false otherwise.
std::shared_ptr< Type > TypePtr
Definition: Content.h:23
std::shared_ptr< RecordLookup > RecordLookupPtr
Definition: util.h:130
Represents an integer in a tuple of slices passed to __getitem__ in Python.
Definition: Slice.h:58
std::map< std::string, std::string > TypeStrs
Definition: util.h:215
Abstract superclass of all array node forms, which expresses the nesting structure without any large ...
Definition: Content.h:39
std::shared_ptr< Identities > IdentitiesPtr
Definition: Identities.h:16
std::shared_ptr< Content > ContentPtr
Definition: ArrayBuilder.h:16
std::shared_ptr< SliceItem > SliceItemPtr
Definition: Slice.h:15
lib
Definition: kernel-dispatch.h:20