Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/sage/misc/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from sage.all import *


def benchmark(n=-1):
"""
Run a well-chosen range of Sage commands and record the time it
Expand Down Expand Up @@ -78,6 +79,7 @@ def benchmark(n=-1):
break
return v, cputime(t)


def bench0():
"""
Run a benchmark.
Expand All @@ -92,12 +94,13 @@ def bench0():
"""
desc = """Benchmark 0: Factor the following polynomial over
the rational numbers: (x^97+19*x+1)*(x^103-19*x^97+14)*(x^100-1)"""
x = polygen(QQ,"x")
x = polygen(QQ, "x")
f = (x**97+19*x+1)*(x**103-19*x**97+14)*(x**100-1)
t = cputime()
F = f.factor()
return (desc, cputime(t))


def bench1():
"""
Run a benchmark.
Expand All @@ -115,6 +118,7 @@ def bench1():
g = E.gens()
return (desc, cputime(t))


def bench2():
"""
Run a benchmark.
Expand All @@ -131,6 +135,7 @@ def bench2():
a = ZZ(3)**1000001 * ZZ(19)**100001
return (desc, cputime(t))


def bench3():
"""
Run a benchmark.
Expand All @@ -147,6 +152,7 @@ def bench3():
a = QQ((2, 3))**100001 * QQ((17, 19))**100001
return (desc, cputime(t))


def bench4():
"""
Run a benchmark.
Expand All @@ -165,6 +171,7 @@ def bench4():
a = f**200
return (desc, cputime(t))


def bench5():
"""
Run a benchmark.
Expand All @@ -183,6 +190,7 @@ def bench5():
w = [f**50 for _ in range(100)]
return (desc, cputime(t))


def bench6():
"""
Run a benchmark.
Expand All @@ -195,12 +203,13 @@ def bench6():

"""
desc = """Compute the p-division polynomials of y^2 = x^3 + 37*x - 997 for primes p < 40."""
E = EllipticCurve([0,0,0,37,-997])
E = EllipticCurve([0, 0, 0, 37, -997])
t = cputime()
for p in [2,3,5,7,11,13,17,19,23,29,31,37]:
for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]:
f = E.division_polynomial(p)
return (desc, cputime(t))


def bench7():
"""
Run a benchmark.
Expand All @@ -213,7 +222,7 @@ def bench7():

"""
desc = """Compute the Mordell-Weil group of y^2 = x^3 + 37*x - 997."""
E = EllipticCurve([0,0,0,37,-997])
E = EllipticCurve([0, 0, 0, 37, -997])
t = cputime()
G = E.gens()
return (desc, cputime(t))
2 changes: 2 additions & 0 deletions src/sage/misc/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#############################################
# Operators
#############################################


class AttrCallObject:
def __init__(self, name, args, kwds):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/misc/compat.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Cross-platform compatibility routines and wrappers."""

#*****************************************************************************
# *****************************************************************************
# Copyright (C) 2017 William Stein <wstein@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# *****************************************************************************

import os
import subprocess
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/copying.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __repr__(self):
return "Type license() to see the full license text."

def __str__(self):
with open(os.path.join(SAGE_ROOT,'COPYING.txt')) as f:
with open(os.path.join(SAGE_ROOT, 'COPYING.txt')) as f:
return f.read()


Expand Down
28 changes: 15 additions & 13 deletions src/sage/misc/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- Julian Rueth (2014-03-19): added ``decorator_keywords`` decorator

"""
#*****************************************************************************
# *****************************************************************************
# Copyright (C) 2009 Tim Dumol
# 2010,2011 Johan S. R. Nielsen
# 2011 Simon King <simon.king@uni-jena.de>
Expand All @@ -24,7 +24,7 @@
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# *****************************************************************************

from functools import (partial, update_wrapper, WRAPPER_ASSIGNMENTS,
WRAPPER_UPDATES)
Expand Down Expand Up @@ -155,10 +155,10 @@ def sage_wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES):
81

