Commit 2748f9ef authored by mathbunnyru's avatar mathbunnyru
Browse files

Delete trailing spaces

parent 3d4f7a19
......@@ -71,7 +71,7 @@ def runcmd(cmd, shell=True):
returncode = os.system(cmd)
else:
returncode = subprocess.call(cmd, shell=shell)
if returncode:
sys.exit(returncode)
......
......@@ -65,7 +65,7 @@ changes/contributions they have specific copyright on, they should indicate
their copyright in the commit message of the change, when they commit the
change to one of the IPython repositories.
With this in mind, the following banner should be used in any source code file
With this in mind, the following banner should be used in any source code file
to indicate the copyright and license terms:
::
......
......@@ -85,7 +85,7 @@ class DeclarationWriter(TreeVisitor):
def visit_StatListNode(self, node):
self.visitchildren(node)
def visit_CDefExternNode(self, node):
if node.include_file is None:
file = u'*'
......@@ -516,6 +516,6 @@ class PxdWriter(DeclarationWriter):
if node.api:
self.put(u'api ')
self.visit(node.declarator)
def visit_StatNode(self, node):
pass
......@@ -13,7 +13,7 @@ class TestMemviewParsing(CythonTest):
def not_parseable(self, expected_error, s):
e = self.should_fail(lambda: self.fragment(s), Errors.CompileError)
self.assertEqual(expected_error, e.message_only)
def test_default_1dim(self):
self.parse(u"cdef int[:] x")
self.parse(u"cdef short int[:] x")
......
......@@ -12,9 +12,9 @@ python_var = 13
def spam(a=0):
cdef:
int b, c
b = c = d = 0
b = 1
c = 2
int(10)
......@@ -23,11 +23,11 @@ def spam(a=0):
some_c_function()
cpdef eggs():
pass
pass
cdef ham():
pass
cdef class SomeClass(object):
def spam(self):
pass
......
......@@ -2517,8 +2517,8 @@ class FixGdbCommand(gdb.Command):
def fix_gdb(self):
"""
It seems that invoking either 'cy exec' and 'py-exec' work perfectly
fine, but after this gdb's python API is entirely broken.
It seems that invoking either 'cy exec' and 'py-exec' work perfectly
fine, but after this gdb's python API is entirely broken.
Maybe some uncleared exception value is still set?
sys.exc_clear() didn't help. A demonstration:
......
"""
array.pxd
Cython interface to Python's array.array module.
* 1D contiguous data view
* tools for fast array creation, maximum C-speed and handiness
* suitable as allround light weight auto-array within Cython code too
Usage:
>>> cimport array
Usage through Cython buffer interface (Py2.3+):
Usage through Cython buffer interface (Py2.3+):
>>> def f(arg1, unsigned i, double dx)
... array.array[double] a = arg1
... a[i] += dx
Fast C-level new_array(_zeros), resize_array, copy_array, Py_SIZE(obj),
zero_array
cdef array.array[double] k = array.copy(d)
cdef array.array[double] k = array.copy(d)
cdef array.array[double] n = array.array(d, Py_SIZE(d) * 2 )
cdef array.array[double] m = array.zeros_like(FLOAT_TEMPLATE)
array.resize(f, 200000)
Zero overhead with naked data pointer views by union:
_f, _d, _i, _c, _u, ...
Zero overhead with naked data pointer views by union:
_f, _d, _i, _c, _u, ...
=> Original C array speed + Python dynamic memory management
cdef array.array a = inarray
if
if
a._d[2] += 0.66 # use as double array without extra casting
float *subview = vector._f + 10 # starting from 10th element
unsigned char *subview_buffer = vector._B + 4
Suitable as lightweight arrays intra Cython without speed penalty.
Replacement for C stack/malloc arrays; no trouble with refcounting,
unsigned char *subview_buffer = vector._B + 4
Suitable as lightweight arrays intra Cython without speed penalty.
Replacement for C stack/malloc arrays; no trouble with refcounting,
mem.leaks; seamless Python compatibility, buffer() optional
last changes: 2009-05-15 rk
: 2009-12-06 bp
......
......@@ -5,7 +5,7 @@ cdef extern from "Python.h":
pass
cdef extern from "datetime.h":
ctypedef extern class datetime.date[object PyDateTime_Date]:
pass
......@@ -23,11 +23,11 @@ cdef extern from "datetime.h":
ctypedef struct PyDateTime_Date:
pass
ctypedef struct PyDateTime_Time:
char hastzinfo
PyObject *tzinfo
ctypedef struct PyDateTime_DateTime:
char hastzinfo
PyObject *tzinfo
......@@ -36,22 +36,22 @@ cdef extern from "datetime.h":
int days
int seconds
int microseconds
# Define structure for C API.
ctypedef struct PyDateTime_CAPI:
# type objects
# type objects
PyTypeObject *DateType
PyTypeObject *DateTimeType
PyTypeObject *TimeType
PyTypeObject *DeltaType
PyTypeObject *TZInfoType
# constructors
object (*Date_FromDate)(int, int, int, PyTypeObject*)
object (*DateTime_FromDateAndTime)(int, int, int, int, int, int, int, object, PyTypeObject*)
object (*Time_FromTime)(int, int, int, int, object, PyTypeObject*)
object (*Delta_FromDelta)(int, int, int, int, PyTypeObject*)
# constructors for the DB API
object (*DateTime_FromTimestamp)(object, object, object)
object (*Date_FromTimestamp)(object, object)
......@@ -96,7 +96,7 @@ cdef extern from "datetime.h":
# PyDateTime CAPI object.
PyDateTime_CAPI *PyDateTimeAPI
void PyDateTime_IMPORT()
# Datetime C API initialization function.
......@@ -108,7 +108,7 @@ cdef inline void import_datetime():
# Note, there are no range checks for any of the arguments.
cdef inline object date_new(int year, int month, int day):
return PyDateTimeAPI.Date_FromDate(year, month, day, PyDateTimeAPI.DateType)
# Create time object using DateTime CAPI factory function
# Note, there are no range checks for any of the arguments.
cdef inline object time_new(int hour, int minute, int second, int microsecond, object tz):
......@@ -127,7 +127,7 @@ cdef inline object timedelta_new(int days, int seconds, int useconds):
# More recognizable getters for date/time/datetime/timedelta.
# There are no setters because datetime.h hasn't them.
# This is because of immutable nature of these objects by design.
# If you would change time/date/datetime/timedelta object you need to recreate.
# If you would change time/date/datetime/timedelta object you need to recreate.
# Get tzinfo of time
cdef inline object time_tzinfo(object o):
......@@ -136,7 +136,7 @@ cdef inline object time_tzinfo(object o):
else:
return None
# Get tzinfo of datetime
# Get tzinfo of datetime
cdef inline object datetime_tzinfo(object o):
if (<PyDateTime_DateTime*>o).hastzinfo:
return <object>(<PyDateTime_DateTime*>o).tzinfo
......@@ -146,7 +146,7 @@ cdef inline object datetime_tzinfo(object o):
# Get year of date
cdef inline int date_year(object o):
return PyDateTime_GET_YEAR(o)
# Get month of date
cdef inline int date_month(object o):
return PyDateTime_GET_MONTH(o)
......@@ -158,7 +158,7 @@ cdef inline int date_day(object o):
# Get year of datetime
cdef inline int datetime_year(object o):
return PyDateTime_GET_YEAR(o)
# Get month of datetime
cdef inline int datetime_month(object o):
return PyDateTime_GET_MONTH(o)
......
......@@ -14,7 +14,7 @@ cdef extern from "<iterator>" namespace "std" nogil:
pass
cdef cppclass random_access_iterator_tag(bidirectional_iterator_tag):
pass
cdef cppclass back_insert_iterator[T](iterator[output_iterator_tag,void,void,void,void]):
pass
cdef cppclass front_insert_iterator[T](iterator[output_iterator_tag,void,void,void,void]):
......@@ -29,4 +29,4 @@ cdef extern from "<iterator>" namespace "std" nogil:
##insert_iterator<Container> inserter (Container& x, typename Container::iterator it)
insert_iterator[CONTAINER] inserter[CONTAINER,ITERATOR](CONTAINER &, ITERATOR)
......@@ -5,7 +5,7 @@ cdef extern from "<limits>" namespace "std" nogil:
round_to_nearest = 1
round_toward_infinity = 2
round_toward_neg_infinity = 3
enum float_denorm_style:
denorm_indeterminate = -1
denorm_absent = 0
......@@ -37,7 +37,7 @@ cdef extern from "<limits>" namespace "std" nogil:
const int min_exponent10
const int max_exponent
const int max_exponent10
const bint has_infinity
const bint has_quiet_NaN
const bint has_signaling_NaN
......
......@@ -16,8 +16,8 @@ cdef extern from "<memory>" namespace "std" nogil:
void construct( T *, const T &) #C++98. The C++11 version is variadic AND perfect-forwarding
void destroy(T *) #C++98
void destroy[U](U *) #unique_ptr unit tests fail w/this
cdef cppclass unique_ptr[T,DELETER=*]:
unique_ptr()
unique_ptr(nullptr_t)
......
......@@ -113,7 +113,7 @@ class Template(object):
self.default_namespace['start_braces'] = delimeters[0]
self.default_namespace['end_braces'] = delimeters[1]
self.delimeters = delimeters
self._unicode = is_unicode(content)
if name is None and stacklevel is not None:
try:
......
......@@ -129,7 +129,7 @@ class TestJediTyper(TransformTest):
variables = types.pop((None, (1, 0)))
self.assertFalse(types)
self.assertEqual({'a': set(['list']), 'b': set(['list']), 'c': set(['list']), 'd': set(['list'])}, variables)
def test_typing_function_list(self):
code = '''\
def func(x):
......@@ -149,14 +149,14 @@ class TestJediTyper(TransformTest):
code = '''\
a = dict()
b = {i: i**2 for i in range(10)}
c = a
c = a
'''
types = self._test(code)
self.assertIn((None, (1, 0)), types)
variables = types.pop((None, (1, 0)))
self.assertFalse(types)
self.assertEqual({'a': set(['dict']), 'b': set(['dict']), 'c': set(['dict'])}, variables)
def test_typing_function_dict(self):
code = '''\
def func(x):
......@@ -186,7 +186,7 @@ class TestJediTyper(TransformTest):
variables = types.pop((None, (1, 0)))
self.assertFalse(types)
self.assertEqual({'a': set(['set']), 'c': set(['set']), 'd': set(['set']), 'e': set(['set'])}, variables)
def test_typing_function_set(self):
code = '''\
def func(x):
......
......@@ -29,7 +29,7 @@ typedef struct arraydescr {
int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *);
#if PY_MAJOR_VERSION >= 3
char *formats;
#endif
#endif
} arraydescr;
......@@ -110,7 +110,7 @@ static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) {
if (items == NULL) {
PyErr_NoMemory();
return -1;
}
}
self->data.ob_item = (char*) items;
self->ob_size = n;
self->allocated = n;
......
......@@ -24,12 +24,12 @@
make
./nCr 10 5
./python
* Build notes
* benchmarks/chaos.py requires cython 0.24 or newer
* embed and freeze work for python2, require cython 0.24 or higher
for python 3.5
#!/usr/bin/python
# Back-Propagation Neural Networks
#
#
# Written in Python. See http://www.python.org/
#
# Neil Schemenauer <nascheme@enme.ucalgary.ca>
......@@ -26,7 +26,7 @@ def makeMatrix(I, J, fill=0.0):
return m
class NN(object):
# print 'class NN'
# print 'class NN'
def __init__(self, ni, nh, no):
# number of input, hidden, and output nodes
self.ni = ni + 1 # +1 for bias node
......@@ -37,7 +37,7 @@ class NN(object):
self.ai = [1.0]*self.ni
self.ah = [1.0]*self.nh
self.ao = [1.0]*self.no
# create weights
self.wi = makeMatrix(self.ni, self.nh)
self.wo = makeMatrix(self.nh, self.no)
......@@ -49,7 +49,7 @@ class NN(object):
for k in range(self.no):
self.wo[j][k] = rand(-2.0, 2.0)
# last change in weights for momentum
# last change in weights for momentum
self.ci = makeMatrix(self.ni, self.nh)
self.co = makeMatrix(self.nh, self.no)
......
......@@ -17,7 +17,7 @@ class Dir(object):
def __init__(self, x, y):
self.x = x
self.y = y
DIRS = [ Dir(1, 0),
Dir(-1, 0),
Dir(0, 1),
......@@ -35,7 +35,7 @@ class Done(object):
FIRST_STRATEGY = 3
MAX_NEIGHBORS_STRATEGY = 4
MIN_NEIGHBORS_STRATEGY = 5
def __init__(self, count, empty=False):
self.count = count
self.cells = None if empty else [[0, 1, 2, 3, 4, 5, 6, EMPTY] for i in range(count)]
......@@ -60,11 +60,11 @@ class Done(object):
return True
else:
return False
def remove_all(self, v):
for i in range(self.count):
self.remove(i, v)
def remove_unfixed(self, v):
changed = False
for i in range(self.count):
......@@ -72,7 +72,7 @@ class Done(object):
if self.remove(i, v):
changed = True
return changed
def filter_tiles(self, tiles):
for v in range(8):
if tiles[v] == 0:
......@@ -206,14 +206,14 @@ class Hex(object):
def contains_pos(self, pos):
return pos in self.nodes_by_pos
def get_by_pos(self, pos):
return self.nodes_by_pos[pos]
def get_by_id(self, id):
return self.nodes_by_id[id]
##################################
class Pos(object):
def __init__(self, hex, tiles, done = None):
......@@ -223,7 +223,7 @@ class Pos(object):
def clone(self):
return Pos(self.hex, self.tiles, self.done.clone())
##################################
@cython.locals(pos=Pos, i=cython.long, v=cython.int,
......@@ -260,7 +260,7 @@ def constraint_pass(pos, last_move=None):
for cell in done.cells:
if len(cell) == 1:
left[cell[0]] -= 1
for v in range(8):
# If there is none, remove the possibility from all tiles
if (pos.tiles[v] > 0) and (left[v] == 0):
......@@ -276,7 +276,7 @@ def constraint_pass(pos, last_move=None):
if (not done.already_done(i)) and (v in cell):
done.set_done(i, v)
changed = True
# Force empty or non-empty around filled cells
filled_cells = (range(done.count) if last_move is None
else [last_move])
......@@ -307,7 +307,7 @@ def constraint_pass(pos, last_move=None):
for u in unknown:
if done.remove(u, EMPTY):
changed = True
return changed
ASCENDING = 1
......@@ -402,7 +402,7 @@ def solved(pos, output, verbose=False):
if (not all_done) or (not exact):
return OPEN
print_pos(pos, output)
return SOLVED
......@@ -414,7 +414,7 @@ def solve_step(prev, strategy, order, output, first=False):
pass
else:
pos = prev
moves = find_moves(pos, strategy, order)
if len(moves) == 0:
return solved(pos, output)
......@@ -481,12 +481,12 @@ def read_file(file):
else:
inctile = int(tile)
tiles[inctile] += 1
# Look for locked tiles
# Look for locked tiles
if tile[0] == "+":
print("Adding locked tile: %d at pos %d, %d, id=%d" %
(inctile, x, y, hex.get_by_pos((x, y)).id))
done.set_done(hex.get_by_pos((x, y)).id, inctile)
linei += 1
for y in range(1, size):
ry = size - 1 + y
......@@ -500,7 +500,7 @@ def read_file(file):
else:
inctile = int(tile)
tiles[inctile] += 1
# Look for locked tiles
# Look for locked tiles
if tile[0] == "+":
print("Adding locked tile: %d at pos %d, %d, id=%d" %
(inctile, x, ry, hex.get_by_pos((x, ry)).id))
......@@ -530,13 +530,13 @@ def run_level36():
output = StringIO()
solve_file(f, strategy, order, output)
expected = """\
3 4 3 2
3 4 4 . 3
2 . . 3 4 3
2 . 1 . 3 . 2
3 3 . 2 . 2
3 . 2 . 2
2 2 . 1
3 4 3 2
3 4 4 . 3
2 . . 3 4 3
2 . 1 . 3 . 2
3 3 . 2 . 2
3 . 2 . 2
2 2 . 1
"""
if output.getvalue() != expected:
raise AssertionError("got a wrong answer:\n%s" % output.getvalue())
......
......@@ -143,7 +143,7 @@ def main(n):
tk = time.time()
times.append(tk - t0)
return times
if __name__ == "__main__":
parser = optparse.OptionParser(
usage="%prog [options]",
......
......@@ -102,13 +102,13 @@ class TaskState(object):
self.task_waiting = False
self.task_holding = False
return self
def waitingWithPacket(self):
self.packet_pending = True
self.task_waiting = True
self.task_holding = False
return self
def isPacketPending(self):
return self.packet_pending
......@@ -233,7 +233,7 @@ class Task(TaskState):
if t is None:
raise Exception("Bad task id %d" % id)
return t
# DeviceTask
......@@ -307,7 +307,7 @@ class IdleTask(Task):
else:
i.control = i.control//2 ^ 0xd008
return self.release(I_DEVB)
# WorkTask
......@@ -385,7 +385,7 @@ class Richards(object):
wkq = None;
DeviceTask(I_DEVA, 4000, wkq, TaskState().waiting(), DeviceTaskRec());
DeviceTask(I_DEVB, 5000, wkq, TaskState().waiting(), DeviceTaskRec());
schedule()
if taskWorkArea.holdCount == 9297 and taskWorkArea.qpktCount == 23246:
......@@ -431,7 +431,7 @@ else:
for it in item.__dict__.values():
if isinstance(it, types.FunctionType):
pypyjit.enable(it.func_code)
if __name__ == '__main__':
import sys
if len(sys.argv) >= 2:
......
......@@ -55,7 +55,7 @@ def main(n):
tk = time()
times.append(tk - t0)
return times
if __name__ == "__main__":
parser = optparse.OptionParser(
usage="%prog [options]",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment