ListOffsetArray.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_LISTOFFSETARRAY_H_
4 #define AWKWARD_LISTOFFSETARRAY_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  ListOffsetForm(bool has_identities,
22  const util::Parameters& parameters,
23  const FormKey& form_key,
24  Index::Form offsets,
25  const FormPtr& content);
26 
28  offsets() const;
29 
30  const FormPtr
31  content() const;
32 
33  const TypePtr
34  type(const util::TypeStrs& typestrs) const override;
35 
36  void
37  tojson_part(ToJson& builder, bool verbose) const override;
38 
39  const FormPtr
40  shallow_copy() const override;
41 
42  const FormPtr
43  with_form_key(const FormKey& form_key) const override;
44 
45  const std::string
46  purelist_parameter(const std::string& key) const override;
47 
48  bool
49  purelist_isregular() const override;
50 
51  int64_t
52  purelist_depth() const override;
53 
54  bool
55  dimension_optiontype() const override;
56 
57  const std::pair<int64_t, int64_t>
58  minmax_depth() const override;
59 
60  const std::pair<bool, int64_t>
61  branch_depth() const override;
62 
63  int64_t
64  numfields() const override;
65 
66  int64_t
67  fieldindex(const std::string& key) const override;
68 
69  const std::string
70  key(int64_t fieldindex) const override;
71 
72  bool
73  haskey(const std::string& key) const override;
74 
75  const std::vector<std::string>
76  keys() const override;
77 
78  bool
79  istuple() const override;
80 
81  bool
82  equal(const FormPtr& other,
83  bool check_identities,
84  bool check_parameters,
85  bool check_form_key,
86  bool compatibility_check) const override;
87 
88  const FormPtr
89  getitem_field(const std::string& key) const override;
90 
91  const FormPtr
92  getitem_fields(const std::vector<std::string>& keys) const override;
93 
94  private:
95  Index::Form offsets_;
96  const FormPtr content_;
97  };
98 
110  template <typename T>
111  class
112 #ifdef AWKWARD_LISTOFFSETARRAY_NO_EXTERN_TEMPLATE
114 #endif
115  ListOffsetArrayOf: public Content {
116  public:
132  ListOffsetArrayOf<T>(const IdentitiesPtr& identities,
133  const util::Parameters& parameters,
134  const IndexOf<T>& offsets,
135  const ContentPtr& content,
136  bool represents_regular = false);
137 
143  const IndexOf<T>
144  offsets() const;
145 
151  const ContentPtr
152  content() const;
153 
159  const IndexOf<T>
160  starts() const;
161 
167  const IndexOf<T>
168  stops() const;
169 
178  Index64
179  compact_offsets64(bool start_at_zero) const;
180 
186  const ContentPtr
187  broadcast_tooffsets64(const Index64& offsets) const;
188 
191  const ContentPtr
192  toRegularArray() const;
193 
201  const ContentPtr
202  toListOffsetArray64(bool start_at_zero) const;
203 
206  const std::string
207  classname() const override;
208 
209  void
210  setidentities() override;
211 
212  void
213  setidentities(const IdentitiesPtr& identities) override;
214 
215  const TypePtr
216  type(const util::TypeStrs& typestrs) const override;
217 
218  const FormPtr
219  form(bool materialize) const override;
220 
222  kernels() const override;
223 
224  void
225  caches(std::vector<ArrayCachePtr>& out) const override;
226 
227  const std::string
228  tostring_part(const std::string& indent,
229  const std::string& pre,
230  const std::string& post) const override;
231 
232  void
233  tojson_part(ToJson& builder, bool include_beginendlist) const override;
234 
235  void
236  nbytes_part(std::map<size_t, int64_t>& largest) const override;
237 
241  int64_t
242  length() const override;
243 
244  const ContentPtr
245  shallow_copy() const override;
246 
247  const ContentPtr
248  deep_copy(bool copyarrays,
249  bool copyindexes,
250  bool copyidentities) const override;
251 
252  void
253  check_for_iteration() const override;
254 
255  const ContentPtr
256  getitem_nothing() const override;
257 
258  const ContentPtr
259  getitem_at(int64_t at) const override;
260 
261  const ContentPtr
262  getitem_at_nowrap(int64_t at) const override;
263 
264  const ContentPtr
265  getitem_range(int64_t start, int64_t stop) const override;
266 
267  const ContentPtr
268  getitem_range_nowrap(int64_t start, int64_t stop) const override;
269 
270  const ContentPtr
271  getitem_field(const std::string& key) const override;
272 
273  const ContentPtr
274  getitem_field(const std::string& key,
275  const Slice& only_fields) const override;
276 
277  const ContentPtr
278  getitem_fields(const std::vector<std::string>& keys) const override;
279 
280  const ContentPtr
281  getitem_fields(const std::vector<std::string>& keys,
282  const Slice& only_fields) const override;
283 
284  const ContentPtr
285  getitem_next_jagged(const Index64& slicestarts,
286  const Index64& slicestops,
287  const SliceItemPtr& slicecontent,
288  const Slice& tail) const override;
289 
290  const ContentPtr
291  carry(const Index64& carry, bool allow_lazy) const override;
292 
293  int64_t
294  purelist_depth() const override;
295 
296  const std::pair<int64_t, int64_t>
297  minmax_depth() const override;
298 
299  const std::pair<bool, int64_t>
300  branch_depth() const override;
301 
302  int64_t
303  numfields() const override;
304 
305  int64_t
306  fieldindex(const std::string& key) const override;
307 
308  const std::string
309  key(int64_t fieldindex) const override;
310 
311  bool
312  haskey(const std::string& key) const override;
313 
314  const std::vector<std::string>
315  keys() const override;
316 
317  bool
318  istuple() const override;
319 
320  // operations
321  const std::string
322  validityerror(const std::string& path) const override;
323 
328  const ContentPtr
329  shallow_simplify() const override;
330 
331  const ContentPtr
332  num(int64_t axis, int64_t depth) const override;
333 
334  const std::pair<Index64, ContentPtr>
335  offsets_and_flattened(int64_t axis, int64_t depth) const override;
336 
337  bool
338  mergeable(const ContentPtr& other, bool mergebool) const override;
339 
340  bool
341  referentially_equal(const ContentPtr& other) const override;
342 
343  const ContentPtr
344  mergemany(const ContentPtrVec& others) const override;
345 
346  const SliceItemPtr
347  asslice() const override;
348 
349  const ContentPtr
350  fillna(const ContentPtr& value) const override;
351 
352  const ContentPtr
353  rpad(int64_t target, int64_t axis, int64_t depth) const override;
354 
355  const ContentPtr
356  rpad_and_clip(int64_t target,
357  int64_t axis,
358  int64_t depth) const override;
359 
360  const ContentPtr
361  reduce_next(const Reducer& reducer,
362  int64_t negaxis,
363  const Index64& starts,
364  const Index64& shifts,
365  const Index64& parents,
366  int64_t outlength,
367  bool mask,
368  bool keepdims) const override;
369 
370  const ContentPtr
371  sort_next(int64_t negaxis,
372  const Index64& starts,
373  const Index64& parents,
374  int64_t outlength,
375  bool ascending,
376  bool stable) const override;
377 
378  const ContentPtr
379  argsort_next(int64_t negaxis,
380  const Index64& starts,
381  const Index64& shifts,
382  const Index64& parents,
383  int64_t outlength,
384  bool ascending,
385  bool stable) const override;
386 
387  const ContentPtr
388  localindex(int64_t axis, int64_t depth) const override;
389 
390  const ContentPtr
391  combinations(int64_t n,
392  bool replacement,
393  const util::RecordLookupPtr& recordlookup,
394  const util::Parameters& parameters,
395  int64_t axis,
396  int64_t depth) const override;
397 
398  const ContentPtr
399  getitem_next(const SliceAt& at,
400  const Slice& tail,
401  const Index64& advanced) const override;
402 
403  const ContentPtr
404  getitem_next(const SliceRange& range,
405  const Slice& tail,
406  const Index64& advanced) const override;
407 
408  const ContentPtr
409  getitem_next(const SliceArray64& array,
410  const Slice& tail,
411  const Index64& advanced) const override;
412 
413  const ContentPtr
414  getitem_next(const SliceJagged64& jagged,
415  const Slice& tail,
416  const Index64& advanced) const override;
417 
418  const ContentPtr
419  getitem_next_jagged(const Index64& slicestarts,
420  const Index64& slicestops,
421  const SliceArray64& slicecontent,
422  const Slice& tail) const override;
423 
424  const ContentPtr
425  getitem_next_jagged(const Index64& slicestarts,
426  const Index64& slicestops,
427  const SliceMissing64& slicecontent,
428  const Slice& tail) const override;
429 
430  const ContentPtr
431  getitem_next_jagged(const Index64& slicestarts,
432  const Index64& slicestops,
433  const SliceJagged64& slicecontent,
434  const Slice& tail) const override;
435 
436  const ContentPtr
437  copy_to(kernel::lib ptr_lib) const override;
438 
439  const ContentPtr
440  numbers_to_type(const std::string& name) const override;
441 
443  bool
444  is_unique() const override;
445 
447  const ContentPtr
448  unique() const override;
449 
451  bool
452  is_subrange_equal(const Index64& start, const Index64& stop) const override;
453 
454  private:
456  const IndexOf<T> offsets_;
458  const ContentPtr content_;
459  const bool represents_regular_;
460  };
461 
462 #ifndef AWKWARD_LISTOFFSETARRAY_NO_EXTERN_TEMPLATE
463  extern template class ListOffsetArrayOf<int32_t>;
464  extern template class ListOffsetArrayOf<uint32_t>;
465  extern template class ListOffsetArrayOf<int64_t>;
466 #endif
467 
471 }
472 
473 #endif // AWKWARD_LISTOFFSETARRAY_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 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
Form describing ListOffsetArray.
Definition: ListOffsetArray.h:17
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
Represents an array of nested lists that can have different lengths using one index named offsets...
Definition: ListOffsetArray.h:111
std::shared_ptr< SliceItem > SliceItemPtr
Definition: Slice.h:15
lib
Definition: kernel-dispatch.h:20