@@ -9,15 +9,15 @@ TESTS::
9
9
sage: TestSuite(A).run()
10
10
"""
11
11
12
- # ** ***************************************************************************
12
+ # ***************************************************************************
13
13
# Copyright (C) 2005, 2006 William Stein <[email protected] >
14
14
#
15
15
# This program is free software: you can redistribute it and/or modify
16
16
# it under the terms of the GNU General Public License as published by
17
17
# the Free Software Foundation, either version 2 of the License, or
18
18
# (at your option) any later version.
19
- # http ://www.gnu.org/licenses/
20
- # ** ***************************************************************************
19
+ # https ://www.gnu.org/licenses/
20
+ # ***************************************************************************
21
21
22
22
from cpython.sequence cimport PySequence_Fast
23
23
@@ -55,9 +55,9 @@ cdef class Matrix(Matrix0):
55
55
for i from 0 <= i < nr:
56
56
tmp = []
57
57
for j from 0 <= j < nc:
58
- tmp.append(w[i* nc + j]._pari_init_())
59
- v.append( ' ,' .join(tmp))
60
- return ' Mat([%s ])' % (' ;' .join(v))
58
+ tmp.append(w[i * nc + j]._pari_init_())
59
+ v.append(' ,' .join(tmp))
60
+ return ' Mat([%s ])' % (' ;' .join(v))
61
61
62
62
def __pari__ (self ):
63
63
"""
@@ -135,11 +135,12 @@ cdef class Matrix(Matrix0):
135
135
for i from 0 <= i < self ._nrows:
136
136
tmp = []
137
137
for j from 0 <= j < self ._ncols:
138
- tmp.append(self .get_unsafe(i,j)._gap_init_())
139
- v.append( ' [%s ]' % (' ,' .join(tmp)) )
138
+ tmp.append(self .get_unsafe(i, j)._gap_init_())
139
+ v.append(' [%s ]' % (' ,' .join(tmp)))
140
140
# It is needed to multiply with 'One(...)', because
141
141
# otherwise the result would not be a gap matrix
142
- return ' [%s ]*One(%s )' % (' ,' .join(v),sage.interfaces.gap.gap(self .base_ring()).name())
142
+ return ' [%s ]*One(%s )' % (' ,' .join(v),
143
+ sage.interfaces.gap.gap(self .base_ring()).name())
143
144
144
145
def _libgap_ (self ):
145
146
"""
@@ -261,9 +262,9 @@ cdef class Matrix(Matrix0):
261
262
for i from 0 <= i < self ._nrows:
262
263
tmp = []
263
264
for j from 0 <= j < self ._ncols:
264
- tmp.append(self .get_unsafe(i,j)._maxima_init_())
265
- v.append( ' [%s ]' % (' ,' .join(tmp)) )
266
- return ' matrix(%s )' % (' ,' .join(v))
265
+ tmp.append(self .get_unsafe(i, j)._maxima_init_())
266
+ v.append(' [%s ]' % (' ,' .join(tmp)))
267
+ return ' matrix(%s )' % (' ,' .join(v))
267
268
268
269
def _mathematica_init_ (self ):
269
270
"""
@@ -420,7 +421,7 @@ cdef class Matrix(Matrix0):
420
421
0+1r5 3
421
422
"""
422
423
P = polymake(self .parent())
423
- return polymake.new_object(P, [ list (r) for r in self .rows(copy = False ) ])
424
+ return polymake.new_object(P, [list (r) for r in self .rows(copy = False )])
424
425
425
426
def _singular_ (self , singular = None ):
426
427
"""
@@ -434,7 +435,8 @@ cdef class Matrix(Matrix0):
434
435
except (NotImplementedError , AttributeError ):
435
436
raise TypeError (" Cannot coerce to Singular" )
436
437
437
- return singular.matrix(self .nrows(),self .ncols(),singular(self .list()))
438
+ return singular.matrix(self .nrows(), self .ncols(),
439
+ singular(self .list()))
438
440
439
441
def _macaulay2_ (self , macaulay2 = None ):
440
442
"""
@@ -504,9 +506,9 @@ cdef class Matrix(Matrix0):
504
506
for i from 0 <= i < nr:
505
507
tmp = []
506
508
for j from 0 <= j < nc:
507
- tmp.append(w[i* nc + j]._pari_init_())
508
- v.append( ' ,' .join(tmp))
509
- return ' [%s ]' % (' ;' .join(v))
509
+ tmp.append(w[i * nc + j]._pari_init_())
510
+ v.append(' ,' .join(tmp))
511
+ return ' [%s ]' % (' ;' .join(v))
510
512
511
513
def _scilab_ (self , scilab = None ):
512
514
"""
@@ -657,7 +659,8 @@ cdef class Matrix(Matrix0):
657
659
entries.sort()
658
660
# We hand-format the keys to get rid of the space that would
659
661
# normally follow the comma
660
- entries = [(sib.name(' (%d ,%d )' % k), sib(v, 2 )) for k,v in entries]
662
+ entries = [(sib.name(' (%d ,%d )' % k), sib(v, 2 ))
663
+ for k, v in entries]
661
664
return sib.name(' matrix' )(self .base_ring(),
662
665
sib.int(self .nrows()),
663
666
sib.int(self .ncols()),
@@ -736,7 +739,7 @@ cdef class Matrix(Matrix0):
736
739
"""
737
740
import numpy
738
741
A = numpy.matrix(self .list(), dtype = dtype, copy = copy)
739
- return numpy.resize(A,(self .nrows(), self .ncols()))
742
+ return numpy.resize(A, (self .nrows(), self .ncols()))
740
743
741
744
def _mpmath_ (self , prec = None , rounding = None ):
742
745
"""
@@ -768,7 +771,7 @@ cdef class Matrix(Matrix0):
768
771
# Define the magic "__array__" function so that numpy.array(m) can convert
769
772
# a matrix m to a numpy array.
770
773
# See http://docs.scipy.org/doc/numpy/user/c-info.how-to-extend.html#converting-an-arbitrary-sequence-object
771
- __array__= numpy
774
+ __array__ = numpy
772
775
773
776
# ##################################################
774
777
# Construction functions
@@ -1046,14 +1049,16 @@ cdef class Matrix(Matrix0):
1046
1049
raise ValueError (msg.format(copy))
1047
1050
x = self .fetch(' columns' )
1048
1051
if x is not None :
1049
- if copy: return list (x)
1052
+ if copy:
1053
+ return list (x)
1050
1054
return x
1051
1055
if self .is_sparse():
1052
1056
columns = self .sparse_columns(copy = copy)
1053
1057
else :
1054
1058
columns = self .dense_columns(copy = copy)
1055
1059
self .cache(' columns' , columns)
1056
- if copy: return list (columns)
1060
+ if copy:
1061
+ return list (columns)
1057
1062
return columns
1058
1063
1059
1064
def rows (self , copy = True ):
@@ -1102,14 +1107,16 @@ cdef class Matrix(Matrix0):
1102
1107
raise ValueError (msg.format(copy))
1103
1108
x = self .fetch(' rows' )
1104
1109
if x is not None :
1105
- if copy: return list (x)
1110
+ if copy:
1111
+ return list (x)
1106
1112
return x
1107
1113
if self .is_sparse():
1108
1114
rows = self .sparse_rows(copy = copy)
1109
1115
else :
1110
1116
rows = self .dense_rows(copy = copy)
1111
1117
self .cache(' rows' , rows)
1112
- if copy: return list (rows)
1118
+ if copy:
1119
+ return list (rows)
1113
1120
return rows
1114
1121
1115
1122
def dense_columns (self , copy = True ):
@@ -1158,7 +1165,8 @@ cdef class Matrix(Matrix0):
1158
1165
"""
1159
1166
x = self .fetch(' dense_columns' )
1160
1167
if x is not None :
1161
- if copy: return list (x)
1168
+ if copy:
1169
+ return list (x)
1162
1170
return x
1163
1171
cdef Py_ssize_t i
1164
1172
A = self if self .is_dense() else self .dense_matrix()
@@ -1212,7 +1220,8 @@ cdef class Matrix(Matrix0):
1212
1220
"""
1213
1221
x = self .fetch(' dense_rows' )
1214
1222
if x is not None :
1215
- if copy: return list (x)
1223
+ if copy:
1224
+ return list (x)
1216
1225
return x
1217
1226
1218
1227
cdef Py_ssize_t i
@@ -1268,7 +1277,8 @@ cdef class Matrix(Matrix0):
1268
1277
"""
1269
1278
x = self .fetch(' sparse_columns' )
1270
1279
if x is not None :
1271
- if copy: return list (x)
1280
+ if copy:
1281
+ return list (x)
1272
1282
return x
1273
1283
1274
1284
cdef Py_ssize_t i, j
@@ -1350,7 +1360,8 @@ cdef class Matrix(Matrix0):
1350
1360
"""
1351
1361
x = self .fetch(' sparse_rows' )
1352
1362
if x is not None :
1353
- if copy: return list (x)
1363
+ if copy:
1364
+ return list (x)
1354
1365
return x
1355
1366
1356
1367
cdef Py_ssize_t i, j
@@ -1501,7 +1512,7 @@ cdef class Matrix(Matrix0):
1501
1512
return self .rows(copy = False )[i]
1502
1513
cdef Py_ssize_t j
1503
1514
V = self .row_ambient_module()
1504
- tmp = [self .get_unsafe(i,j) for j in range (self ._ncols)]
1515
+ tmp = [self .get_unsafe(i, j) for j in range (self ._ncols)]
1505
1516
return V(tmp, coerce = False , copy = False , check = False )
1506
1517
1507
1518
# ##########################################################################
@@ -1750,12 +1761,12 @@ cdef class Matrix(Matrix0):
1750
1761
bottom = bottom.row()
1751
1762
else :
1752
1763
raise TypeError (' a matrix must be stacked with '
1753
- ' another matrix or a vector' )
1764
+ ' another matrix or a vector' )
1754
1765
other = < Matrix?> bottom
1755
1766
1756
1767
if self ._ncols != other._ncols:
1757
1768
raise TypeError (" number of columns must be the same, not %s and %s " %
1758
- (self .ncols(), bottom.ncols()) )
1769
+ (self .ncols(), bottom.ncols()))
1759
1770
1760
1771
top_ring = self ._base_ring
1761
1772
bottom_ring = other._base_ring
@@ -1794,10 +1805,10 @@ cdef class Matrix(Matrix0):
1794
1805
cdef Py_ssize_t nr = self ._nrows
1795
1806
for r in range (self ._nrows):
1796
1807
for c in range (self ._ncols):
1797
- Z.set_unsafe(r, c, self .get_unsafe(r,c))
1808
+ Z.set_unsafe(r, c, self .get_unsafe(r, c))
1798
1809
for r in range (other._nrows):
1799
1810
for c in range (other._ncols):
1800
- Z.set_unsafe(r+ nr, c, other.get_unsafe(r,c))
1811
+ Z.set_unsafe(r + nr, c, other.get_unsafe(r, c))
1801
1812
1802
1813
return Z
1803
1814
@@ -1976,29 +1987,29 @@ cdef class Matrix(Matrix0):
1976
1987
right = right.column()
1977
1988
else :
1978
1989
raise TypeError (" a matrix must be augmented with another matrix, "
1979
- " or a vector" )
1990
+ " or a vector" )
1980
1991
1981
1992
cdef Matrix other
1982
1993
other = right
1983
1994
1984
1995
if self ._nrows != other._nrows:
1985
1996
raise TypeError (' number of rows must be the same, '
1986
- ' {0} != {1}' .format(self ._nrows, other._nrows))
1997
+ ' {0} != {1}' .format(self ._nrows, other._nrows))
1987
1998
if not (self ._base_ring is other.base_ring()):
1988
1999
other = other.change_ring(self ._base_ring)
1989
2000
1990
2001
cdef Matrix Z
1991
- Z = self .new_matrix(ncols = self ._ncols + other._ncols)
2002
+ Z = self .new_matrix(ncols = self ._ncols + other._ncols)
1992
2003
1993
2004
cdef Py_ssize_t r, c
1994
2005
for r from 0 <= r < self ._nrows:
1995
2006
for c from 0 <= c < self ._ncols:
1996
- Z.set_unsafe(r,c, self .get_unsafe(r,c))
2007
+ Z.set_unsafe(r, c, self .get_unsafe(r, c))
1997
2008
nc = self .ncols()
1998
2009
1999
2010
for r from 0 <= r < other._nrows:
2000
2011
for c from 0 <= c < other._ncols:
2001
- Z.set_unsafe(r, c+ nc, other.get_unsafe(r,c))
2012
+ Z.set_unsafe(r, c + nc, other.get_unsafe(r, c))
2002
2013
2003
2014
if subdivide:
2004
2015
Z._subdivide_on_augment(self , other)
@@ -2261,7 +2272,7 @@ cdef class Matrix(Matrix0):
2261
2272
return A
2262
2273
2263
2274
def submatrix (self , Py_ssize_t row = 0 , Py_ssize_t col = 0 ,
2264
- Py_ssize_t nrows = - 1 , Py_ssize_t ncols = - 1 ):
2275
+ Py_ssize_t nrows = - 1 , Py_ssize_t ncols = - 1 ):
2265
2276
"""
2266
2277
Return the matrix constructed from ``self`` using the specified
2267
2278
range of rows and columns.
@@ -2316,7 +2327,8 @@ cdef class Matrix(Matrix0):
2316
2327
nrows = self ._nrows - row
2317
2328
if ncols == - 1 :
2318
2329
ncols = self ._ncols - col
2319
- return self .matrix_from_rows_and_columns(range (row, row+ nrows), range (col, col+ ncols))
2330
+ return self .matrix_from_rows_and_columns(range (row, row + nrows),
2331
+ range (col, col + ncols))
2320
2332
2321
2333
def set_row (self , row , v ):
2322
2334
r """
@@ -2382,7 +2394,7 @@ cdef class Matrix(Matrix0):
2382
2394
raise ValueError (msg.format(self ._ncols, len (v)))
2383
2395
if (row < 0 ) or (row >= self ._nrows):
2384
2396
msg = " row number must be between 0 and {0} (inclusive), not {1}"
2385
- raise ValueError (msg.format(self ._nrows- 1 , row))
2397
+ raise ValueError (msg.format(self ._nrows - 1 , row))
2386
2398
2387
2399
try :
2388
2400
for j in range (self ._ncols):
@@ -2456,7 +2468,7 @@ cdef class Matrix(Matrix0):
2456
2468
raise ValueError (msg.format(self ._nrows, len (v)))
2457
2469
if (col < 0 ) or (col >= self ._ncols):
2458
2470
msg = " column number must be between 0 and {0} (inclusive), not {1}"
2459
- raise ValueError (msg.format(self ._ncols- 1 , col))
2471
+ raise ValueError (msg.format(self ._ncols - 1 , col))
2460
2472
2461
2473
try :
2462
2474
for i in range (self ._nrows):
@@ -2640,7 +2652,7 @@ cdef class Matrix(Matrix0):
2640
2652
return self
2641
2653
cdef Matrix A
2642
2654
A = self .new_matrix(self ._nrows, self ._ncols, self ,
2643
- coerce = False , sparse = False )
2655
+ coerce = False , sparse = False )
2644
2656
if self ._subdivisions is not None :
2645
2657
A.subdivide(self .subdivisions())
2646
2658
return A
@@ -2684,7 +2696,7 @@ cdef class Matrix(Matrix0):
2684
2696
if self .is_sparse():
2685
2697
return self
2686
2698
A = self .new_matrix(self ._nrows, self ._ncols, self ,
2687
- coerce = False , sparse = True )
2699
+ coerce = False , sparse = True )
2688
2700
if self ._subdivisions is not None :
2689
2701
A.subdivide(self .subdivisions())
2690
2702
return A
0 commit comments