-
-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
%timeit on command line doesn't recognize [1..10] syntax #797
Comments
comment:3
The workaround now is to use the timeit command, which does send things to the preparser.
|
comment:5
Just because there is a workaround doesn't mean this should be closed. I reported this problem to Fernando Perez of Ipython and he "admitted" that it is a bug, and was working on fixing it at that last sage days. I'm re-opening this. By the way, it's generally very bad for anybody but me or Michael Abshoff to close tickets on trac! |
comment:6
I only closed it after mabshoff gave his okay on IRC. I guess I should have posted the IRC log. |
Replying to @jasongrout: Here is some account of what happens in Sage 3.2.3:
So, the first problem is not a problem anymore.
So, that is the only remaining issue. I am now looking at |
comment:8
We can overwrite the default magic commands in IPython:
|
comment:9
I somehow got the impression that it is an issue with preparsing, for the following reason:
This is the same error as in
In the code, by default preparsing should be done; namely, in
Now, we also have
So, it should be with preparsing. For testing, I inserted a line in the code that prints the value of The curious thing is that this line is executed when doing I was just told that Can you tell me where the behaviour of |
comment:10
Are you doing this in the notebook or the command-line? They're two totally separate things. Can you hop on IRC? |
comment:11
When you run %timeit from the command-line, it runs code in IPython and does not touch any code in the Sage library. The issue is that the IPython magic command "%timeit" doesn't do the preparsing. Fernando was working on an upstream fix for this. An easy downstream fix for this would be to do as I suggested above and overwrite the IPython version of timeit with our own with the expose_magic function.
The right place to put this would probably be in local/bin/ipy_profile_sage.py. |
comment:12
Replying to @mwhansen:
Thank you! While you replied, I tried to post the following: Replying to @mwhansen:
It is command-line, and I don't know what happens on the notebook. Can you test it? If it is in
Hence, if the line starts with But what happens afterwards? In the end of the day,
I try (I never used IRC before). So, if it works, see you soon. Cheers |
Attachment: timeit.patch.gz Change preparse_ipython so that %timeit results in calling timeit.eval |
comment:13
In Idea: Call With the patch, the following examples now work:
and the other ways of calling the timer still work:
|
Changed keywords from none to timeit ipython |
comment:14
Replying to @simon-king-jena:
Probably I should elaborate more on how it works. In the old version of For the new version, I suggest to test whether the word after '%' is 'timeit'. If it is, |
comment:15
To emphasize another detail: My suggestion only relates with |
comment:16
This patch works for me, but I think mhansen ought to comment on this approach versus the approach he advocated above using |
comment:17
The _ip.expose_magic approach also seems to work just as well. I would prefer using the ipython mechanism for doing this, rather than complicating the preparser. In fact, I'd suggest using ipython to do all of the %mode functionality as well, if it's a possibility. |
comment:18
Simon, what do you think about the idea of using ipython to do this, like mhansen suggests above? I think it's cleaner, it keeps the ipython stuff together (i.e., the "%" commands with ipython), and avoids making the preparser more complicated. |
comment:19
Hi Jason, Replying to @jasongrout:
Sure, it makes sense. The problem is that i have no idea about ipython, so, I guess i would not be able to do it in that way. Perhaps i should look at local/bin/ipy_profile_sage.py, but i wouldn't be upset if someone else were faster... :) Cheers, |
comment:20
Changing this to "needs work" in light of mhansen's solution above. |
Attachment: trac_797.patch.gz |
Author: Mike Hansen |
comment:21
I've put a patch up which implements the expose_magic idea. |
comment:22
Looks great! Positive review to Mike's patch. Only apply Mike's patch (to the local/bin repository!) |
Merged: sage-4.3.1.rc1 |
Reviewer: Jason Grout |
Component: user interface
Keywords: timeit ipython
Author: Mike Hansen
Reviewer: Jason Grout
Merged: sage-4.3.1.rc1
Issue created by migration from https://trac.sagemath.org/ticket/797
The text was updated successfully, but these errors were encountered: