[Top][All Lists]

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

Re: [igraph] Speed comparison of R and C

From: Tamás Nepusz
Subject: Re: [igraph] Speed comparison of R and C
Date: Tue, 8 Feb 2011 21:25:11 +0100


Here's an explanation about what's going on behind the scenes. Basically, g <- 
set.edge.attribute(g, "cap", index=x, value=x) makes a *copy* of the graph 
object in every iteration of the for loop; set.edge.attribute always copies the 
graph first, applies the modification to the copy and assigns it back to g. I 
conjecture that this operation causes most of the overhead. As I'm not too 
familiar with R, I don't know why it works this way -- maybe Gabor can shed 
light on it.

However, depending on your use-case, there might be more efficient ways of 
doing things in R. For instance, your current for loop basically retrieves an 
edge attribute once for every edge. Instead of that, you could simply write 
E(g)$load to retrieve the values of the "load" edge attribute for all the edges 
at once, and this is much faster.  Similarly, you can use E(g)$cap <- 
capacities to assign to all the edge attributes at once, and this is also much 


On 8 Feb 2011, at 20:38, William Tu wrote:

> Sorry guys,
> My updated rw_speed.R.
> William
> On Tue, Feb 8, 2011 at 2:24 PM, William Tu <address@hidden> wrote:
>> Hi Tamas,
>> Thanks for all the advices. I've attached my C and R code.
>> btw, is this the correct way to reply to the mailing list? I click the
>> "reply via email to" button below the discussion page.
>> William
> <rw_speed.R>

reply via email to

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