Group Abstract Group Abstract

Message Boards Message Boards

0
|
7K Views
|
4 Replies
|
5 Total Likes
View groups...
Share
Share this post:

[?] Replace AppendTo with usage of Reap Sow?

Posted 9 years ago
4 Replies

Justin,

I would think that Map might be faster:

s35vertlist = Map[VertexDegree[Subgraph[s35, #]] &, cyclelists35]

Sow works like this -- you don't append to the list -- it just collects the values. I do not recommend this in your case because you want a value returned for every element in your cyclelist

s35vertlist = 
 Reap[Do[Sow[VertexDegree[Subgraph[s35, cyclelists35[[i]]]]], {i, 
    Length[cyclelists35]}]]

Try doing an AbsoluteTiming[] for your loop and the Map and post the times. I am guessing that the Map is faster.

Regards

POSTED BY: Neil Singer

You don't need Sow/Reap here:

s35vertlist =  Table[VertexDegree[Subgraph[s35, cyclelists35[[i]]]], {i,    Length[cyclelists35]}]

should do, or

s35vertlist = VertexDegree[Subgraph[s35, #]] & /@ cyclelists35

With respect to a functional style, maybe there is something graph specific which could make it even better but that is not my area.

POSTED BY: Kuba Podkalicki

Sorry, Crossed with Kuda's post at the same time... I would also time Kuda's table approach to see if it is faster than the loop and/or the Map. Curious to know which is faster.

(Also, if you compile the function you will probably get a significant speedup with any of the approaches)

POSTED BY: Neil Singer

Wow. I am so glad I posted this question. All three solutions worked much faster than my original part. The first Table implementation took 65.9754. The second that uses some mapping code I don't understand took 64.1661. And the One that uses the Map function name took 63.4734! Thank you both for you help. I will try to read more about Table and Map since I didn't understand how to use them before.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard