[Top][All Lists]

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

Re: [igraph] New user of igraph in C. Basic question about data importa

From: Gábor Csárdi
Subject: Re: [igraph] New user of igraph in C. Basic question about data importation
Date: Wed, 29 Apr 2009 09:27:51 +0200

On Wed, Apr 29, 2009 at 4:57 AM, Paul Johnson <address@hidden> wrote:
> Ach!   I still don't understand.
> How do I get a vector of reals into the adjlist vector neis?
> int M = 7;
> double edge[] = {1,2,3,4,5,7,8}

you really want to define the graph like this? I mean, hardwired into
the source code? I doubt it. Even you do, it does not work well in
practice, because it allocates memory on the stack, and the size of
the stack is limited.

> for (i=0; i<nodes; i++) {
>  igraph_vector_t *neis=igraph_adjlist_get(&myAList, i);
>  for (j=0; j <M; j++) {
>    igraph_vector_push_back(neis, edge[j] );
>  }
> }
> Inefficient, right?
> This calls the memory allocator 1 time for each individual item being added.

Actually it is not that inefficient, because it always allocates twice
as much memory as the current size of the vector. So the allocator is
called log(n) times for a vector of size n.

But you are right that it is better to use igraph_vector_update().

> I am looking for an igraph function with a declaration like
> int igraph_vector_real_copy(igraph_vector_t *v,
> real *data, long int length);

Yeah, but why don't you put your data immediately into 'v' instead of
putting it into 'data' and then copy it.


> pj
> --
> Paul E. Johnson
> Professor, Political Science
> 1541 Lilac Lane, Room 504
> University of Kansas
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help

Gabor Csardi <address@hidden>     UNIL DGM

reply via email to

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