[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] igraph_spmatrix_t and graphs

From: Tamas Nepusz
Subject: Re: [igraph] igraph_spmatrix_t and graphs
Date: Fri, 05 Aug 2011 16:37:21 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110617 Lightning/1.0b2 Thunderbird/3.1.11

Dear Oscar,

igraph_spmatrix_t is more like an internal datatype than a full-fledged
sparse matrix type, so not all operations are supported or documented; for
instance, there is no simple one-function call to construct a graph from an

One thing that is not documented but may be useful for you is an auxiliary
data type called igraph_spmatrix_iter_t, which is an iterator over the
possibly non-zero entries of the sparse matrix. You can use an
igraph_spmatrix_iter_t to construct an edge list and a corresponding weight
vector on the fly, then create an igraph_t out of the edge list, and assign
the weights as edge attributes. These are the igraph_spmatrix_* functions
from the header:

int igraph_spmatrix_iter_create(igraph_spmatrix_iter_t *mit, const
igraph_spmatrix_t *m);
int igraph_spmatrix_iter_reset(igraph_spmatrix_iter_t *mit);
int igraph_spmatrix_iter_next(igraph_spmatrix_iter_t *mit);
igraph_bool_t igraph_spmatrix_iter_end(igraph_spmatrix_iter_t *mit);
void igraph_spmatrix_iter_destroy(igraph_spmatrix_iter_t *mit);

So, first you create an iterator using igraph_spmatrix_iter_create, then
step over the elements one by one using igraph_spmatrix_iter_next, and check
whether you are at the end of the matrix using igraph_spmatrix_iter_end.
Finally, you destroy the iterator using igraph_spmatrix_iter_destroy. At any
stage, you can look up the current row index, column index and value using
the "ri", "ci" and "value" members of the iterator.


On 08/05/2011 04:20 PM, Oscar Cuadros Linares wrote:
> Dear Igraph users.
> I want to create a graph from a sparse matrix (igraph_spmatrix_t), but i 
> can't. 
> sugestions?
> Thanks.
> Oscar
> -- 
> En Cristo y María
> Oscar Cuadros Linares
> Ciencia de la Computación
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help

reply via email to

[Prev in Thread] Current Thread [Next in Thread]