Loading...
Searching...
No Matches
Index.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_INDEX_H_
4#define AWKWARD_INDEX_H_
5
6#include <string>
7#include <map>
8#include <memory>
9
10#include "awkward/common.h"
11#include "awkward/util.h"
13
14namespace awkward {
15 template <typename T>
16 class IndexOf;
17
32 public:
34 enum class Form {i8, u8, i32, u32, i64, kNumIndexForm};
35
37 static Form
38 str2form(const std::string& str);
39
41 static const std::string
43
47 virtual ~Index();
48
52 virtual const std::shared_ptr<Index>
53 shallow_copy() const = 0;
54
56 virtual IndexOf<int64_t>
57 to64() const = 0;
58
60 virtual bool
61 iscontiguous() const = 0;
62 };
63
77 template <typename T>
78 class
79#ifdef AWKWARD_INDEX_NO_EXTERN_TEMPLATE
81#endif
82 IndexOf: public Index {
83 public:
94 IndexOf<T>(const std::shared_ptr<T>& ptr,
95 int64_t offset,
96 int64_t length,
97 kernel::lib ptr_lib);
98
100 IndexOf<T>(int64_t length, kernel::lib ptr_lib = kernel::lib::cpu);
101
103 static IndexOf<T>
105
107 bool
109
111 const std::shared_ptr<T>
112 ptr() const;
113
116 ptr_lib() const;
117
119 T*
120 data() const;
121
128 int64_t
129 offset() const;
130
132 int64_t
133 length() const;
134
137 const std::string
138 classname() const;
139
141 const std::string
142 tostring() const;
143
150 const std::string
151 tostring_part(const std::string& indent,
152 const std::string& pre,
153 const std::string& post) const;
154
156 Form
157 form() const;
158
164 T
165 getitem_at(int64_t at) const;
166
169 T
170 getitem_at_nowrap(int64_t at) const;
171
175 void
176 setitem_at_nowrap(int64_t at, T value) const;
177
190 getitem_range(int64_t start, int64_t stop) const;
191
200 getitem_range_nowrap(int64_t start, int64_t stop) const;
201
211 void
212 nbytes_part(std::map<size_t, int64_t>& largest) const;
213
214 const std::shared_ptr<Index>
215 shallow_copy() const override;
216
218 to64() const override;
219
220 bool
221 iscontiguous() const override;
222
226 const IndexOf<T>
227 deep_copy() const;
228
229 const IndexOf<T>
230 copy_to(kernel::lib ptr_lib) const;
231
232 bool
233 referentially_equal(const IndexOf<T>& other) const;
234
235 private:
237 const std::shared_ptr<T> ptr_;
239 const kernel::lib ptr_lib_;
241 const int64_t offset_;
243 const int64_t length_;
244 bool is_empty_advanced_;
245 };
246
247#ifndef AWKWARD_INDEX_NO_EXTERN_TEMPLATE
248 extern template class IndexOf<int8_t>;
249 extern template class IndexOf<uint8_t>;
250 extern template class IndexOf<int32_t>;
251 extern template class IndexOf<uint32_t>;
252 extern template class IndexOf<int64_t>;
253#endif
254
260}
261
262#endif // AWKWARD_INDEX_H_
Abstract superclass of all array node forms, which expresses the nesting structure without any large ...
Definition: Content.h:39
A contiguous, one-dimensional array of integers used to represent data structures,...
Definition: Index.h:82
void setitem_at_nowrap(int64_t at, T value) const
Assigns an integer value (type T) in-place.
void nbytes_part(std::map< size_t, int64_t > &largest) const
Internal function used to calculate Content::nbytes.
const std::string tostring() const
Returns a string representation of this array (single-line XML).
T * data() const
Raw pointer to the beginning of data (i.e. offset accounted for).
IndexOf< T > getitem_range(int64_t start, int64_t stop) const
Subinterval of this array, handling negative indexing and bounds-checking like Python.
const std::shared_ptr< Index > shallow_copy() const override
Copies this Index node without copying its buffer.
bool referentially_equal(const IndexOf< T > &other) const
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 std::string tostring_part(const std::string &indent, const std::string &pre, const std::string &post) const
Internal function to build an output string for tostring.
static IndexOf< T > empty_advanced()
Create a zero-length index representing an empty 'advanced' index.
bool iscontiguous() const override
Returns true if this index is contiguous false otherwise.
const std::string classname() const
User-friendly name of this class: "Index8", "IndexU8", "Index32", "IndexU32", or "Index64".
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::shared_ptr< T > ptr() const
Reference-counted pointer to the integer array buffer.
IndexOf< T > getitem_range_nowrap(int64_t start, int64_t stop) const
Subinterval of this array, without handling negative indexing or bounds-checking.
int64_t offset() const
Location of item zero in the buffer, relative to ptr, measured in the number of elements.
const IndexOf< T > copy_to(kernel::lib ptr_lib) const
kernel::lib ptr_lib() const
The Kernel Library that ptr uses.
const IndexOf< T > deep_copy() const
Copies this Index node and all the data in its buffer.
int64_t length() const
Number of elements in the array.
Form form() const
Returns the enum describing this Index's integer specialization.
bool is_empty_advanced() const
Returns true if this is an empty 'advanced' index.
IndexOf< int64_t > to64() const override
Converts this Index to an Index64.
A contiguous, one-dimensional array of integers used to represent data structures,...
Definition: Index.h:31
virtual const std::shared_ptr< Index > shallow_copy() const =0
Copies this Index node without copying its buffer.
static const std::string form2str(Form form)
Converts a Form enumeration into a string.
static Form str2form(const std::string &str)
Converts a string into a Form enumeration.
Form
Integer type of an Index, used by ListForm, IndexedForm, etc.
Definition: Index.h:34
virtual IndexOf< int64_t > to64() const =0
Converts this Index to an Index64.
virtual ~Index()
Virtual destructor acts as a first non-inline virtual function that determines a specific translation...
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
lib
Definition: kernel-dispatch.h:20
Definition: BitMaskedArray.h:15