"""
#TRAC 9919: Workaround for bug in @update_wrapper when used with
#non-function callables.
# TRAC 9919: Workaround for bug in @update_wrapper when used with
# non-function callables.
assigned = set(assigned).intersection(set(dir(wrapped)))
#end workaround
# end workaround

def f(wrapper, assigned=assigned, updated=updated):
update_wrapper(wrapper, wrapped, assigned=assigned, updated=updated)
Expand All @@ -168,9 +168,9 @@ def f(wrapper, assigned=assigned, updated=updated):
wrapper.__wrapped__ = wrapped
wrapper._sage_src_ = lambda: sage_getsource(wrapped)
wrapper._sage_src_lines_ = lambda: sage_getsourcelines(wrapped)
#Getting the signature right in documentation by Sphinx (Issue 9976)
#The attribute _sage_argspec_() is read by Sphinx if present and used
#as the argspec of the function instead of using reflection.
# Getting the signature right in documentation by Sphinx (Issue 9976)
# The attribute _sage_argspec_() is read by Sphinx if present and used
# as the argspec of the function instead of using reflection.
wrapper._sage_argspec_ = lambda: sage_getargspec(wrapped)
return wrapper
return f
Expand Down Expand Up @@ -424,7 +424,7 @@ def listForNone(l):
newArgs = [self.name + opt for opt in self.options.keys()]
args = (argspec.args if argspec.args is not None else []) + newArgs
defaults = (argspec.defaults if argspec.defaults is not None else ()) \
+ tuple(self.options.values())
+ tuple(self.options.values())
# Note: argspec.defaults is not always a tuple for some reason
return FullArgSpec(args, argspec.varargs, argspec.varkw, defaults,
kwonlyargs=[], kwonlydefaults=None, annotations={})
Expand Down Expand Up @@ -496,9 +496,9 @@ def wrapper(*args, **kwds):
options.update(kwds)
return func(*args, **options)

#Add the options specified by @options to the signature of the wrapped
#function in the Sphinx-generated documentation (Issue 9976), using the
#special attribute _sage_argspec_ (see e.g. sage.misc.sageinspect)
# Add the options specified by @options to the signature of the wrapped
# function in the Sphinx-generated documentation (Issue 9976), using the
# special attribute _sage_argspec_ (see e.g. sage.misc.sageinspect)
def argspec():
argspec = sage_getargspec(func)
args = ((argspec.args if argspec.args is not None else []) +
Expand Down Expand Up @@ -659,6 +659,7 @@ def wrapper(*args, **kwds):

return wrapper


class specialize:
r"""
A decorator generator that returns a decorator that in turn
Expand Down Expand Up @@ -697,6 +698,7 @@ def __init__(self, *args, **kwargs):
def __call__(self, f):
return sage_wraps(f)(partial(f, *self.args, **self.kwargs))


def decorator_keywords(func):
r"""
A decorator for decorators with optional keyword arguments.
Expand Down Expand Up @@ -731,7 +733,7 @@ def decorator_keywords(func):
@sage_wraps(func)
def wrapped(f=None, **kwargs):
if f is None:
return sage_wraps(func)(lambda f:func(f, **kwargs))
return sage_wraps(func)(lambda f: func(f, **kwargs))
else:
return func(f, **kwargs)
return wrapped
16 changes: 8 additions & 8 deletions src/sage/misc/edit_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
# we can set some defaults, however. Add your own if you like.

template_defaults = {
'vi' : Template('vi -c ${line} ${file}'),
'vim' : Template('vim -c ${line} ${file}'),
'emacs' : Template('emacs ${opts} +${line} ${file}'),
'nedit-nc' : Template('nedit-nc -line ${line} ${file}'),
'nedit-client' : Template('nedit-client -line ${line} ${file}'),
'ncl' : Template('ncl -line ${line} ${file}'),
'gedit' : Template('gedit +${line} ${file} &'),
'kate' : Template('kate -u --line +${line} ${file} &') }
'vi': Template('vi -c ${line} ${file}'),
'vim': Template('vim -c ${line} ${file}'),
'emacs': Template('emacs ${opts} +${line} ${file}'),
'nedit-nc': Template('nedit-nc -line ${line} ${file}'),
'nedit-client': Template('nedit-client -line ${line} ${file}'),
'ncl': Template('ncl -line ${line} ${file}'),
'gedit': Template('gedit +${line} ${file} &'),
'kate': Template('kate -u --line +${line} ${file} &')}


def file_and_line(obj):
Expand Down
28 changes: 19 additions & 9 deletions src/sage/misc/explain_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@

"""

#*****************************************************************************
# *****************************************************************************
# Copyright (C) 2009 Carl Witty <Carl.Witty@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# *****************************************************************************


import pickletools
Expand Down Expand Up @@ -258,6 +258,7 @@ def explain_pickle(pickle=None, file=None, compress=True, **kwargs):

return explain_pickle_string(p, **kwargs)


