Awkward Array: include/awkward/Index.h Source File

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"
12#include "awkward/kernel-dispatch.h"
13
14namespace awkward {
15 template <typename T>
16 class IndexOf;
17
31 class LIBAWKWARD_EXPORT_SYMBOL Index {
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
42 form2str(Form form);
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
80 LIBAWKWARD_EXPORT_SYMBOL
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>
104 empty_advanced();
105
107 bool
108 is_empty_advanced() const;
109
111 const std::shared_ptr<T>
112 ptr() const;
113
115 kernel::lib
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
189 IndexOf<T>
190 getitem_range(int64_t start, int64_t stop) const;
191
199 IndexOf<T>
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
217 IndexOf<int64_t>
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
255 using Index8 = IndexOf<int8_t>;
256 using IndexU8 = IndexOf<uint8_t>;
257 using Index32 = IndexOf<int32_t>;
258 using IndexU32 = IndexOf<uint32_t>;
259 using Index64 = IndexOf<int64_t>;
260}
261
262#endif // AWKWARD_INDEX_H_
awkward::Form
Abstract superclass of all array node forms, which expresses the nesting structure without any large ...
Definition: Content.h:39
awkward::IndexOf
A contiguous, one-dimensional array of integers used to represent data structures,...
Definition: Index.h:82
awkward::IndexOf::setitem_at_nowrap
void setitem_at_nowrap(int64_t at, T value) const
Assigns an integer value (type T) in-place.
awkward::IndexOf::nbytes_part
void nbytes_part(std::map< size_t, int64_t > &largest) const
Internal function used to calculate Content::nbytes.
awkward::IndexOf::tostring
const std::string tostring() const
Returns a string representation of this array (single-line XML).
awkward::IndexOf::data
T * data() const
Raw pointer to the beginning of data (i.e. offset accounted for).
awkward::IndexOf::getitem_range
IndexOf< T > getitem_range(int64_t start, int64_t stop) const
Subinterval of this array, handling negative indexing and bounds-checking like Python.
awkward::IndexOf::shallow_copy
const std::shared_ptr< Index > shallow_copy() const override
Copies this Index node without copying its buffer.
awkward::IndexOf::referentially_equal
bool referentially_equal(const IndexOf< T > &other) const
awkward::IndexOf::getitem_at_nowrap
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...
awkward::IndexOf::tostring_part
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.
awkward::IndexOf::empty_advanced
static IndexOf< T > empty_advanced()
Create a zero-length index representing an empty 'advanced' index.
awkward::IndexOf::iscontiguous
bool iscontiguous() const override
Returns true if this index is contiguous false otherwise.
awkward::IndexOf::classname
const std::string classname() const
User-friendly name of this class: "Index8", "IndexU8", "Index32", "IndexU32", or "Index64".
awkward::IndexOf::getitem_at
T getitem_at(int64_t at) const
Returns the element at a given position in the array, handling negative indexing and bounds-checking ...
awkward::IndexOf::ptr
const std::shared_ptr< T > ptr() const
Reference-counted pointer to the integer array buffer.
awkward::IndexOf::getitem_range_nowrap
IndexOf< T > getitem_range_nowrap(int64_t start, int64_t stop) const
Subinterval of this array, without handling negative indexing or bounds-checking.
awkward::IndexOf::offset
int64_t offset() const
Location of item zero in the buffer, relative to ptr, measured in the number of elements.
awkward::IndexOf::copy_to
const IndexOf< T > copy_to(kernel::lib ptr_lib) const
awkward::IndexOf::ptr_lib
kernel::lib ptr_lib() const
The Kernel Library that ptr uses.
awkward::IndexOf::deep_copy
const IndexOf< T > deep_copy() const
Copies this Index node and all the data in its buffer.
awkward::IndexOf::length
int64_t length() const
Number of elements in the array.
awkward::IndexOf::form
Form form() const
Returns the enum describing this Index's integer specialization.
awkward::IndexOf::is_empty_advanced
bool is_empty_advanced() const
Returns true if this is an empty 'advanced' index.
awkward::IndexOf::to64
IndexOf< int64_t > to64() const override
Converts this Index to an Index64.
awkward::Index
A contiguous, one-dimensional array of integers used to represent data structures,...
Definition: Index.h:31
awkward::Index::shallow_copy
virtual const std::shared_ptr< Index > shallow_copy() const =0
Copies this Index node without copying its buffer.
awkward::Index::form2str
static const std::string form2str(Form form)
Converts a Form enumeration into a string.
awkward::Index::str2form
static Form str2form(const std::string &str)
Converts a string into a Form enumeration.
awkward::Index::Form
Form
Integer type of an Index, used by ListForm, IndexedForm, etc.
Definition: Index.h:34
awkward::Index::to64
virtual IndexOf< int64_t > to64() const =0
Converts this Index to an Index64.
awkward::Index::~Index
virtual ~Index()
Virtual destructor acts as a first non-inline virtual function that determines a specific translation...
common.h
LIBAWKWARD_EXPORT_SYMBOL
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
kernel-dispatch.h
awkward::kernel::lib
lib
Definition: kernel-dispatch.h:20
awkward::kernel::lib::cpu
@ cpu
awkward
Definition: BitMaskedArray.h:15
util.h