[Numpy-discussion] Problems with Numexpr and discontiguous arrays

Tim Hochberg tim.hochberg at ieee.org
Thu Oct 5 12:52:14 EDT 2006


Ivan Vilata i Balaguer wrote:
> En/na Tim Hochberg ha escrit::
>
>   
>> Ivan Vilata i Balaguer wrote:
>>     
>>> It seemed that discontiguous arrays worked OK in Numexpr since r1977 or
>>> so, but I have come across some alignment or striding problems which can
>>> be seen with the following code::
>>>       
>> I looked at this just a little bit and clearly this bit from interp_body 
>> cannot work in the presence of recor arrays:
>>
>> //....
>>         intp sf1 = sb1 / sizeof(double);        \
>> //...
>>         #define f1    ((double *)x1)[j*sf1]
>>
>> There are clearly some assumptions that sb1 is evenly divisible by 
>> sizeof(double). [...]
>>     
>
> I noticed something strange in those statements when implementing
> support for strings, and I must confess that I didn't grasp their
> meaning, so I implemented it a little differently for strings::
>
>     #define s1    ((char   *)x1 + j*params.memsteps[arg1])
>   
I believe that these approaches are the same as long as memstep is a 
multiple of itemsize. I chose the indexing rather than the pointer foo 
version[1] because there's a rumor that compilers will sometimes 
generate faster code for it. One additional potential slowdown in the 
above is the compiler may not be able to tell that memsteps[arg1]) is 
constant and may do that lookup repeatedly. Or maybe not, I try not to 
second guess compilers too much.

-tim



[1] I'm pretty sure I used the pointer foo version at least for a while. 
and may have gone back and forth several times.

> That seemed to work, but it might not be right (though I tested a bit),
> and certainly it may not be efficient enough.  Here you have my previous
> patches if you want to have a look at how I (try to) do it:
>
> 1.http://www.mail-archive.com/numpy-discussion%40lists.sourceforge.net/msg01551.html
> 2.http://www.mail-archive.com/numpy-discussion%40lists.sourceforge.net/msg02261.html
> 3.http://www.mail-archive.com/numpy-discussion%40lists.sourceforge.net/msg02644.html
>
> ::
>
> 	Ivan Vilata i Balaguer   >qo<   http://www.carabos.com/
> 	       Cárabos Coop. V.  V  V   Enjoy Data
> 	                          ""
>
>   
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> ------------------------------------------------------------------------
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>   






More information about the NumPy-Discussion mailing list