ListArray.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_LISTARRAY_H_
4 #define AWKWARD_LISTARRAY_H_
5 
6 #include <memory>
7 
8 #include "awkward/common.h"
9 #include "awkward/Index.h"
10 #include "awkward/Identities.h"
11 #include "awkward/Content.h"
12 
13 namespace awkward {
18  public:
21  ListForm(bool has_identities,
22  const util::Parameters& parameters,
23  const FormKey& form_key,
24  Index::Form starts,
25  Index::Form stops,
26  const FormPtr& content);
27 
29  starts() const;
30 
32  stops() const;
33 
34  const FormPtr
35  content() const;
36 
37  const TypePtr
38  type(const util::TypeStrs& typestrs) const override;
39 
40  void
41  tojson_part(ToJson& builder, bool verbose) const override;
42 
43  const FormPtr
44  shallow_copy() const override;
45 
46  const FormPtr
47  with_form_key(const FormKey& form_key) const override;
48 
49  const std::string
50  purelist_parameter(const std::string& key) const override;
51 
52  bool
53  purelist_isregular() const override;
54 
55  int64_t
56  purelist_depth() const override;
57 
58  bool
59  dimension_optiontype() const override;
60 
61  const std::pair<int64_t, int64_t>
62  minmax_depth() const override;
63 
64  const std::pair<bool, int64_t>
65  branch_depth() const override;
66 
67  int64_t
68  numfields() const override;
69 
70  int64_t
71  fieldindex(const std::string& key) const override;
72 
73  const std::string
74  key(int64_t fieldindex) const override;
75 
76  bool
77  haskey(const std::string& key) const override;
78 
79  const std::vector<std::string>
80  keys() const override;
81 
82  bool
83  istuple() const override;
84 
85  bool
86  equal(const FormPtr& other,
87  bool check_identities,
88  bool check_parameters,
89  bool check_form_key,
90  bool compatibility_check) const override;
91 
92  const FormPtr
93  getitem_field(const std::string& key) const override;
94 
95  const FormPtr
96  getitem_fields(const std::vector<std::string>& keys) const override;
97 
98  private:
99  Index::Form starts_;
100  Index::Form stops_;
101  const FormPtr content_;
102  };
103 
113  template <typename T>
114  class
115 #ifdef AWKWARD_LISTARRAY_NO_EXTERN_TEMPLATE
117 #endif
118  ListArrayOf: public Content {
119  public:
139  ListArrayOf<T>(const IdentitiesPtr& identities,
140  const util::Parameters& parameters,
141  const IndexOf<T>& starts,
142  const IndexOf<T>& stops,
143  const ContentPtr& content);
144 
153  const IndexOf<T>
154  starts() const;
155 
164  const IndexOf<T>
165  stops() const;
166 
172  const ContentPtr
173  content() const;
174 
182  Index64
183  compact_offsets64(bool start_at_zero) const;
184 
194  const ContentPtr
195  broadcast_tooffsets64(const Index64& offsets) const;
196 
204  const ContentPtr
205  toRegularArray() const;
206 
219  const ContentPtr
220  toListOffsetArray64(bool start_at_zero) const;
221 
224  const std::string
225  classname() const override;
226 
227  void
228  setidentities() override;
229 
230  void
231  setidentities(const IdentitiesPtr& identities) override;
232 
233  const TypePtr
234  type(const util::TypeStrs& typestrs) const override;
235 
236  const FormPtr
237  form(bool materialize) const override;
238 
240  kernels() const override;
241 
242  void
243  caches(std::vector<ArrayCachePtr>& out) const override;
244 
245  const std::string
246  tostring_part(const std::string& indent,
247  const std::string& pre,
248  const std::string& post) const override;
249 
250  void
251  tojson_part(ToJson& builder, bool include_beginendlist) const override;
252 
253  void
254  nbytes_part(std::map<size_t, int64_t>& largest) const override;
255 
259  int64_t
260  length() const override;
261 
262  const ContentPtr
263  shallow_copy() const override;
264 
265  const ContentPtr
266  deep_copy(bool copyarrays,
267  bool copyindexes,
268  bool copyidentities) const override;
269 
270  void
271  check_for_iteration() const override;
272 
273  const ContentPtr
274  getitem_nothing() const override;
275 
276  const ContentPtr
277  getitem_at(int64_t at) const override;
278 
279  const ContentPtr
280  getitem_at_nowrap(int64_t at) const override;
281 
282  const ContentPtr
283  getitem_range(int64_t start, int64_t stop) const override;
284 
285  const ContentPtr
286  getitem_range_nowrap(int64_t start, int64_t stop) const override;
287 
288  const ContentPtr
289  getitem_field(const std::string& key) const override;
290 
291  const ContentPtr
292  getitem_field(const std::string& key,
293  const Slice& only_fields) const override;
294 
295  const ContentPtr
296  getitem_fields(const std::vector<std::string>& keys) const override;
297 
298  const ContentPtr
299  getitem_fields(const std::vector<std::string>& keys,
300  const Slice& only_fields) const override;
301 
302  const ContentPtr
303  carry(const Index64& carry, bool allow_lazy) const override;
304 
305  int64_t
306  purelist_depth() const override;
307 
308  const std::pair<int64_t, int64_t>
309  minmax_depth() const override;
310 
311  const std::pair<bool, int64_t>
312  branch_depth() const override;
313 
314  int64_t
315  numfields() const override;
316 
317  int64_t
318  fieldindex(const std::string& key) const override;
319 
320  const std::string
321  key(int64_t fieldindex) const override;
322 
323  bool
324  haskey(const std::string& key) const override;
325 
326  const std::vector<std::string>
327  keys() const override;
328 
329  bool
330  istuple() const override;
331 
332  // operations
333  const std::string
334  validityerror(const std::string& path) const override;
335 
340  const ContentPtr
341  shallow_simplify() const override;
342 
343  const ContentPtr
344  num(int64_t axis, int64_t depth) const override;
345 
346  const std::pair<Index64, ContentPtr>
347  offsets_and_flattened(int64_t axis, int64_t depth) const override;
348 
349  bool
350  mergeable(const ContentPtr& other, bool mergebool) const override;
351 
352  bool
353  referentially_equal(const ContentPtr& other) const override;
354 
355  const ContentPtr
356  mergemany(const ContentPtrVec& others) const override;
357 
358  const SliceItemPtr
359  asslice() const override;
360 
361  const ContentPtr
362  fillna(const ContentPtr& value) const override;
363 
364  const ContentPtr
365  rpad(int64_t target, int64_t axis, int64_t depth) const override;
366 
367  const ContentPtr
368  rpad_and_clip(int64_t target,
369  int64_t axis,
370  int64_t depth) const override;
371 
372  const ContentPtr
373  reduce_next(const Reducer& reducer,
374  int64_t negaxis,
375  const Index64& starts,
376  const Index64& shifts,
377  const Index64& parents,
378  int64_t outlength,
379  bool mask,
380  bool keepdims) const override;
381 
382  const ContentPtr
383  sort_next(int64_t negaxis,
384  const Index64& starts,
385  const Index64& parents,
386  int64_t outlength,
387  bool ascending,
388  bool stable) const override;
389 
390  const ContentPtr
391  argsort_next(int64_t negaxis,
392  const Index64& starts,
393  const Index64& shifts,
394  const Index64& parents,
395  int64_t outlength,
396  bool ascending,
397  bool stable) const override;
398 
399  const ContentPtr
400  localindex(int64_t axis, int64_t depth) const override;
401 
402  const ContentPtr
403  combinations(int64_t n,
404  bool replacement,
405  const util::RecordLookupPtr& recordlookup,
406  const util::Parameters& parameters,
407  int64_t axis,
408  int64_t depth) const override;
409 
410  const ContentPtr
411  getitem_next(const SliceAt& at,
412  const Slice& tail,
413  const Index64& advanced) const override;
414 
415  const ContentPtr
416  getitem_next(const SliceRange& range,
417  const Slice& tail,
418  const Index64& advanced) const override;
419 
420  const ContentPtr
421  getitem_next(const SliceArray64& array,
422  const Slice& tail,
423  const Index64& advanced) const override;
424 
425  const ContentPtr
426  getitem_next(const SliceJagged64& jagged,
427  const Slice& tail,
428  const Index64& advanced) const override;
429 
430  const ContentPtr
431  getitem_next_jagged(const Index64& slicestarts,
432  const Index64& slicestops,
433  const SliceArray64& slicecontent,
434  const Slice& tail) const override;
435 
436  const ContentPtr
437  getitem_next_jagged(const Index64& slicestarts,
438  const Index64& slicestops,
439  const SliceMissing64& slicecontent,
440  const Slice& tail) const override;
441 
442  const ContentPtr
443  getitem_next_jagged(const Index64& slicestarts,
444  const Index64& slicestops,
445  const SliceJagged64& slicecontent,
446  const Slice& tail) const override;
447 
448  const ContentPtr
449  copy_to(kernel::lib ptr_lib) const override;
450 
451  const ContentPtr
452  numbers_to_type(const std::string& name) const override;
453 
455  bool
456  is_unique() const override;
457 
459  const ContentPtr
460  unique() const override;
461 
463  bool
464  is_subrange_equal(const Index64& start, const Index64& stop) const override;
465 
466  private:
468  const IndexOf<T> starts_;
470  const IndexOf<T> stops_;
472  const ContentPtr content_;
473  };
474 
475 #ifndef AWKWARD_LISTARRAY_NO_EXTERN_TEMPLATE
476  extern template class ListArrayOf<int32_t>;
477  extern template class ListArrayOf<uint32_t>;
478  extern template class ListArrayOf<int64_t>;
479 #endif
480 
484 }
485 
486 #endif // AWKWARD_LISTARRAY_H_
Represents a Python slice object (usual syntax: array[start:stop:step]).
Definition: Slice.h:93
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
Represents an array of nested lists that can have different lengths using two indexes named starts an...
Definition: ListArray.h:114
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 a SliceArrayOf, SliceMissingOf, or SliceJaggedOf with missing values: None (no equivalent ...
Definition: Slice.h:431
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.
Form
Integer type of an Index, used by ListForm, IndexedForm, etc.
Definition: Index.h:34
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
Form describing ListArray.
Definition: ListArray.h:17
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