Re: improving a huge double-for cycle

2008-09-23 Thread km
how abt this ? N = len(IN) for k in range(N): for j in range(N): if j = k: # or k = j doSomething() KM ~~~ On Thu, Sep 18, 2008 at 6:27 PM, Tim Chase [EMAIL PROTECTED]wrote: Code: Select all for i in range(len(IN)): #scan all elements of

Re: improving a huge double-for cycle

2008-09-23 Thread Tim Chase
km wrote: how abt this ? N = len(IN) for k in range(N): for j in range(N): if j = k: # or k = j doSomething() This has the root problem that the if statement is evaluated N*N times, which is ugly/slow O(N^2) behavior. My solution managed to reduce

Re: improving a huge double-for cycle

2008-09-20 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : On Thu, 18 Sep 2008 20:43:00 +0200, Bruno Desthuilliers wrote: Now the obvious winner is pruebono - even unoptimized, using sets seems to be *way* faster than even the most optimized corrected version of your algorithm. I'm not being snarky about losing priority

Re: improving a huge double-for cycle

2008-09-20 Thread Bruno Desthuilliers
Bruno Desthuilliers a écrit : Alexzive a écrit : Hello there :) , (snip) Now the obvious winner is pruebono Correction (my bad) : Steven D'Aprano submitted the set-based solution first. So the winners are Steven and pruebono. -- http://mail.python.org/mailman/listinfo/python-list

Re: improving a huge double-for cycle

2008-09-20 Thread Bruno Desthuilliers
Harald Luessen a écrit : On Thu, 18 Sep 2008 Bruno Desthuilliers wrote: # Harald : uncomment this and run test_results. As far as I can tell, it # doesn't yields the expected results ## IN7 = IN[:] ## def sortk7(n): ## return n.coordinates[0] ## def doubles7(): ## is ordering better

Re: improving a huge double-for cycle

2008-09-20 Thread Steven D'Aprano
On Sat, 20 Sep 2008 19:01:42 +0200, Bruno Desthuilliers wrote: Once again, sorry if me missing your correct answer drives you paranoid :-) What do you mean by that? How many other people have been talking about me? *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: improving a huge double-for cycle

2008-09-20 Thread Aaron Castironpi Brady
On Sep 20, 9:20 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sat, 20 Sep 2008 19:01:42 +0200, Bruno Desthuilliers wrote: Once again, sorry if me missing your correct answer drives you paranoid :-) What do you mean by that? How many other people have been talking about

Re: improving a huge double-for cycle

2008-09-19 Thread Alex Ziller
Thank you all for replying me! special thanks to Tino. Your code rocks! I got all the double nodes in couple of seconds and in a useful output with the coupled nodes pro line.. cheers from Germany! 2008/9/18 Tino Wildenhain [EMAIL PROTECTED] Tino Wildenhain wrote: Hi,

Re: improving a huge double-for cycle

2008-09-19 Thread Gabriel Genellina
En Fri, 19 Sep 2008 02:11:51 -0300, Tino Wildenhain [EMAIL PROTECTED] escribió: Also I never saw a list where the threading often goes wrong like this here - is there any special setup or is it just peoples MUA which screws up? Perhaps it's due to the newsgroup/list duality... -- Gabriel

Re: improving a huge double-for cycle

2008-09-19 Thread Jake Anderson
Bruno Desthuilliers wrote: Alexzive a écrit : Hello there :) , I am a python newbie and need to run following code for a task in an external simulation programm called Abaqus which makes use of python to access the mesh (ensamble of nodes with xy coordinates) of a certain geometrical model.

Re: improving a huge double-for cycle

2008-09-19 Thread giltay
On Sep 18, 7:42 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: I'm not being snarky about losing priority here, but I submitted essentially the same solution two hours earlier than pruebono. My apologies (seriosuly). In this case, I think it might just be haste. For what it's

Re: improving a huge double-for cycle

2008-09-19 Thread Harald Luessen
On Thu, 18 Sep 2008 Bruno Desthuilliers wrote: # Harald : uncomment this and run test_results. As far as I can tell, it # doesn't yields the expected results ## IN7 = IN[:] ## def sortk7(n): ## return n.coordinates[0] ## def doubles7(): ## is ordering better ? - Nope Sir, it's broken...

Re: improving a huge double-for cycle

