| This is a really basic question, I'm sure, for cython types. In the notebook, I have the following cell to compute a famous but totally inefficient $\pi(x)$ (prime counting function). It already is about 100 times faster than the equivalent in native Python. Question: The |
| The statement will cast If you want to use the C math library version of floor I think you need an appropriate include statement. Edit: If you use the Here is new code with the changes:
Makes sense; I remember something about 'casting' from reading C tutorials...
kcrisman (Apr 20 '11)
Followup to make you earn your check mark :) - any way to make the t = fact/j turn white too? Obviously this can be done in C, but I don't know how to make Cython do it right. Thank you!
kcrisman (Apr 20 '11)
Actually, it doesn't matter, because I need too long of numbers for the code to work right. No choice but to use Sage integers, I guess :) This is not for high performance!
kcrisman (Apr 20 '11)
To answer your second comment: there is a cython compiler directive you can use `cdivision=True`. This turns off exception checking for division by zero. It's the exception checking that adds more C code and why the annotated code there is yellow. Look at http://docs.cython.org/src/reference/compilation.htmlbenjaminfjones (Apr 20 '11)
Thanks, that makes sense. I'm just never sure what will behave like Python and what will behave like what I think (not know) C will do. As I said, even with longs this code becomes wrong after about n=22, and as it's just for demonstration I have no interest in importing mpz etc :)
kcrisman (Apr 21 '11) |
Asked: Apr 20 '11
Seen: 483 times
Last updated: Apr 21 '11
powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.