vecmem 1.14.0
Loading...
Searching...
No Matches
jagged_device_vector.ipp
1/*
2 * VecMem project, part of the ACTS project (R&D line)
3 *
4 * (c) 2021-2024 CERN for the benefit of the ACTS project
5 *
6 * Mozilla Public License Version 2.0
7 */
8
9#pragma once
10
11// System include(s).
12#include <cassert>
13
14namespace vecmem {
15
16template <typename T>
19 : m_size(data.size()), m_ptr(data.ptr()) {}
20
21template <typename T>
23 const jagged_device_vector& parent)
24 : m_size(parent.m_size), m_ptr(parent.m_ptr) {}
25
26template <typename T>
27VECMEM_HOST_AND_DEVICE jagged_device_vector<T>&
29
30 // Check if anything needs to be done.
31 if (this == &rhs) {
32 return *this;
33 }
34
35 // Make this object point at the same data in memory as the one we're
36 // copying from.
37 m_size = rhs.m_size;
38 m_ptr = rhs.m_ptr;
39
40 // Return this object.
41 return *this;
42}
43
44template <typename T>
45VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::at(size_type pos)
46 -> reference {
47
48 // Check if the index is valid.
49 assert(pos < m_size);
50
51 // Return a reference to the vector element.
52 return reference{m_ptr[pos]};
53}
54
55template <typename T>
56VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::at(size_type pos) const
58
59 // Check if the index is valid.
60 assert(pos < m_size);
61
62 // Return a reference to the vector element.
63 return const_reference{m_ptr[pos]};
64}
65
66template <typename T>
68 -> reference {
69
70 // Return a reference to the vector element.
71 return reference{m_ptr[pos]};
72}
73
74template <typename T>
75VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::operator[](
76 size_type pos) const -> const_reference {
77
78 // Return a reference to the vector element.
79 return const_reference{m_ptr[pos]};
80}
81
82template <typename T>
83VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::front() -> reference {
84
85 // Make sure that there is at least one element in the outer vector.
86 assert(m_size > 0);
87
88 // Return a reference to the first element of the vector.
89 return reference{m_ptr[0]};
90}
91
92template <typename T>
93VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::front() const
95
96 // Make sure that there is at least one element in the outer vector.
97 assert(m_size > 0);
98
99 // Return a reference to the first element of the vector.
100 return const_reference{m_ptr[0]};
101}
102
103template <typename T>
104VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::back() -> reference {
105
106 // Make sure that there is at least one element in the outer vector.
107 assert(m_size > 0);
108
109 // Return a reference to the last element of the vector.
110 return reference{m_ptr[m_size - 1]};
111}
112
113template <typename T>
114VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::back() const
115 -> const_reference {
116
117 // Make sure that there is at least one element in the outer vector.
118 assert(m_size > 0);
119
120 // Return a reference to the last element of the vector.
121 return const_reference{m_ptr[m_size - 1]};
122}
123
124template <typename T>
125VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::begin() -> iterator {
126
127 return iterator(m_ptr);
128}
129
130template <typename T>
131VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::begin() const
132 -> const_iterator {
133
134 return const_iterator(m_ptr);
135}
136
137template <typename T>
138VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::cbegin() const
139 -> const_iterator {
140
141 return begin();
142}
143
144template <typename T>
145VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::end() -> iterator {
146
147 return iterator(m_ptr + m_size);
148}
149
150template <typename T>
151VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::end() const
152 -> const_iterator {
153
154 return const_iterator(m_ptr + m_size);
155}
156
157template <typename T>
158VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::cend() const
159 -> const_iterator {
160
161 return end();
162}
163
164template <typename T>
165VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::rbegin()
167
168 return reverse_iterator(end());
169}
170
171template <typename T>
172VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::rbegin() const
174
175 return const_reverse_iterator(end());
176}
177
178template <typename T>
179VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::crbegin() const
181
182 return rbegin();
183}
184
185template <typename T>
186VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::rend()
188
189 return reverse_iterator(begin());
190}
191
192template <typename T>
193VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::rend() const
195
196 return const_reverse_iterator(begin());
197}
198
199template <typename T>
200VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::crend() const
202
203 return rend();
204}
205
206template <typename T>
207VECMEM_HOST_AND_DEVICE bool jagged_device_vector<T>::empty(void) const {
208 return m_size == 0;
209}
210
211template <typename T>
212VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::size(void) const
213 -> size_type {
214 return m_size;
215}
216
217template <typename T>
218VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::max_size() const
219 -> size_type {
220
221 return m_size;
222}
223
224template <typename T>
225VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::capacity() const
226 -> size_type {
227
228 return m_size;
229}
230
231} // namespace vecmem
A view for jagged vectors.
Definition jagged_vector_view.hpp:44
Custom iterator for vecmem::jagged_device_vector.
Definition jagged_device_vector_iterator.hpp:34
Type mimicking std::reverse_iterator.
Definition reverse_iterator.hpp:25
A view for jagged vectors.
Definition jagged_device_vector.hpp:47
VECMEM_HOST_AND_DEVICE jagged_device_vector(data::jagged_vector_view< T > data)
Construct a jagged device vector from a jagged vector view object.
Definition jagged_device_vector.ipp:17
VECMEM_HOST_AND_DEVICE reverse_iterator rend()
Return a reverse iterator pointing at the beginning of the vector.
Definition jagged_device_vector.ipp:186
VECMEM_HOST_AND_DEVICE const_iterator cbegin() const
Return a constant forward iterator pointing at the beginning of the vector.
Definition jagged_device_vector.ipp:138
VECMEM_HOST_AND_DEVICE jagged_device_vector & operator=(const jagged_device_vector &rhs)
Copy assignment operator.
Definition jagged_device_vector.ipp:28
VECMEM_HOST_AND_DEVICE const_iterator cend() const
Return a constant forward iterator pointing at the end of the vector.
Definition jagged_device_vector.ipp:158
VECMEM_HOST_AND_DEVICE size_type max_size() const
Return the maximum (fixed) number of elements in the vector.
Definition jagged_device_vector.ipp:218
VECMEM_HOST_AND_DEVICE reference at(size_type pos)
Return a specific element of the vector in a "safe way" (non-const)
Definition jagged_device_vector.ipp:45
VECMEM_HOST_AND_DEVICE reverse_iterator rbegin()
Return a reverse iterator pointing at the end of the vector.
Definition jagged_device_vector.ipp:165
VECMEM_HOST_AND_DEVICE const_reverse_iterator crend() const
Return a constant reverse iterator pointing at the beginning of the vector.
Definition jagged_device_vector.ipp:200
VECMEM_HOST_AND_DEVICE reference front()
Return the first element of the vector (non-const)
Definition jagged_device_vector.ipp:83
VECMEM_HOST_AND_DEVICE size_type size(void) const
Get the number of rows in this view.
Definition jagged_device_vector.ipp:212
VECMEM_HOST_AND_DEVICE iterator begin()
Return a forward iterator pointing at the beginning of the vector.
Definition jagged_device_vector.ipp:125
VECMEM_HOST_AND_DEVICE const_reverse_iterator crbegin() const
Return a constant reverse iterator pointing at the end of the vector.
Definition jagged_device_vector.ipp:179
device_vector< T > reference
Value reference type.
Definition jagged_device_vector.hpp:61
VECMEM_HOST_AND_DEVICE reference back()
Return the last element of the vector (non-const)
Definition jagged_device_vector.ipp:104
VECMEM_HOST_AND_DEVICE iterator end()
Return a forward iterator pointing at the end of the vector.
Definition jagged_device_vector.ipp:145
device_vector< std::add_const_t< T > > const_reference
Constant value reference type.
Definition jagged_device_vector.hpp:63
VECMEM_HOST_AND_DEVICE bool empty(void) const
Checks whether this view has no rows.
Definition jagged_device_vector.ipp:207
VECMEM_HOST_AND_DEVICE size_type capacity() const
Return the current (fixed) capacity of the vector.
Definition jagged_device_vector.ipp:225
VECMEM_HOST_AND_DEVICE reference operator[](size_type pos)
Return a specific element of the vector (non-const)
Definition jagged_device_vector.ipp:67
std::size_t size_type
Size type for the array.
Definition jagged_device_vector.hpp:56
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35