2008-09-19 Thread pruebauno
On Sep 18, 7:42 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Thu, 18 Sep 2008 20:43:00 +0200, Bruno Desthuilliers wrote: Now the obvious winner is pruebono - even unoptimized, using sets seems to be *way* faster than even the most optimized corrected version of your

Re: improving a huge double-for cycle

2008-09-19 Thread Terry Reedy
Gabriel Genellina wrote: En Fri, 19 Sep 2008 02:11:51 -0300, Tino Wildenhain [EMAIL PROTECTED] escribió: Also I never saw a list where the threading often goes wrong like this here - is there any special setup or is it just peoples MUA which screws up? Perhaps it's due to the newsgroup/list

improving a huge double-for cycle

2008-09-18 Thread Alexzive
Hello there :) , I am a python newbie and need to run following code for a task in an external simulation programm called Abaqus which makes use of python to access the mesh (ensamble of nodes with xy coordinates) of a certain geometrical model. [IN is the starting input containing the nodes to

Re: improving a huge double-for cycle

2008-09-18 Thread skip
Alex Unfortunately my len(IN) is about 100.000 and the running time Alex about 15h :( Alex Any idea to improve it? numpy? http://numpy.scipy.org/ http://www.scipy.org/Numpy_Example_List More immediately, note that you are building a list of len(IN) ints every time

Re: improving a huge double-for cycle

2008-09-18 Thread Peter Otten
Alexzive wrote: Hello there :) , I am a python newbie and need to run following code for a task in an external simulation programm called Abaqus which makes use of python to access the mesh (ensamble of nodes with xy coordinates) of a certain geometrical model. [IN is the starting input

Re: improving a huge double-for cycle

2008-09-18 Thread Tim Chase
Code: Select all for i in range(len(IN)): #scan all elements of the list IN for j in range(len(IN)): if i j: if IN[i].coordinates[0] == IN[j].coordinates[0]: if IN[i].coordinates[1] == IN[j].coordinates[1]: SN.append(IN[i].label)

Re: improving a huge double-for cycle

2008-09-18 Thread bearophileHUGS
Skip: indexes = range(len(IN)) for i in indexes: #scan all elements of the list IN for j in indexes: Nope, use xrange in both situations, and save a list. Tim Chase: for i in xrange(len(IN)): for j in xrange(i+1, len(IN)): if IN[i].coordinates ==

Re: improving a huge double-for cycle

2008-09-18 Thread Steven D'Aprano
On Thu, 18 Sep 2008 05:25:02 -0700, Alexzive wrote: Hello there :) , I am a python newbie and need to run following code for a task in an external simulation programm called Abaqus which makes use of python to access the mesh (ensamble of nodes with xy coordinates) of a certain geometrical

Re: improving a huge double-for cycle

2008-09-18 Thread Tim Chase
Tim Chase: for i in xrange(len(IN)): for j in xrange(i+1, len(IN)): if IN[i].coordinates == IN[j].coordinates: SN.append(IN[i].label) If my college algorithms memory serves me sufficiently, this reduces your O(N^2) to O(N log N) which will garner you some decent time

Re: improving a huge double-for cycle

2008-09-18 Thread J. Cliff Dyer
On Thu, 2008-09-18 at 07:57 -0500, Tim Chase wrote: Code: Select all for i in range(len(IN)): #scan all elements of the list IN for j in range(len(IN)): if i j: if IN[i].coordinates[0] == IN[j].coordinates[0]: if IN[i].coordinates[1] ==

Re: improving a huge double-for cycle

2008-09-18 Thread pruebauno
On Sep 18, 8:25 am, Alexzive [EMAIL PROTECTED] wrote: Hello there :) , I am a python newbie and need to run following code for a task in an external simulation programm called Abaqus which makes use of python to access the mesh (ensamble of nodes with xy coordinates) of a certain geometrical

Re: improving a huge double-for cycle

2008-09-18 Thread Jake Anderson
psyco might help a fair bit (10x-40x) here ;- perhaps look at dumping the data into sqlite then pulling it back out. It (or the other databases) are designed for tossing around large lumps of data. Alexzive wrote: Hello there :) , I am a python newbie and need to run following code for a

Re: improving a huge double-for cycle

