21#include "../base/base_uses.f90"
23 USE libxs,
ONLY: libxs_diff
26# define PURE_ARRAY_EQ PURE
31 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'dbt_array_list_methods'
50 INTEGER,
DIMENSION(:),
ALLOCATABLE :: col_data
51 INTEGER,
DIMENSION(:),
ALLOCATABLE :: ptr
55 MODULE PROCEDURE allocate_and_get_ith_array
80 INTEGER,
DIMENSION(number_of_arrays(list)),
INTENT(IN) :: indices
85 DO i = 1,
SIZE(indices)
86 ind = indices(i) +
list%ptr(i) - 1
102 INTEGER,
INTENT(IN) :: ndata
103 INTEGER,
DIMENSION(:),
INTENT(IN),
OPTIONAL :: data_1, data_2, data_3, data_4
104 INTEGER :: ptr, size_all
109 cpassert(
PRESENT(data_1))
110 size_all = size_all +
SIZE(data_1)
113 cpassert(
PRESENT(data_2))
114 size_all = size_all +
SIZE(data_2)
117 cpassert(
PRESENT(data_3))
118 size_all = size_all +
SIZE(data_3)
121 cpassert(
PRESENT(data_4))
122 size_all = size_all +
SIZE(data_4)
125 ALLOCATE (
list%ptr(ndata + 1))
126 ALLOCATE (
list%col_data(size_all))
132 list%col_data(ptr:ptr +
SIZE(data_1) - 1) = data_1(:)
133 ptr = ptr +
SIZE(data_1)
137 list%col_data(ptr:ptr +
SIZE(data_2) - 1) = data_2(:)
138 ptr = ptr +
SIZE(data_2)
142 list%col_data(ptr:ptr +
SIZE(data_3) - 1) = data_3(:)
143 ptr = ptr +
SIZE(data_3)
147 list%col_data(ptr:ptr +
SIZE(data_4) - 1) = data_4(:)
148 ptr = ptr +
SIZE(data_4)
162 INTEGER,
DIMENSION(:),
INTENT(IN) :: i_selected
165 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: data_1, data_2, data_3, data_4
167 ndata =
SIZE(i_selected)
178 CALL get_arrays(
list, data_1, data_2, data_3, i_selected=i_selected)
182 CALL get_arrays(
list, data_1, data_2, data_3, data_4, i_selected=i_selected)
194 DEALLOCATE (
list%ptr,
list%col_data)
203 SUBROUTINE get_arrays(list, data_1, data_2, data_3, data_4, i_selected)
206 INTEGER,
ALLOCATABLE,
DIMENSION(:),
INTENT(OUT), &
207 OPTIONAL :: data_1, data_2, data_3, data_4
208 INTEGER,
DIMENSION(:),
INTENT(IN), &
209 OPTIONAL :: i_selected
211 INTEGER,
DIMENSION(number_of_arrays(list)) :: o
214 IF (
PRESENT(i_selected))
THEN
215 ndata =
SIZE(i_selected)
216 o(1:ndata) = i_selected(:)
219 o(1:ndata) = (/(i, i=1, ndata)/)
222 associate(ptr =>
list%ptr, col_data =>
list%col_data)
224 ALLOCATE (data_1, source=col_data(ptr(o(1)):ptr(o(1) + 1) - 1))
227 ALLOCATE (data_2, source=col_data(ptr(o(2)):ptr(o(2) + 1) - 1))
230 ALLOCATE (data_3, source=col_data(ptr(o(3)):ptr(o(3) + 1) - 1))
233 ALLOCATE (data_4, source=col_data(ptr(o(4)):ptr(o(4) + 1) - 1))
245 INTEGER,
INTENT(IN) :: i
246 INTEGER,
INTENT(IN) :: array_size
247 INTEGER,
DIMENSION(array_size),
INTENT(OUT) :: array
249 associate(ptr =>
list%ptr, col_data =>
list%col_data)
252 array(:) = col_data(ptr(i):ptr(i + 1) - 1)
262 SUBROUTINE allocate_and_get_ith_array(list, i, array)
264 INTEGER,
INTENT(IN) :: i
265 INTEGER,
DIMENSION(:),
ALLOCATABLE,
INTENT(OUT) :: array
267 associate(ptr =>
list%ptr, col_data =>
list%col_data)
270 ALLOCATE (array, source=col_data(ptr(i):ptr(i + 1) - 1))
282 INTEGER :: i_data, num_data
286 DO i_data = 1, num_data
299 INTEGER :: i_data, num_data
303 DO i_data = 1, num_data
317 INTEGER :: i_data, i_ptr, num_data, partial_sum
320 ALLOCATE (list_out%ptr, source=list_in%ptr)
321 ALLOCATE (list_out%col_data(
SIZE(list_in%col_data)))
322 DO i_data = 1, num_data
324 DO i_ptr = list_out%ptr(i_data), list_out%ptr(i_data + 1) - 1
325 list_out%col_data(i_ptr) = partial_sum
326 partial_sum = partial_sum + list_in%col_data(i_ptr)
338 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: data_1, data_2, data_3, data_4
339 INTEGER,
DIMENSION(number_of_arrays(list_in)), &
343 CALL get_arrays(list_in, data_1, data_2, i_selected=dbt_inverse_order(order))
348 CALL get_arrays(list_in, data_1, data_2, data_3, i_selected=dbt_inverse_order(order))
350 data_1, data_2, data_3)
353 CALL get_arrays(list_in, data_1, data_2, data_3, data_4, i_selected=dbt_inverse_order(order))
355 data_1, data_2, data_3, data_4)
368 check_equal = array_eq_i(list1%col_data, list2%col_data) .AND. array_eq_i(list1%ptr, list2%ptr)
375 pure_array_eq
FUNCTION array_eq_i(arr1, arr2)
376 INTEGER,
INTENT(IN),
DIMENSION(:) :: arr1
377 INTEGER,
INTENT(IN),
DIMENSION(:) :: arr2
378 LOGICAL :: array_eq_i
381 array_eq_i = .NOT. libxs_diff(arr1, arr2)
384 IF (
SIZE(arr1) ==
SIZE(arr2)) array_eq_i = all(arr1 == arr2)
Wrapper for allocating, copying and reshaping arrays.
Representation of arbitrary number of 1d integer arrays with arbitrary sizes. This is needed for gene...
integer function, dimension(:), allocatable, public sum_of_arrays(list)
sum of all elements for each array stored in list
subroutine, public get_arrays(list, data_1, data_2, data_3, data_4, i_selected)
Get all arrays contained in list.
subroutine, public create_array_list(list, ndata, data_1, data_2, data_3, data_4)
collects any number of arrays of different sizes into a single array (listcol_data),...
subroutine, public destroy_array_list(list)
destroy array list.
integer function, dimension(:), allocatable, public sizes_of_arrays(list)
sizes of arrays stored in list
pure integer function, public number_of_arrays(list)
number of arrays stored in list
subroutine, public array_offsets(list_in, list_out)
partial sums of array elements.
pure integer function, dimension(number_of_arrays(list)), public get_array_elements(list, indices)
Get an element for each array.
type(array_list) function, public array_sublist(list, i_selected)
extract a subset of arrays
subroutine, public reorder_arrays(list_in, list_out, order)
reorder array list.
logical function, public check_equal(list1, list2)
check whether two array lists are equal
tensor index and mapping to DBM index
pure integer function, dimension(size(order)), public dbt_inverse_order(order)
Invert order.
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...