ZigRazor / CXXGraph

Header-Only C++ Library for Graph Representation and Algorithms
https://zigrazor.github.io/CXXGraph/
Mozilla Public License 2.0
425 stars 106 forks source link

Provide functions for exporting matrices as sequential data types #454

Open sbaldu opened 2 weeks ago

sbaldu commented 2 weeks ago

We currently define the adjacency matrix (and all other matrices) as hash maps, and this is the most optimal choice, but I was thinking that it would be useful to provide some functions for exporting those matrices as more standard sequential data structure (linearized vector, vector of vector, Eigen matrix, ecc.). This would be useful for example if a user wants to draw a heat map for those matrices. We could easily implement this with a template function specialized for each data type we want to support. Furthermore, one might want to do some calculations with those matrices, and in that case a sequential data structure would be better because it would grant locality (this would be critical if the calculation is run on a GPU)

Example:

...
CXX::Graph<int> graph(edgeSet);
auto adj1 = export<std::vector<int>>(graph.getAdjMatrix());
auto adj2 = export<std::vector<std::vector<int>>>(graph.getAdjMatrix());
auto adj3 = export<Eigen::Matrix<int>>(graph.getAdjMatrix());
...

It could be a free function, a Graph method or both.

Wdyt @ZigRazor @nolankramer?

ZigRazor commented 2 weeks ago

yes, good idea!