2008-09-18 Thread Tino Wildenhain
Hi, Alexzive wrote: Hello there :) , I am a python newbie and need to run following code for a task in an external simulation programm called Abaqus which makes use of python to access the mesh (ensamble of nodes with xy coordinates) of a certain geometrical model. [IN is the starting input

Re: improving a huge double-for cycle

2008-09-18 Thread Tino Wildenhain
Tino Wildenhain wrote: Hi, Alexzive wrote: Hello there :) , I am a python newbie and need to run following code for a task in an external simulation programm called Abaqus which makes use of python to access the mesh (ensamble of nodes with xy coordinates) of a certain geometrical model. [IN

Re: improving a huge double-for cycle

2008-09-18 Thread giltay
On Sep 18, 11:18 am, [EMAIL PROTECTED] wrote: dup=set() SN=[] for item in IN:    c=item.coordinates[0], item.coordinates[1]    if c in dup:       SN.append(item.label)    else:       dup.add(c) +1 for O(N) If item.coordinates is just an (x, y) pair, you can skip building c and save a

Re: improving a huge double-for cycle

2008-09-18 Thread Harald Luessen
On Thu, 18 Sep 2008 Alexzive wrote: I am a python newbie and need to run following code for a task in an external simulation programm called Abaqus which makes use of python to access the mesh (ensamble of nodes with xy coordinates) of a certain geometrical model. [IN is the starting input

Re: improving a huge double-for cycle

2008-09-18 Thread Paul Hankin
On Sep 18, 2:25 pm, Alexzive [EMAIL PROTECTED] wrote: Hello there :) , I am a python newbie and need to run following code for a task in an external simulation programm called Abaqus which makes use of python to access the mesh (ensamble of nodes with xy coordinates) of a certain geometrical

Re: improving a huge double-for cycle

2008-09-18 Thread Paul Hankin
On Sep 18, 2:25 pm, Alexzive [EMAIL PROTECTED] wrote: Hello there :) , I am a python newbie and need to run following code for a task in an external simulation programm called Abaqus which makes use of python to access the mesh (ensamble of nodes with xy coordinates) of a certain geometrical

Re: improving a huge double-for cycle

2008-09-18 Thread Bruno Desthuilliers
Harald Luessen a écrit : (snip) I did not test the syntax, but here is an idea with sorted lists. It should be O(NlogN). def sk(x): return x.coordinates[0] IN.sort(key=sk) for i in xrange(len(IN)): for j in xrange(i+1, len(IN)): if IN[i].coordinates[0] == IN[j].coordinates[0]:

Re: improving a huge double-for cycle

2008-09-18 Thread Bruno Desthuilliers
Alexzive a écrit : Hello there :) , I am a python newbie and need to run following code for a task in an external simulation programm called Abaqus which makes use of python to access the mesh (ensamble of nodes with xy coordinates) of a certain geometrical model. [IN is the starting input

Re: improving a huge double-for cycle

2008-09-18 Thread bearophileHUGS
Bruno Desthuilliers: def doubles9(): ... SN = [] sn_append = SN.append Few more: import psyco def doubles10(): dup = set() SN = [] for item in IN: c = item.coordinates if c in dup: SN.append(item) else: dup.add(c)

Re: improving a huge double-for cycle

2008-09-18 Thread Steven D'Aprano
On Thu, 18 Sep 2008 20:43:00 +0200, Bruno Desthuilliers wrote: Now the obvious winner is pruebono - even unoptimized, using sets seems to be *way* faster than even the most optimized corrected version of your algorithm. I'm not being snarky about losing priority here, but I submitted

Re: improving a huge double-for cycle

2008-09-18 Thread bearophileHUGS
bearophile: doubles12 : 0.00184026840268 For fun, and to have an almost baseline reference, I have done a little benchmark in D too: import std.stdio: writefln; // Using Tango std lib you don't need all this version (Win32) { import std.c.windows.windows; double clock() { long

Re: improving a huge double-for cycle

2008-09-18 Thread Terry Reedy
Steven D'Aprano wrote: On Thu, 18 Sep 2008 20:43:00 +0200, Bruno Desthuilliers wrote: Now the obvious winner is pruebono - even unoptimized, using sets seems to be *way* faster than even the most optimized corrected version of your algorithm. I'm not being snarky about losing priority here,

Re: improving a huge double-for cycle

2008-09-18 Thread Tino Wildenhain
Hi, Terry Reedy wrote: ... Yes, after figuring out what to do from the original post, I saw yours and then Pruebono's and decided that since two people had submitted the jackpot algorithm, I need not say more. I will say this: this solution amounts to finding equivalence classes (the sets of