80 #ifndef AU_ARRAY_VIEW_ACCESS_H
81 #define AU_ARRAY_VIEW_ACCESS_H
89 #define ARRAY_VIEW_READ 0
90 #define ARRAY_VIEW_WRITE 1
102 #define VIEW_ACCESS_HELP_V(v_bu, v_st, a_bu, a_st, count_n, rw) \
104 if (rw == ARRAY_VIEW_READ) \
107 std::copy(a_bu.begin() + a_st, a_bu.begin() + a_st + count_n, v_bu.begin() + v_st); \
111 std::copy(v_bu.begin() + v_st, v_bu.begin() + v_st + count_n, a_bu.begin() + a_st); \
127 inline int ArrayViewAccessV(std::vector<T> &view_v, std::vector<T> &array_v, std::vector<unsigned long long> &array_size, std::vector<unsigned long long> &start, std::vector<unsigned long long> &end,
int read_write_code)
129 std::vector<unsigned long long> view_size;
130 unsigned long long element_count = 1;
131 view_size.resize(array_size.size());
132 for (
int i = 0; i < array_size.size(); i++)
134 view_size[i] = end[i] - start[i] + 1;
135 element_count = element_count * view_size[i];
138 view_v.resize(element_count);
139 if (view_size == array_size)
141 VIEW_ACCESS_HELP(view_v, 0, array_v, 0, element_count, read_write_code);
145 if (view_size.size() == 1)
147 VIEW_ACCESS_HELP(view_v, 0, array_v, start[0], element_count, read_write_code);
151 unsigned long long array_buffer_offset = 0, view_buffer_offset = 0;
153 if (view_size.size() == 2)
155 for (
int i = 0; i < view_size[0]; i++)
157 array_buffer_offset = array_size[1] * (start[0] + i) + start[1];
158 view_buffer_offset = view_size[1] * i;
160 VIEW_ACCESS_HELP(view_v, view_buffer_offset, array_v, array_buffer_offset, view_size[1], read_write_code);
166 array_buffer_offset = 0, view_buffer_offset = 0;
167 std::vector<unsigned long long> ord(start.begin(), start.end());
168 for (
unsigned long long i = 0; i < element_count; i++)
171 MEMCPY_ACCESS_HELP(view_v, view_buffer_offset, array_v, array_buffer_offset, 1, read_write_code);
172 view_buffer_offset++;
182 #define VIEW_ACCESS_HELP_P(v_bu, v_st, a_bu, a_st, count_n, rw, type_size) \
184 if (rw == ARRAY_VIEW_READ) \
186 std::memcpy(v_bu + v_st, a_bu + a_st, count_n * type_size); \
190 std::memcpy(a_bu + a_st, v_bu + v_st, count_n * type_size); \
195 inline int ArrayViewAccessP(T *view_v, T *array_v, std::vector<unsigned long long> array_size, std::vector<unsigned long long> start, std::vector<unsigned long long> end,
int read_write_code)
197 std::vector<unsigned long long> view_size;
198 unsigned long long element_count = 1;
199 view_size.resize(array_size.size());
200 for (
int i = 0; i < array_size.size(); i++)
202 view_size[i] = end[i] - start[i] + 1;
203 element_count = element_count * view_size[i];
207 if (view_size == array_size)
213 if (view_size.size() == 1)
215 VIEW_ACCESS_HELP_P(view_v, 0, array_v, start[0], element_count, read_write_code,
sizeof(T));
219 unsigned long long array_buffer_offset = 0, view_buffer_offset = 0;
220 if (view_size.size() == 2)
225 for (
int i = 0; i < view_size[0]; i++)
229 array_buffer_offset = array_size[1] * (start[0] + i) + start[1];
230 view_buffer_offset = view_size[1] * i;
232 VIEW_ACCESS_HELP_P(view_v, view_buffer_offset, array_v, array_buffer_offset, view_size[1], read_write_code,
sizeof(T));
239 array_buffer_offset = 0, view_buffer_offset = 0;
240 std::vector<unsigned long long> ord(start.begin(), start.end());
241 for (
unsigned long long i = 0; i < element_count; i++)
244 VIEW_ACCESS_HELP_P(view_v, view_buffer_offset, array_v, array_buffer_offset, 1, read_write_code,
sizeof(T));
245 view_buffer_offset++;
#define ITERATOR_MACRO(ordinates_p, start_p, end_p)
Definition: ft_array_iterator.h:97
#define VIEW_ACCESS_HELP_P(v_bu, v_st, a_bu, a_st, count_n, rw, type_size)
Definition: ft_array_view_access.h:182
int ArrayViewAccessP(T *view_v, T *array_v, std::vector< unsigned long long > array_size, std::vector< unsigned long long > start, std::vector< unsigned long long > end, int read_write_code)
Definition: ft_array_view_access.h:195
int ArrayViewAccessV(std::vector< T > &view_v, std::vector< T > &array_v, std::vector< unsigned long long > &array_size, std::vector< unsigned long long > &start, std::vector< unsigned long long > &end, int read_write_code)
Access an view (subset) of an array.
Definition: ft_array_view_access.h:127
#define ROW_MAJOR_ORDER_MACRO(dsize, dsize_len, coordinate, offset)
macro version of above two functions for speed
Definition: ft_utility_macro.h:124