Is there any implementation of sparse arrays or equivalent lists in Fortran.
In the stage of computation of large data set we pass say an array of size of n=10000 to a subroutine to do some stuff on them. For example, finding similar elements in it and listing them for each item sequentially. That is, for item one, to find all similar items through the list (array) and to store the resulting marks. The resulting could be large as the list for each element. Note that regarding the criteria the similarity we use is not symmetric which means we need to iterate the evaluation for all items fully. The resulting therefore could be in different length for each according to criteria being used. Storing all the results therefore requires sparse arrays/list which is available in Python as:
R = an array # an array
L = [] # list initialization
for e in R: # iteration on all elements of R
r = similars(e,R,criteria) # r is array & different in size for each element
L.append(r) # store the ranks in list L
For simplicity now we use usual arrays in Fortran where for n<=1000 it is n*n. As you see this is a very inefficient idea for larger sizes.
Any solution?
A solution without linked list.
Here, one assumes that the vectors “r” contain double precision values.
Notice that this solution uses no pointer, just allocatable arrays, which warrants to avoid memory leaks. The number of reallocations is limited (log2(list%n)) but one accepts to allocate list%result with a size larger than really needed (maximum twice).
At last, the vectors “r” are duplicated in the list (this is not the case in the python version).
Result :