Becksteinlab / kda

Python package used for the analysis of biochemical kinetic diagrams.
GNU General Public License v3.0
3 stars 1 forks source link

ENH: leverage `kda.diagrams.enumerate_partial_diagrams()` to preallocate arrays in `generate_partial_diagrams()` #39

Closed nawtrey closed 2 years ago

nawtrey commented 2 years ago

kda.diagrams.generate_partial_diagrams() currently appends the partial diagram edge lists to a list instead of filling in an array because it was previously difficult to quantify the number of partial diagrams/spanning trees that could be generated from an input diagram. This is now pretty simple to calculate with the addition of kda.diagrams.enumerate_partial_diagrams(), given the rate matrix is provided.

To conserve the current call signature for generate_partial_diagrams(), a call to kda.graph_utils.retrieve_rate_matrix() should suffice for retrieving the rate matrix. With this it should be possible to preallocate an array for the partial diagram edges, which should result in a reasonable speedup and a small reduction in spacial complexity. The final array should have the shape P x (N-1) x M, where P is the number of partial diagrams (calculated from enumerate_partial_diagrams()), N is the number of nodes in the input diagram, and M is the length of the edge tuples (2 or 3).

The returned edge list is already converted to an array, so this should be a pretty straight-forward change.