[Numpy-discussion] Numpy performance vs Matlab.
Nicolas ROUX
nicolas.roux@st....
Fri Jan 9 06:04:36 CST 2009
Hi !
Thanks a lot for your fast/detailed reply.
A very good point for Numpy ;-)
I spent all my time trying to prepare my testcase to better share with you,
that's why I didn't reply fast.
I understand the weakness of the missing JITcompiler in Python vs Matlab,
that's why I invistigated numpy vectorization/broadcast.
(hoping to find a cool way to write our code in fast Numpy)
I used the page http://www.scipy.org/PerformancePython to write my code
efficiently in Numpy.
While doing it I found one issue.
To have pretty code, I created p0 and p1 arrays of indexes.
In "test8" I wished to see the commented line working, which is not the
case.
Having to use "ix_" is not pretty enough, and seems to not work with further
dimensions.
Why the comment line is not working ?
############################################
def test8():
m = 1024
n = 512
Out = numpy.zeros((m,n))
In = numpy.zeros((m,n))
p0 = numpy.ogrid[0:m]
p1 = numpy.ogrid[0:n]
Out[0:m,0:n] = In[0:m,0:n]
#Out[p0,p1] = In[p0,p1] #This doesn't work
Out[numpy.ix_(p0,p1)] = In[numpy.ix_(p0,p1)]
############################################
What is maybe not clear in the above code, is that I don't want to predefine
all possible ogrid/vector.
The number of possible ogrid/vector is big if in need to define all.
... And this vector definition become more paintful.
So Numpy vector style is fine if i can write something like:
Out[p0,p1] = In[p0,p1] #2 dimensions case
And
Out[p0,p1,1] = In[p0,p1,1] #3 dimensions case
But is not fine if i have to add ".ix_()" or to multiply the number of
vector definitions.
Below example with 3 dimensions instead of 2.
############################################
def test9():
m = 1024
n = 512
Out = numpy.zeros((m,n,3))
In = numpy.zeros((m,n,3))
p0 = numpy.ogrid[0:m]
p1 = numpy.ogrid[0:n]
Out[0:m,0:n,2] = In[0:m,0:n,2]
#Out[p0,p1,2] = In[p0,p1,2]
Out[numpy.ix_(p0,p1,2)] = In[numpy.ix_(p0,p1,2)]
############################################
Tanks again for your support ;-)
Cheers,
Nicolas.
More information about the Numpy-discussion
mailing list