[Numpy-tickets] [NumPy] #938: choose() much slower than in numarray
NumPy
numpy-tickets@scipy....
Sat Oct 18 01:48:19 CDT 2008
#938: choose() much slower than in numarray
------------------------+---------------------------------------------------
Reporter: smoerz | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone:
Component: numpy.core | Version: devel
Severity: normal | Keywords:
------------------------+---------------------------------------------------
choose is much slower in numpy than in numarray, and even more if an
output array is specified, as these tests show:
{{{
import timeit
setups = {
'numarray': """
import numarray as N
n1, n2 = 4, 1000000
a1 = N.arange(n1*n2, type='Float64', shape=(n1,n2))
a2 = -N.arange(n1*n2, type='Float64', shape=(n1,n2))
a3 = -N.arange(n1*n2, type='Float64', shape=(n1,n2))
b1 = N.arange(n2, type='Float64')
b2 = -N.arange(n2, type='Float64')
b3 = -N.arange(n2, type='Float64')
c = N.remainder(N.arange(n2, type='Int32'),2)
""",
'numpy': """
import numpy as N
n1, n2 = 4, 1000000
a1 = N.arange(n1*n2, dtype='Float64').reshape((n1,n2))
a2 = -N.arange(n1*n2, dtype='Float64').reshape((n1,n2))
a3 = -N.arange(n1*n2, dtype='Float64').reshape((n1,n2))
b1 = N.arange(n2, dtype='Float64')
b2 = -N.arange(n2, dtype='Float64')
b3 = -N.arange(n2, dtype='Float64')
c = N.remainder(N.arange(n2, dtype='Int32'),2)
"""
}
stmta = "N.choose(c, (a1, a2))"
stmtao = "N.choose(c, (a1, a2), a3)"
stmtb = "N.choose(c, (b1, b2))"
stmtbo = "N.choose(c, (b1, b2), b3)"
timeit.Timer(setup=setups['numarray'], stmt=stmta).repeat(3,100)
[3.3187780380249023, 3.2966721057891846, 3.3234250545501709]
timeit.Timer(setup=setups['numpy'], stmt=stmta).repeat(3,100)
[14.842453002929688, 14.833296060562134, 14.836632966995239]
timeit.Timer(setup=setups['numarray'], stmt=stmtao).repeat(3,100)
[3.1973719596862793, 3.2031948566436768, 3.2093629837036133]
timeit.Timer(setup=setups['numpy'], stmt=stmtao).repeat(3,100)
[17.546916007995605, 17.548220157623291, 17.536314010620117]
timeit.Timer(setup=setups['numarray'], stmt=stmtb).repeat(3,100)
[0.6694338321685791, 0.66939401626586914, 0.67307686805725098]
timeit.Timer(setup=setups['numpy'], stmt=stmtb).repeat(3,100)
[3.7615809440612793, 3.7627589702606201, 3.7547731399536133]
timeit.Timer(setup=setups['numarray'], stmt=stmtbo).repeat(3,100)
[0.67037606239318848, 0.67186903953552246, 0.66994881629943848]
timeit.Timer(setup=setups['numpy'], stmt=stmtbo).repeat(3,100)
[4.4750981330871582, 4.4650890827178955, 4.4679431915283203]
}}}
--
Ticket URL: <http://scipy.org/scipy/numpy/ticket/938>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list