[Scipy-tickets] [SciPy] #805: Faster implementation of argsreduce in scipy.stats.distributions

SciPy scipy-tickets@scipy....
Mon Dec 1 09:13:08 CST 2008


#805: Faster implementation of argsreduce in scipy.stats.distributions
-------------------------+--------------------------------------------------
 Reporter:  pbrod        |        Owner:  somebody
     Type:  enhancement  |       Status:  new     
 Priority:  normal       |    Milestone:  0.8     
Component:  scipy.stats  |      Version:  devel   
 Severity:  normal       |   Resolution:          
 Keywords:               |  
-------------------------+--------------------------------------------------
Comment (by pbrod):

 Replying to [comment:1 stefan]:
 > Thank you for optimising argsreduce.  Would you please add some tests,
 and reformat the docstring according to the NumPy docstring format?  As
 soon as that is done, we can merge the patch.  Thanks!

 Ok. Some test_runs of old implementation:
 {{{
 In [175]: A = np.ones((4,5))
 In [176]: timeit out = argsreduce(cond,A,A,A,A,A,A,A,A,A)
 1000 loops, best of 3: 214 µs per loop
 In [177]: timeit out = argsreduce(cond,A,A,A)
 10000 loops, best of 3: 77.9 µs per loop
 }}}

 compared to the new implementation

 {{{
 In [180]: timeit out = dst.argsreduce(cond,A,A,A,A,A,A,A,A,A)
 10000 loops, best of 3: 194 µs per loop
 In [181]: timeit out =dst.argsreduce(cond,A,A,A)
 10000 loops, best of 3: 70.7 µs per loop
 }}}

  Some tests of argsreduce is attached in the test_argsreduce.py file. My
 suggestion for a new doc-string for argsreduce is:
 {{{
     """
     Return the elements of each input array that satisfy some condition.

     Parameters
     ----------
     condition : array_like
         An array whose nonzero or True entries indicate the elements of
 each
         input array to extract. The shape of 'condition' must match the
 common
         shape of the input arrays according to the broadcasting rules in
 numpy.
     arg1, arg2, arg3, ... : array_like
         one or more input arrays.

     Returns
     -------
     narg1, narg2, narg3, ... : ndarray
         sequence of copies of the input arrays converted to the same size
 as the
         nonzero values of condition.

     Example
     -------
     >>> import numpy as np
     >>> rand = np.random.random_sample
     >>> A = rand((4,5))
     >>> B = 2
     >>> C = rand((1,5))
     >>> cond = np.ones(A.shape)
     >>> [A1,B1,C1] = argsreduce(cond,A,B,C)
     >>> B1.shape
     (20,)
     >>> cond[2,:] = 0
     >>> [A2,B2,C2] = argsreduce(cond,A,B,C)
     >>> B2.shape
     (15,)

     See also
     --------
     numpy.extract
     """
 }}}

-- 
Ticket URL: <http://scipy.org/scipy/scipy/ticket/805#comment:2>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list