def explain_pickle_string(pickle, in_current_sage=False,
default_assumptions=False, eval=False, preparse=True,
pedantic=False):
Expand Down Expand Up @@ -295,6 +296,8 @@ def explain_pickle_string(pickle, in_current_sage=False,


valid_name_re = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$')


def name_is_valid(name):
r"""
Test whether a string is a valid Python identifier. (We use a
Expand All @@ -318,6 +321,7 @@ def name_is_valid(name):
# This string is used as the representation of a mark.
the_mark = 'mark'


class PickleObject:
r"""
Pickles have a stack-based virtual machine. The :func:`explain_pickle`
Expand Down Expand Up @@ -374,6 +378,7 @@ def _sage_input_(self, sib, coerced):
self.immutable = True
return self.expression


class PickleDict:
r"""
An object which can be used as the value of a :class:`PickleObject`. The items
Expand All @@ -394,6 +399,7 @@ def __init__(self, items):
"""
self.items = items


class PickleInstance:
r"""
An object which can be used as the value of a :class:`PickleObject`. Unlike
Expand All @@ -412,6 +418,7 @@ def __init__(self, klass):
"""
self.klass = klass


class PickleExplainer:
r"""
An interpreter for the pickle virtual machine, that executes
Expand Down Expand Up @@ -831,9 +838,9 @@ def _APPENDS_helper(self, lst, slice):
lst.expression = self.sib(lst.value)
elif isinstance(lst, PickleObject) or self.default_assumptions:
if isinstance(lst.value, list) or \
(isinstance(lst.value, PickleInstance) and
issubclass(lst.value.klass, list)) or \
self.default_assumptions:
(isinstance(lst.value, PickleInstance) and
issubclass(lst.value.klass, list)) or \
self.default_assumptions:
if len(slice) > 1:
self.sib.command(lst, self.sib.name('list').extend(lst, slice))
else:
Expand Down Expand Up @@ -1105,10 +1112,10 @@ def BUILD(self):
slots = state[1].value
state = state[0].value
d = self.sib.getattr(obj, '__dict__')
for k,v in state.items:
for k, v in state.items:
self.sib.command(obj, self.sib.assign(d[k], v))
if slots is not None:
for k,v in slots.items:
for k, v in slots.items:
if isinstance(k, PickleObject) and isinstance(k.value, str):
self.sib.command(obj, self.sib.assign(self.sib.getattr(obj, k.value), v))
else:
Expand Down Expand Up @@ -2473,6 +2480,7 @@ def unpickle_instantiate(fn, args):

unpickle_persistent_loader = None


def unpickle_persistent(s):
r"""
Takes an integer index and returns the persistent object with that
Expand Down Expand Up @@ -2985,6 +2993,7 @@ def __setstate__(self, state):
self.x = state[1]['y']
self.y = state[0]['x']


class TestGlobalOldName:
r"""
A featureless new-style class. When you try to unpickle an instance
Expand Down Expand Up @@ -3032,6 +3041,7 @@ def __repr__(self):

register_unpickle_override('sage.misc.explain_pickle', 'TestGlobalOldName', TestGlobalNewName, call_name=('sage.misc.explain_pickle', 'TestGlobalNewName'))


class TestGlobalFunnyName:
r"""
A featureless new-style class which has a name that's not a legal
Expand Down Expand Up @@ -3065,5 +3075,5 @@ def __repr__(self):


TestGlobalFunnyName.__name__ = "funny$name"
#This crashed Sphinx. Instead, we manually execute this just before the test.
#globals()['funny$name'] = TestGlobalFunnyName
# This crashed Sphinx. Instead, we manually execute this just before the test.
# globals()['funny$name'] = TestGlobalFunnyName
4 changes: 2 additions & 2 deletions src/sage/misc/flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def flatten(in_list, ltypes=(list, tuple), max_level=sys.maxsize):
while isinstance(new_list[index], ltypes) and current_level < max_level:
v = list(new_list[index])
len_v = len(v)
new_list[index : index + 1] = v
new_list[index: index + 1] = v
old_level = level_list[index]
level_list[index : index + 1] = [0] * len_v
level_list[index: index + 1] = [0] * len_v
if len_v:
current_level += 1
level_list[index + len_v - 1] = old_level + 1
Expand Down
1 change: 1 addition & 0 deletions src/sage/misc/func_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def bern(n):

from sage.misc import persist


class func_persist:
r"""
Put ``@func_persist`` right before your function
Expand Down
Loading