Closed Inazuma110 closed 3 years ago
Really nice -- I made a few changes internally to use the functions already in the package, it barely changes the performance (a little less memory is needed). I'll merge - thanks for the great contributions :tada: !
Improved performance of function lp
Improved the performance of function lp. In this function, the following two factors had a significant impact on the performance.
The first is to retrieve the adjacent vertex each time for each vertex.
When the number of vertices is N, the computational complexity of this operation is O(N). In the original code, this operation is performed on all vertices, so the computational complexity is O(N^2), which is very slow. In this fix, adjacent vertices are now precomputed and retained.
The other is the format of the counts variable.
Before the fix, the function Stats.counts was used to counting the occurrences of labels. However, if the neighboring labels are far apart in value, there will be many zeroes in the array. (For example, applying the Stats.counts function to [1, 100] would result in [1, 0, ... , 0, 1], resulting in 98 useless elements.) This information is not only useless but also computationally expensive when knowing the most occurring labels. In this fix, the information of non-adjacent labels is not retained.
(Also, in the Stats.counts function, if the label value does not start from 1, the return array will start from the smallest label value. (For example. If the label is [2], the Stats.count function will return [1] instead of [0, 1].) This was causing a bug, which has also been fixed.)
I tried to benchmark before and after the change.
Before
After
Related issues
Checklist
test/...
test/runtests.jl
docs/src/...
.zenodo.json
I did not make any changes to the tests and document, because I did not change the function behavior.
Pinging
Pinging @tpoisot