[Tutor] improving speed using and recalling C functions

Gabriele Brambilla gb.gabrielebrambilla at gmail.com
Fri Apr 11 15:56:54 CEST 2014


Hi, I'm sorry but there is a big problem.
the code is producing empty file.dat.

I think it's because of this that previously I have done that strange trick
of myinternet...

So:

for my_line in open('data.dat'):

                myinternet = []

                gmlis = []

                print('reading the line', count, '/599378')

                my_parts = [float(i) for i in my_line.split()]

                phase = my_parts[4]

                zobs = my_parts[5]

                rho = my_parts[6]



                gmils=[my_parts[7], my_parts[8], my_parts[9], my_parts[10],
my_parts[11]]



                i = int((phase-phamin)/stepPHA)

                j = int((zobs-obamin)/stepOB)



                for gammar, MYMAP in zip(gmlis, MYMAPS):



                        omC = (1.5)*(gammar**3)*c/(rho*rlc)

                        gig = omC*hcut/eVtoErg

                #check the single emission



                        for w in eel:

                                omega =
(10**(w*stepENE+Lemin))*eVtoErg/hcut

                                x = omega/omC

                                kap = instruments.kappa(x)

                                Iom = (1.732050808/c)*(e**2)*gammar*kap
#jackson dI/domega

                                P = Iom*(c/(rho*rlc))/(2*pi) #jackson P

                                phps = P/(hcut*omega) #photons per second

                                www =  phps/(stepPHA*sin(zobs)*stepOB)

                                MYMAP[i,j,w] += www



                count = count + 1

when I exit here the MYMAP matrix has all the cells = 0.

Now I will try to fiugre it out why.

Thanks

Gabriele



2014-04-11 9:20 GMT-04:00 Gabriele Brambilla <gb.gabrielebrambilla at gmail.com
>:

> Hi Danny,
> I'm quiet impressed.
> the program takes near 30 minutes instead of more than 8 hours!
>
> this is the profile:
> Fri Apr 11 09:14:04 2014    restats
>
>          19532732 function calls in 2105.024 seconds
>
>    Ordered by: internal time
>
>    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
>         1 2087.606 2087.606 2105.006 2105.006 skymapsI.py:44(mymain)
>  18101000   12.757    0.000   12.757    0.000 {method 'write' of 'file'
> objects}
>
>    715853    3.473    0.000    3.473    0.000 {method 'split' of 'str'
> objects}
>    715854    1.162    0.000    1.162    0.000 {zip}
>         1    0.018    0.018 2105.024 2105.024 <string>:1(<module>)
>         6    0.006    0.001    0.006    0.001 {open}
>         5    0.002    0.000    0.002    0.000 {method 'close' of 'file'
> objects}
>
>         1    0.000    0.000    0.000    0.000 function_base.py:8(linspace)
>         5    0.000    0.000    0.000    0.000 {numpy.core.multiarray.zeros}
>         1    0.000    0.000    0.000    0.000 function_base.py:93(logspace)
>         1    0.000    0.000    0.000    0.000
> {numpy.core.multiarray.arange}
>         3    0.000    0.000    0.000    0.000 {range}
>         1    0.000    0.000    0.000    0.000 {method 'disable' of
> '_lsprof.Prof
> iler' objects}
>
> I hope to have similar problems in the future to learn better how to do
> with them!
> but in the profile I don't see any operation regarding reading the file or
> the mathematical operations...are them hidden in mymain()?
>
> thanks
>
> Gabriele
>
>
>
>
> 2014-04-10 21:38 GMT-04:00 Danny Yoo <dyoo at hashcollision.org>:
>
> > Comment:  You are looping over your sliced eel five times.  Do you
>> >    need to?  I like eel salad a great deal, as well, but, how about:
>> >
>> >
>> >        for k in eel:
>> >            MYMAP1[i, j, k] = MYMAP1[i, j, k] + myinternet[oo]
>> >            MYMAP2[i, j, k] = MYMAP2[i, j, k] + myinternet[oo]
>> >            MYMAP3[i, j, k] = MYMAP3[i, j, k] + myinternet[oo]
>> >            MYMAP4[i, j, k] = MYMAP4[i, j, k] + myinternet[oo]
>> >            MYMAP5[i, j, k] = MYMAP5[i, j, k] + myinternet[oo]
>> >            oo = oo + 1
>>
>>
>> Hi Gabriele,
>>
>> Also note that, when Martin looked at this part of the code, he
>> unfortunately misinterpreted its effect; Martin's proposed rewrite
>> here does not preserve the meaning of the original code.  But rather
>> than wag my finger at how Martin interpreted the code, I'd rather make
>> the observation that this is a warning sign that the original code
>> here was not easy to understand.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140411/0e083c87/attachment.html>


More information about the Tutor mailing list