[SciPy-User] optimising python numpy snippet

Sai Rajeshwar rajsai24 at gmail.com
Fri Jul 25 00:58:22 EDT 2014


thanks eric..  few queries
1)  these vector operations are possible only because of numpy,?
2) is the optimisation you have suugested a kind of loop unrolling..
3)does the above optimisation uses SIMD internally

thanks


*with regards..*

*M. Sai Rajeswar*
*M-tech  Computer Technology*


*IIT Delhi----------------------------------Cogito Ergo Sum---------*


On Fri, Jul 25, 2014 at 12:07 AM, Eric Hermes <ehermes at chem.wisc.edu> wrote:

>  Hello,
>
> A quick and dirty simplification may end up in a bit of a speed boost. You
> can eliminate some of the loops and replace them with vector operations, as
> below.
>
>
> for k in xrange(self.pooled_shape[3]):
>     for l in xrange(self.pooled_shape[4]):
>         self.pooled[0, :, :, k, l] = numpy.tanh(self.conv_out[0, :, :,
> k*3:(k+1)*3, l*3:(l+1)*3].sum((2, 3))/9. + self.b[:, :])
>
> I have left in some extraneous slices (:) for clarity of code.
>
> Eric
>
>
> On 7/24/2014 12:40 PM, Sai Rajeshwar wrote:
>
>  hi all,
>
>    I have written the following for loop statement inn my code..  when i
> profiled it.. i found that it is taking huge amount of time..  can any one
> suggest to make this statement faster
>
> ----------------------------------------------------------------------------
>
> f
>
>
>
> *or i in xrange(self.pooled_shape[1]):             for j in
> xrange(self.pooled_shape[2]):                 for k in
> xrange(self.pooled_shape[3]):                     for l in
> xrange(self.pooled_shape[4]):
> self.pooled[0][i][j][k][l]=math.tanh((numpy.sum(self.conv_out[0][i][j][k*3][l*3:(l+1)*3])+numpy.sum(self.conv_out[0][i][j][k*3+1][l*3:(l+1)*3])+numpy.sum(self.conv_out[0][i][j][k*3+2][l*3:(l+1)*3]))/9.0+self.b[i][j])*
>
>  thanks a lot in advance
>
>
>  *with regards..*
>
>  *M. Sai Rajeswar*
> *M-tech  Computer Technology*
>
>
> *IIT Delhi ----------------------------------Cogito Ergo Sum--------- *
>
>
> _______________________________________________
> SciPy-User mailing listSciPy-User at scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-user
>
>
> --
> Eric Hermes
> J.R. Schmidt Group
> Chemistry Department
> University of Wisconsin - Madison
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20140725/d776155c/attachment.html>


More information about the SciPy-User mailing list