|
|
Subscribe / Log in / New account

Advanced computing with IPython

Advanced computing with IPython

Posted Jun 20, 2018 17:03 UTC (Wed) by yroyon (guest, #99220)
Parent article: Advanced computing with IPython

Thanks for the article. A great gentle introduction.

A couple of things were not obvious to me.

1) First you time your snippets using %%time, then %%timeit. It's not clear why. From the docs, I gather %%timeit accepts extra options, though you don't use them. It's still not clear to me why two separate magics exist instead of one. Could just add the options to %%time, no?

2) The approximation of e using Python vs. Fortran gives a pretty different output. Not really a desirable outcome. Is that solely because of the type precision?


to post comments

Advanced computing with IPython

Posted Jun 20, 2018 18:22 UTC (Wed) by excors (subscriber, #95769) [Link] (1 responses)

They should both be using double-precision floats, and should calculate 1+1/1e8 identically. But the ** operator is much more complicated and can be implemented in many different ways with different levels of accuracy and performance. I guess Python probably uses pow() from the C standard library, so might not even give the same answer if you run it on Windows, and the Fortran compiler presumably has its own implementation. So it's more a consequence of their maths libraries than of the language itself, exacerbated by doing a silly computation .

Advanced computing with IPython

Posted Jun 20, 2018 18:39 UTC (Wed) by excors (subscriber, #95769) [Link]

Oh, and also the Python version returns the value from n=1e8-1, while the Fortran version goes up to n=1e8, because 'range' takes an exclusive upper bound and 'do' is inclusive. But even after fixing that, it seems there's still a (slightly smaller) difference in their outputs.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds