<br><br><div class="gmail_quote">On Sun, May 31, 2009 at 9:08 PM, David Cournapeau <span dir="ltr"><<a href="mailto:david@ar.media.kyoto-u.ac.jp" target="_blank">david@ar.media.kyoto-u.ac.jp</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>Charles R Harris wrote:<br>
><br>
><br>
> On Sun, May 31, 2009 at 7:18 PM, David Cournapeau<br>
</div>> <<a href="mailto:david@ar.media.kyoto-u.ac.jp" target="_blank">david@ar.media.kyoto-u.ac.jp</a> <mailto:<a href="mailto:david@ar.media.kyoto-u.ac.jp" target="_blank">david@ar.media.kyoto-u.ac.jp</a>>><br>
<div>> wrote:<br>
><br>
> Charles R Harris wrote:<br>
> ><br>
> ><br>
> > On Sun, May 31, 2009 at 11:54 AM, rob steed <<a href="mailto:rjsteed@talk21.com" target="_blank">rjsteed@talk21.com</a><br>
> <mailto:<a href="mailto:rjsteed@talk21.com" target="_blank">rjsteed@talk21.com</a>><br>
</div><div><div></div><div>> > <mailto:<a href="mailto:rjsteed@talk21.com" target="_blank">rjsteed@talk21.com</a> <mailto:<a href="mailto:rjsteed@talk21.com" target="_blank">rjsteed@talk21.com</a>>>> wrote:<br>
> ><br>
> ><br>
> > Hi,<br>
> > After my previous email, I have opened a ticket #1117 (correlate<br>
> > not order dependent)<br>
> ><br>
> > I have found that the correlate function is defined in<br>
> > multiarraymodule.c and<br>
> > that inputs are being swapped using the following code<br>
> ><br>
> > n1 = ap1->dimensions[0];<br>
> > n2 = ap2->dimensions[0];<br>
> > if (n1 < n2) {<br>
> > ret = ap1;<br>
> > ap1 = ap2;<br>
> > ap2 = ret;<br>
> > ret = NULL;<br>
> > i = n1;<br>
> > n1 = n2;<br>
> > n2 = i;<br>
> > }<br>
> ><br>
> > I do not know the code well enough to see whether this could<br>
> just<br>
> > be removed (I don't know c either).<br>
> > Maybe the algorithmn requires the inputs to be length ordered? I<br>
> > will try to work it out.<br>
> ><br>
> ><br>
> > If the correlation algorithm doesn't use an fft and is done<br>
> > explicitly, then the maximum overlap for any shift is the length of<br>
> > the shortest input. Swapping the arrays makes that logic easier to<br>
> > implement, but it isn't necessary.<br>
><br>
> But this logic is also wrong if the swapping is not taken into<br>
> account -<br>
> as the OP mentioned, correlate(a, b) is not equal to correlate(b,<br>
> a) in<br>
> the general case. The output is reversed in the second case<br>
> compared to<br>
> the first case.<br>
><br>
><br>
> I didn't say it was *correctly* implemented ;)<br>
<br>
</div></div>:) So I gave it a shot<br>
<br>
<a href="http://github.com/cournape/numpy/commits/fix_correlate" target="_blank">http://github.com/cournape/numpy/commits/fix_correlate</a><br>
<br>
(It took me a while to realize that PyArray_ISFLEXIBLE returns false for<br>
array object. Is this expected ? The documentation concerning copyswap<br>
says that it is necessary for flexible arrays, but I think it is<br>
necessary for object arrays as well).<br>
</blockquote><div><br>Don't know. PyArray_ISFLEXIBLE looks like a macro... <br><br>#define PyArray_ISFLEXIBLE(obj) PyTypeNum_ISFLEXIBLE(PyArray_TYPE(obj))<br><br>#define PyTypeNum_ISFLEXIBLE(type) (((type) >=NPY_STRING) && \<br>
((type) <=NPY_VOID))<br><br>And the typecodes are '?bhilqpBHILQPfdgFDGSUVO'. So 'SUV' are flexible and O is not. I'm not clear on how correlate should apply to any of 'SUV' but it might be worth having it work for objects.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
It still bothers me that correlate does not conjugate the second<br>
argument for complex arrays...<br>
<div><div></div><div></div></div></blockquote><div><br>It bothers me also... Chuck <br></div><br></div><br>