vecmem 1.28.0
Loading...
Searching...
No Matches
jagged_vector.ipp
1/*
2 * VecMem project, part of the ACTS project (R&D line)
3 *
4 * (c) 2021 CERN for the benefit of the ACTS project
5 *
6 * Mozilla Public License Version 2.0
7 */
8#pragma once
9
10// VecMem include(s).
11#include "vecmem/utils/details/narrow_size.hpp"
12
13// System include(s).
14#include <cassert>
15
16namespace vecmem {
17
18template <typename TYPE>
20 memory_resource* resource) {
21
22 // Get the size of the "outer vector".
23 const std::size_t size = vec.size();
24
25 // Construct the object to be returned.
29 (resource != nullptr ? *resource : *(vec.get_allocator().resource())));
30
31 // Helper local type definition(s).
32 typedef typename data::jagged_vector_data<TYPE>::value_type value_type;
33 typedef typename value_type::size_type size_type;
34
35 // Fill the result object with information.
36 for (std::size_t i = 0; i < size; ++i) {
37 result.host_ptr()[i] =
38 value_type(static_cast<size_type>(vec[i].size()), vec[i].data());
39 }
40
41 // Return the created object.
42 return result;
43}
44
45template <typename TYPE, typename ALLOC1, typename ALLOC2>
47 std::vector<std::vector<TYPE, ALLOC1>, ALLOC2>& vec,
48 memory_resource* resource) {
49
50 // This function needs a non-null memory resource pointer.
51 assert(resource != nullptr);
52
53 // Get the size of the "outer vector".
54 const std::size_t size = vec.size();
55
56 // Construct the object to be returned.
60 *resource);
61
62 // Helper local type definition(s).
63 typedef typename data::jagged_vector_data<TYPE>::value_type value_type;
64 typedef typename value_type::size_type size_type;
65
66 // Fill the result object with information.
67 for (std::size_t i = 0; i < size; ++i) {
68 result.host_ptr()[i] =
69 value_type(static_cast<size_type>(vec[i].size()), vec[i].data());
70 }
71
72 // Return the created object.
73 return result;
74}
75
76template <typename TYPE>
78 memory_resource* resource) {
79
80 // Get the size of the "outer vector".
81 const std::size_t size = vec.size();
82
83 // Construct the object to be returned.
87 (resource != nullptr ? *resource : *(vec.get_allocator().resource())));
88
89 // Helper local type definition(s).
90 typedef
92 typedef typename value_type::size_type size_type;
93
94 // Fill the result object with information.
95 for (std::size_t i = 0; i < size; ++i) {
96 result.host_ptr()[i] =
97 value_type(static_cast<size_type>(vec[i].size()), vec[i].data());
98 }
99
100 // Return the created object.
101 return result;
102}
103
104template <typename TYPE, typename ALLOC1, typename ALLOC2>
106 const std::vector<std::vector<TYPE, ALLOC1>, ALLOC2>& vec,
107 memory_resource* resource) {
108
109 // This function needs a non-null memory resource pointer.
110 assert(resource != nullptr);
111
112 // Get the size of the "outer vector".
113 const std::size_t size = vec.size();
114
115 // Construct the object to be returned.
119 *resource);
120
121 // Helper local type definition(s).
122 typedef
124 typedef typename value_type::size_type size_type;
125
126 // Fill the result object with information.
127 for (std::size_t i = 0; i < size; ++i) {
128 result.host_ptr()[i] =
129 value_type(static_cast<size_type>(vec[i].size()), vec[i].data());
130 }
131
132 // Return the created object.
133 return result;
134}
135
136} // namespace vecmem
An allocator class that wraps a memory resource.
Definition allocator.hpp:37
A data wrapper for jagged vectors.
Definition jagged_vector_data.hpp:30
typename base_type::size_type size_type
Use the base class's size_type.
Definition jagged_vector_data.hpp:36
typename base_type::value_type value_type
Use the base class's value_type.
Definition jagged_vector_data.hpp:38
VECMEM_HOST constexpr SIZE_TYPE narrow_size(INPUT_TYPE size)
Narrow a host-side element count to a device-side size type.
Definition narrow_size.hpp:47
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
VECMEM_HOST data::vector_view< T > get_data(array< T, N > &a)
Helper function creating a vecmem::data::vector_view object.
Definition array.ipp:217