[SciPy-user] call to vectorize works only after several calls

joep josef.pktd at gmail.com
Sat Oct 4 09:51:12 EDT 2008


I get some strange behavior, when vectorized function is called
without valid arguments:
The first time I call it, it throws an exception, if I call it again,
after I called a with a non-empyty argument list, then it works. I
don't see why the underlying state should have changed.

Any clues?
This makes testing and debugging pretty difficult

Josef

------------- file: test_ppf_indexerror.py ----------------------
from scipy import stats

print '\nfirst try'
try:
    print stats.foldcauchy.ppf(0,0.2)
except Exception,e:
    print 'error occured on first try'
    print e
print '\ncalling with vec arguments'
print stats.foldcauchy.ppf([-1,0.0, 0.1,0.9,1.0,2],0.2)
print '\nsecond try'
print stats.foldcauchy.ppf(0,0.2)
print ' second try worked'
------------------------------------------------

when called from command line, this produces (with trunk and scipy
0.6.0, numpy 1.2rc2):

{{{
>python test_ppf_indexerror.py

first try
error occured on first try
invalid index

calling with vec arguments
[        NaN  0.          0.16455889  6.31992596         Inf
NaN]

second try
0.0
 second try worked
}}}

Here is the traceback if I call it just once on the command line:

{{{
python -c "from scipy import stats;print stats.foldcauchy.ppf(0,0.2)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Josef\_progs\virtualpy25\envscipy\lib\site-packages\scipy
\stats\distr
ibutions.py", line 587, in ppf
    place(output,cond,self._ppf(*goodargs)*scale + loc)
  File "C:\Josef\_progs\virtualpy25\envscipy\lib\site-packages\scipy
\stats\distr
ibutions.py", line 399, in _ppf
    return self.vecfunc(q,*args)
  File "C:\Programs\Python25\Lib\site-packages\numpy\lib
\function_base.py", line
 1648, in __call__
    newargs.append(asarray(arg).flat[0])
IndexError: invalid index
}}}



More information about the SciPy-User mailing list