program attached Re: reference count problems

Tim Hochberg tim.hochberg at ieee.org
Wed Nov 15 16:15:18 CST 2006


Robert Kern wrote:
> Mathew Yeates wrote:
>
>   
>> def delta2day1(delta):
>>     return delta.days/365.0
>> deltas2days=numpy.frompyfunc(delta2day1,1,1)
>>     
>
> If I had to guess where the problem is, it's here. frompyfunc() and vectorize()
> have always been tricky beasts to get right.
>   
<curnudgen mode>

IMO, frompyfunc is an attractive nuisance. It doesn't magically make 
scalar Python functions fast, as people seem to assume, and it prevents 
people from figuring out how to write vectorized functions in the many 
cases where that's practicable. And it sounds like it may be buggy to boot.

In this case, I don't know that you can easily vectorize this by hand, 
but there are many ways that it could be rewritten to avoid frompyfunc. 
For example:

    def deltas2days(seq):
        return numpy.fromter((x.days for x in seq), dtype=float,
    count=len(seq))

One line shorter, about equally opaque and less likely to have 
mysterious bugs.

</curmudgen mode>

-tim


-------------------------------------------------------------------------
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




More information about the Numpy-discussion mailing list