Loading...
Searching...
No Matches
Identities.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_IDENTITIES_H_
4#define AWKWARD_IDENTITIES_H_
5
6#include <string>
7#include <vector>
8#include <map>
9#include <memory>
10
11#include "awkward/common.h"
12#include "awkward/Index.h"
13
14namespace awkward {
15 class Identities;
16 using IdentitiesPtr = std::shared_ptr<Identities>;
17
58 public:
60 using Ref = int64_t;
61
63 using FieldLoc = std::vector<std::pair<int64_t, std::string>>;
64
69 static Ref
71
73 static IdentitiesPtr
75
89 Identities(const Ref ref,
90 const FieldLoc& fieldloc,
91 int64_t offset,
92 int64_t width,
93 int64_t length);
94
98 virtual ~Identities();
99
101 const Ref
102 ref() const;
103
106 const FieldLoc
107 fieldloc() const;
108
114 const int64_t
115 offset() const;
116
118 const int64_t
119 width() const;
120
122 const int64_t
123 length() const;
124
126 virtual kernel::lib
127 ptr_lib() const = 0;
128
131 virtual const std::string
132 classname() const = 0;
133
135 virtual const std::string
136 identity_at(int64_t where) const = 0;
137
139 virtual const IdentitiesPtr
140 to64() const = 0;
141
148 virtual const std::string
149 tostring_part(const std::string& indent,
150 const std::string& pre,
151 const std::string& post) const = 0;
152
158 virtual const IdentitiesPtr
159 getitem_range_nowrap(int64_t start, int64_t stop) const = 0;
160
170 virtual void
171 nbytes_part(std::map<size_t, int64_t>& largest) const = 0;
172
176 virtual const IdentitiesPtr
177 shallow_copy() const = 0;
178
182 virtual const IdentitiesPtr
183 deep_copy() const = 0;
184
206 virtual const IdentitiesPtr
207 getitem_carry_64(const Index64& carry) const = 0;
208
210 virtual const IdentitiesPtr
211 withfieldloc(const FieldLoc& fieldloc) const = 0;
212
215 virtual int64_t
216 value(int64_t row, int64_t col) const = 0;
217
224 virtual const IdentitiesPtr
225 copy_to(kernel::lib ptr_lib) const = 0;
226
228 const std::string
229 tostring() const;
230
235 virtual bool
236 referentially_equal(const IdentitiesPtr& other) const = 0;
237
238 protected:
240 const Ref ref_;
244 int64_t offset_;
246 int64_t width_;
248 int64_t length_;
249 };
250
290 template <typename T>
291 class
292#ifdef AWKWARD_IDENTITIES_NO_EXTERN_TEMPLATE
294#endif
295 IdentitiesOf: public Identities {
296 public:
311 IdentitiesOf<T>(const Ref ref,
312 const FieldLoc& fieldloc,
313 int64_t offset,
314 int64_t width,
315 int64_t length,
316 const std::shared_ptr<T> ptr,
317 kernel::lib ptr_lib = kernel::lib::cpu);
318
321 IdentitiesOf<T>(const Ref ref,
322 const FieldLoc& fieldloc,
323 int64_t width,
324 int64_t length,
325 kernel::lib ptr_lib = kernel::lib::cpu);
326
328 const std::shared_ptr<T>
329 ptr() const;
330
332 ptr_lib() const override;
333
335 T*
336 data() const;
337
338 const std::string
339 classname() const override;
340
341 const std::string
342 identity_at(int64_t at) const override;
343
344 const IdentitiesPtr
345 to64() const override;
346
347 const std::string
348 tostring_part(const std::string& indent,
349 const std::string& pre,
350 const std::string& post) const override;
351
352 const IdentitiesPtr
353 getitem_range_nowrap(int64_t start, int64_t stop) const override;
354
355 void
356 nbytes_part(std::map<size_t, int64_t>& largest) const override;
357
358 const IdentitiesPtr
359 shallow_copy() const override;
360
361 const IdentitiesPtr
362 deep_copy() const override;
363
364 const IdentitiesPtr
365 getitem_carry_64(const Index64& carry) const override;
366
367 const IdentitiesPtr
368 withfieldloc(const FieldLoc& fieldloc) const override;
369
370 int64_t
371 value(int64_t row, int64_t col) const override;
372
373 const IdentitiesPtr
374 copy_to(kernel::lib ptr_lib) const override;
375
381 const std::vector<T>
382 getitem_at(int64_t at) const;
383
386 const std::vector<T>
387 getitem_at_nowrap(int64_t at) const;
388
400 const IdentitiesPtr
401 getitem_range(int64_t start, int64_t stop) const;
402
403 bool
404 referentially_equal(const IdentitiesPtr& other) const override;
405
406 private:
408 const std::shared_ptr<T> ptr_;
410 const kernel::lib ptr_lib_;
411 };
412
413#ifndef AWKWARD_IDENTITIES_NO_EXTERN_TEMPLATE
414 extern template class IdentitiesOf<int32_t>;
415 extern template class IdentitiesOf<int64_t>;
416#endif
417
420}
421
422#endif // AWKWARD_IDENTITIES_H_
A contiguous, two-dimensional array of integers and a list of strings used to represent a path from t...
Definition: Identities.h:295
const IdentitiesPtr deep_copy() const override
Copies this Identities node and all the data in its buffer.
const IdentitiesPtr withfieldloc(const FieldLoc &fieldloc) const override
Returns this Identities node with a different fieldloc.
T * data() const
Raw pointer to the beginning of data (i.e. offset accounted for).
const IdentitiesPtr shallow_copy() const override
Copies this Identities node without copying its buffer.
const std::vector< T > getitem_at(int64_t at) const
Returns the element at a given position in the array, handling negative indexing and bounds-checking ...
const std::string identity_at(int64_t at) const override
Return a string representing an identity tuple at where.
bool referentially_equal(const IdentitiesPtr &other) const override
Returns true if this Identities has all the same buffers and parameters as other; false otherwise.
const IdentitiesPtr copy_to(kernel::lib ptr_lib) const override
Moves the identity ptr buffer of the array between devices.
const IdentitiesPtr getitem_range(int64_t start, int64_t stop) const
Subinterval of this array, handling negative indexing and bounds-checking like Python.
void nbytes_part(std::map< size_t, int64_t > &largest) const override
Internal function used to calculate Content::nbytes.
const IdentitiesPtr to64() const override
Converts this Identities to an Identities64.
const IdentitiesPtr getitem_carry_64(const Index64 &carry) const override
Returns an Identities array with elements filtered, rearranged, and possibly duplicated by the carry ...
const std::shared_ptr< T > ptr() const
Reference-counted pointer to the array buffer.
const std::string tostring_part(const std::string &indent, const std::string &pre, const std::string &post) const override
Internal function to build an output string for tostring.
int64_t value(int64_t row, int64_t col) const override
Returns the integer value of the two-dimensional array at row and col.
const std::vector< T > getitem_at_nowrap(int64_t at) const
Returns the element at a given position in the array, without handling negative indexing or bounds-ch...
const IdentitiesPtr getitem_range_nowrap(int64_t start, int64_t stop) const override
Subinterval of this array, without handling negative indexing or bounds-checking.
kernel::lib ptr_lib() const override
The Kernel Library that ptr uses.
const std::string classname() const override
User-friendly name of this class: "Identities32" or "Identities64".
A contiguous, two-dimensional array of integers and a list of strings used to represent a path from t...
Definition: Identities.h:57
const std::string tostring() const
Returns a string representation of this array (multi-line XML).
Identities(const Ref ref, const FieldLoc &fieldloc, int64_t offset, int64_t width, int64_t length)
Called by all subclass constructors; assigns ref, fieldloc, offset, width, and length upon constructi...
int64_t width_
See width.
Definition: Identities.h:246
const int64_t length() const
The number of identities in the array.
const int64_t width() const
The number of integers in each identity tuple.
static IdentitiesPtr none()
A constant, empty Identities pointer (nullptr).
virtual const IdentitiesPtr to64() const =0
Converts this Identities to an Identities64.
virtual kernel::lib ptr_lib() const =0
The Kernel Library that ptr uses.
virtual const IdentitiesPtr getitem_carry_64(const Index64 &carry) const =0
Returns an Identities array with elements filtered, rearranged, and possibly duplicated by the carry ...
virtual ~Identities()
Virtual destructor acts as a first non-inline virtual function that determines a specific translation...
int64_t Ref
Identities reference type (64-bit integer).
Definition: Identities.h:60
virtual const std::string tostring_part(const std::string &indent, const std::string &pre, const std::string &post) const =0
Internal function to build an output string for tostring.
static Ref newref()
Returns a new Identities reference that is globally unique in the current process.
virtual const IdentitiesPtr copy_to(kernel::lib ptr_lib) const =0
Moves the identity ptr buffer of the array between devices.
const Ref ref() const
A globally unique reference to this set of identities.
virtual const IdentitiesPtr shallow_copy() const =0
Copies this Identities node without copying its buffer.
const int64_t offset() const
Location of item zero in the buffer, relative to ptr, measured in the number of elements....
virtual int64_t value(int64_t row, int64_t col) const =0
Returns the integer value of the two-dimensional array at row and col.
virtual const std::string classname() const =0
User-friendly name of this class: "Identities32" or "Identities64".
const FieldLoc fieldloc_
See fieldloc.
Definition: Identities.h:242
const FieldLoc fieldloc() const
A list of integer-string pairs indicating the positions of all tuple/record field indicators within t...
virtual const IdentitiesPtr deep_copy() const =0
Copies this Identities node and all the data in its buffer.
virtual void nbytes_part(std::map< size_t, int64_t > &largest) const =0
Internal function used to calculate Content::nbytes.
std::vector< std::pair< int64_t, std::string > > FieldLoc
Identities field location type (integer-string pairs).
Definition: Identities.h:63
int64_t offset_
See offset.
Definition: Identities.h:244
virtual const IdentitiesPtr getitem_range_nowrap(int64_t start, int64_t stop) const =0
Subinterval of this array, without handling negative indexing or bounds-checking.
virtual const std::string identity_at(int64_t where) const =0
Return a string representing an identity tuple at where.
const Ref ref_
See ref.
Definition: Identities.h:240
virtual const IdentitiesPtr withfieldloc(const FieldLoc &fieldloc) const =0
Returns this Identities node with a different fieldloc.
virtual bool referentially_equal(const IdentitiesPtr &other) const =0
Returns true if this Identities has all the same buffers and parameters as other; false otherwise.
A contiguous, one-dimensional array of integers used to represent data structures,...
Definition: Index.h:82
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
lib
Definition: kernel-dispatch.h:20
Definition: BitMaskedArray.h:15
std::shared_ptr< Identities > IdentitiesPtr
Definition: Identities.h:16