<div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>> For instance<br>><br>> In [7]: def countmembers(a1, a2) :<br>>   ...:     a = sort(a2)
<br>>   ...:     il = a.searchsorted(a1, side='l')<br>>   ...:     ir = a.searchsorted(a1, side='r')<br>>   ...:     return ir - il<br>>   ...:<br>><br>> In [8]: a2 = random.randint(0,10,(100,))
<br>><br>> In [9]: a1 = arange(11)<br>><br>> In [11]: a2 = random.randint(0,5,(100,))<br>><br>> In [12]: a1 = arange(10)<br>><br>> In [13]: countmembers(a1,a2)<br>> Out[13]: array([16, 28, 16, 25, 15,  0,  0,  0,  0,  0])
<br>><br>><br>> The subtraction can be replaced by != to get a boolean mask.<br><br>It looks good! Isn't it faster than setmember1d for unique input arrays?<br>I do not like setmember1d much (it is long unlike other functions in
<br>arraysetops and looks clumsy to me now and I do not understand it<br>anymore...), so feel free to replace it.<br><br>BTW. setmember1d gives me the same mask as countmembers for several<br>non-unique inputs I tried...<br>
<br>r.</blockquote><div><br>Try this, then:<br>countmembers(N.array([1,1]), N.array([2]))<br>array([0, 0])<br>N.setmember1d(N.array([1,1]), N.array([2]))<br>array([ True, False], dtype=bool)<br><br>setmember1d really needs the first array to be unique. I thought about it quite a bit and tried to understand the code (which is no small feat and I don't claim I have succeeded).
<br>As far as I can tell, setmember1d gets it right for the duplicate element with the highest index, all other duplicates are found to be in the second array, independent of whether or not that's actually true.<br><br>
I found it easier to state my problem in terms of unique arrays rather than trying to figure out a general solution, but countmembers sure is nice.<br><br>    Jan<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
---------- Forwarded message ----------<br>From: Robert Cimrman <<a href="mailto:cimrman3@ntc.zcu.cz">cimrman3@ntc.zcu.cz</a>><br>To: Discussion of Numerical Python <<a href="mailto:numpy-discussion@scipy.org">numpy-discussion@scipy.org
</a>><br>Date: Thu, 25 Jan 2007 12:35:10 +0100<br>Subject: Re: [Numpy-discussion] setmember1d memory leak?<br>Robert Cimrman wrote:<br>> Charles R Harris wrote:<br>>><br>>> In [7]: def countmembers(a1, a2) :
<br>>>   ...:     a = sort(a2)<br>>>   ...:     il = a.searchsorted(a1, side='l')<br>>>   ...:     ir = a.searchsorted(a1, side='r')<br>>>   ...:     return ir - il<br>>>   ...:
<br>>> The subtraction can be replaced by != to get a boolean mask.<br>><br>> It looks good! Isn't it faster than setmember1d for unique input arrays?<br>> I do not like setmember1d much (it is long unlike other functions in
<br>> arraysetops and looks clumsy to me now and I do not understand it<br>> anymore...), so feel free to replace it.<br>><br>> BTW. setmember1d gives me the same mask as countmembers for several<br>> non-unique inputs I tried...
<br><br>But still a function like 'findsorted' returning a bool mask would be<br>handy - one searchsorted-like call could be saved in setmember1d.<br><br>cheers,<br>r.<br><br><br><br><br>---------- Forwarded message ----------
<br>From: rex <<a href="mailto:rex@nosyntax.com">rex@nosyntax.com</a>><br>To: Discussion of Numerical Python <<a href="mailto:numpy-discussion@scipy.org">numpy-discussion@scipy.org</a>><br>Date: Thu, 25 Jan 2007 03:50:24 -0800
<br>Subject: [Numpy-discussion] Compiling Python with icc<br>George Nurser <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:gnurser@googlemail.com">gnurser@googlemail.com</a>> [2007-01-25 02:05]:
<br><br>> Perhaps compiling python itself with icc might give a useful speedup.<br>> Apparently somebody managed this for python 2.3 in 2003:<br>> <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.python.org/pipermail/c++-sig/2003-October/005824.html" target="_blank">
http://mail.python.org/pipermail/c++-sig/2003-October/005824.html</a><br><br>Hello George,<br><br>I saw that post yesterday, and just got around to trying it. It works.<br><br>./configure CC=icc --prefix=/usr/local<br><br>
In addition to commenting out<br><br>#BASECFLAGS=     -OPT:Olimit=0<br><br>I added<br><br>-xT -parallel<br><br>to the<br><br>OPT=<br><br>line for my Core 2 Duo CPU. The usual Make, Make install worked, and<br>pybench now runs in 
3.15 seconds vs 4.7 seconds with Python2.5 compiled<br>with gcc. That's a 49% speed increase.<br><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://svn.python.org/projects/external/pybench-2.0/" target="_blank">
http://svn.python.org/projects/external/pybench-2.0/</a><br><br>And, if psyco is used, pybench runs in 1.6 seconds for one iteration and<br>then crashes. Psyco + icc results in a ~300% speed increase. Pybench<br>needs to be updated for 1+ gigaflop systems.
<br><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://psyco.sourceforge.net/" target="_blank">http://psyco.sourceforge.net/</a><br><br>-rex<br>--<br>"I have always wished that my computer would be as easy to use as my
<br>telephone. My wish has come true. I no longer know how to use my telephone"<br>    --Bjorne Stroustrup (originator of C++ programming language)<br><br><br><br><br>_______________________________________________<br>
Numpy-discussion mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Numpy-discussion@scipy.org">Numpy-discussion@scipy.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://projects.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">
http://projects.scipy.org/mailman/listinfo/numpy-discussion</a><br><br><br></blockquote></div><br>