#797: %timeit doesn't recognize [1..10] syntax
----------------------------+-----------------------------------------------
Reporter: jason | Owner: was
Type: defect | Status: reopened
Priority: minor | Milestone: sage-3.4.1
Component: user interface | Resolution:
Keywords: |
----------------------------+-----------------------------------------------
Comment (by SimonKing):
Replying to [comment:11 mhansen]:
> 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.
>
> {{{
> sage: _ip.expose_magic("timeit", lambda self, s: timeit(s))
> sage: %timeit [1..10]
> 625 loops, best of 3: 58.4 µs per loop
> }}}
>
> The right place to put this would probably be in
local/bin/ipy_profile_sage.py.
Thank you!
While you replied, I tried to post the following:
Replying to [comment:10 mhansen]:
> Are you doing this in the notebook or the command-line? They're two
totally separate things.
It is command-line, and I don't know what happens on the notebook. Can you
test it?
If it is in `preparser_ipython`, then the following might be the source of
trouble:
{{{
def preparse_ipython(line, reset=True):
global num_lines
global q_lines
L = line.lstrip()
if L.startswith('%'):
# This should be installed as an Ipython magic command,
# but I don't know how yet...
L = L[1:].strip()
import sage.interfaces.all
if L.lower() in sage.interfaces.all.interfaces:
switch_interface(L.lower())
return "''"
else:
# only preparse non-magic lines
return line
}}}
Hence, if the line starts with `%` and if the word after `%` is not the
name of an interface than simply the line is returned unchanged.
But what happens afterwards? In the end of the day, `%timeit` gets an
interpretation and does call some `timeit` command!
> Can you hop on IRC?
I try (I never used IRC before). So, if it works, see you soon.
Cheers
Simon
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/797#comment:12>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of
Reinventing the Wheel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---