@@ -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,12 +739,12 @@ 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
# Define the magic "__array__" function so that numpy.array(m) can convert
742
745
# a matrix m to a numpy array.
743
746
# See http://docs.scipy.org/doc/numpy/user/c-info.how-to-extend.html#converting-an-arbitrary-sequence-object
744
- __array__= numpy
747
+ __array__ = numpy
745
748
746
749
# ##################################################
747
750
# Construction functions
@@ -1019,14 +1022,16 @@ cdef class Matrix(Matrix0):
1019
1022
raise ValueError (msg.format(copy))
1020
1023
x = self .fetch(' columns' )
1021
1024
if x is not None :
1022
- if copy: return list (x)
1025
+ if copy:
1026
+ return list (x)
1023
1027
return x
1024
1028
if self .is_sparse():
1025
1029
columns = self .sparse_columns(copy = copy)
1026
1030
else :
1027
1031
columns = self .dense_columns(copy = copy)
1028
1032
self .cache(' columns' , columns)
1029
- if copy: return list (columns)
1033
+ if copy:
1034
+ return list (columns)
1030
1035
return columns
1031
1036
1032
1037
def rows (self , copy = True ):
@@ -1075,14 +1080,16 @@ cdef class Matrix(Matrix0):
1075
1080
raise ValueError (msg.format(copy))
1076
1081
x = self .fetch(' rows' )
1077
1082
if x is not None :
1078
- if copy: return list (x)
1083
+ if copy:
1084
+ return list (x)
1079
1085
return x
1080
1086
if self .is_sparse():
1081
1087
rows = self .sparse_rows(copy = copy)
1082
1088
else :
1083
1089
rows = self .dense_rows(copy = copy)
1084
1090
self .cache(' rows' , rows)
1085
- if copy: return list (rows)
1091
+ if copy:
1092
+ return list (rows)
1086
1093
return rows
1087
1094
1088
1095
def dense_columns (self , copy = True ):
@@ -1131,7 +1138,8 @@ cdef class Matrix(Matrix0):
1131
1138
"""
1132
1139
x = self .fetch(' dense_columns' )
1133
1140
if x is not None :
1134
- if copy: return list (x)
1141
+ if copy:
1142
+ return list (x)
1135
1143
return x
1136
1144
cdef Py_ssize_t i
1137
1145
A = self if self .is_dense() else self .dense_matrix()
@@ -1185,7 +1193,8 @@ cdef class Matrix(Matrix0):
1185
1193
"""
1186
1194
x = self .fetch(' dense_rows' )
1187
1195
if x is not None :
1188
- if copy: return list (x)
1196
+ if copy:
1197
+ return list (x)
1189
1198
return x
1190
1199
1191
1200
cdef Py_ssize_t i
@@ -1241,7 +1250,8 @@ cdef class Matrix(Matrix0):
1241
1250
"""
1242
1251
x = self .fetch(' sparse_columns' )
1243
1252
if x is not None :
1244
- if copy: return list (x)
1253
+ if copy:
1254
+ return list (x)
1245
1255
return x
1246
1256
1247
1257
cdef Py_ssize_t i, j
@@ -1323,7 +1333,8 @@ cdef class Matrix(Matrix0):
1323
1333
"""
1324
1334
x = self .fetch(' sparse_rows' )
1325
1335
if x is not None :
1326
- if copy: return list (x)
1336
+ if copy:
1337
+ return list (x)
1327
1338
return x
1328
1339
1329
1340
cdef Py_ssize_t i, j
@@ -1474,7 +1485,7 @@ cdef class Matrix(Matrix0):
1474
1485
return self .rows(copy = False )[i]
1475
1486
cdef Py_ssize_t j
1476
1487
V = self .row_ambient_module()
1477
- tmp = [self .get_unsafe(i,j) for j in range (self ._ncols)]
1488
+ tmp = [self .get_unsafe(i, j) for j in range (self ._ncols)]
1478
1489
return V(tmp, coerce = False , copy = False , check = False )
1479
1490
1480
1491
# ##########################################################################
@@ -1723,12 +1734,12 @@ cdef class Matrix(Matrix0):
1723
1734
bottom = bottom.row()
1724
1735
else :
1725
1736
raise TypeError (' a matrix must be stacked with '
1726
- ' another matrix or a vector' )
1737
+ ' another matrix or a vector' )
1727
1738
other = < Matrix?> bottom
1728
1739
1729
1740
if self ._ncols != other._ncols:
1730
1741
raise TypeError (" number of columns must be the same, not %s and %s " %
1731
- (self .ncols(), bottom.ncols()) )
1742
+ (self .ncols(), bottom.ncols()))
1732
1743
1733
1744
top_ring = self ._base_ring
1734
1745
bottom_ring = other._base_ring
@@ -1767,10 +1778,10 @@ cdef class Matrix(Matrix0):
1767
1778
cdef Py_ssize_t nr = self ._nrows
1768
1779
for r in range (self ._nrows):
1769
1780
for c in range (self ._ncols):
1770
- Z.set_unsafe(r, c, self .get_unsafe(r,c))
1781
+ Z.set_unsafe(r, c, self .get_unsafe(r, c))
1771
1782
for r in range (other._nrows):
1772
1783
for c in range (other._ncols):
1773
- Z.set_unsafe(r+ nr, c, other.get_unsafe(r,c))
1784
+ Z.set_unsafe(r + nr, c, other.get_unsafe(r, c))
1774
1785
1775
1786
return Z
1776
1787
@@ -1949,29 +1960,29 @@ cdef class Matrix(Matrix0):
1949
1960
right = right.column()
1950
1961
else :
1951
1962
raise TypeError (" a matrix must be augmented with another matrix, "
1952
- " or a vector" )
1963
+ " or a vector" )
1953
1964
1954
1965
cdef Matrix other
1955
1966
other = right
1956
1967
1957
1968
if self ._nrows != other._nrows:
1958
1969
raise TypeError (' number of rows must be the same, '
1959
- ' {0} != {1}' .format(self ._nrows, other._nrows))
1970
+ ' {0} != {1}' .format(self ._nrows, other._nrows))
1960
1971
if not (self ._base_ring is other.base_ring()):
1961
1972
other = other.change_ring(self ._base_ring)
1962
1973
1963
1974
cdef Matrix Z
1964
- Z = self .new_matrix(ncols = self ._ncols + other._ncols)
1975
+ Z = self .new_matrix(ncols = self ._ncols + other._ncols)
1965
1976
1966
1977
cdef Py_ssize_t r, c
1967
1978
for r from 0 <= r < self ._nrows:
1968
1979
for c from 0 <= c < self ._ncols:
1969
- Z.set_unsafe(r,c, self .get_unsafe(r,c))
1980
+ Z.set_unsafe(r, c, self .get_unsafe(r, c))
1970
1981
nc = self .ncols()
1971
1982
1972
1983
for r from 0 <= r < other._nrows:
1973
1984
for c from 0 <= c < other._ncols:
1974
- Z.set_unsafe(r, c+ nc, other.get_unsafe(r,c))
1985
+ Z.set_unsafe(r, c + nc, other.get_unsafe(r, c))
1975
1986
1976
1987
if subdivide:
1977
1988
Z._subdivide_on_augment(self , other)
@@ -2234,7 +2245,7 @@ cdef class Matrix(Matrix0):
2234
2245
return A
2235
2246
2236
2247
def submatrix (self , Py_ssize_t row = 0 , Py_ssize_t col = 0 ,
2237
- Py_ssize_t nrows = - 1 , Py_ssize_t ncols = - 1 ):
2248
+ Py_ssize_t nrows = - 1 , Py_ssize_t ncols = - 1 ):
2238
2249
"""
2239
2250
Return the matrix constructed from ``self`` using the specified
2240
2251
range of rows and columns.
@@ -2289,7 +2300,8 @@ cdef class Matrix(Matrix0):
2289
2300
nrows = self ._nrows - row
2290
2301
if ncols == - 1 :
2291
2302
ncols = self ._ncols - col
2292
- return self .matrix_from_rows_and_columns(range (row, row+ nrows), range (col, col+ ncols))
2303
+ return self .matrix_from_rows_and_columns(range (row, row + nrows),
2304
+ range (col, col + ncols))
2293
2305
2294
2306
def set_row (self , row , v ):
2295
2307
r """
@@ -2355,7 +2367,7 @@ cdef class Matrix(Matrix0):
2355
2367
raise ValueError (msg.format(self ._ncols, len (v)))
2356
2368
if (row < 0 ) or (row >= self ._nrows):
2357
2369
msg = " row number must be between 0 and {0} (inclusive), not {1}"
2358
- raise ValueError (msg.format(self ._nrows- 1 , row))
2370
+ raise ValueError (msg.format(self ._nrows - 1 , row))
2359
2371
2360
2372
try :
2361
2373
for j in range (self ._ncols):
@@ -2429,7 +2441,7 @@ cdef class Matrix(Matrix0):
2429
2441
raise ValueError (msg.format(self ._nrows, len (v)))
2430
2442
if (col < 0 ) or (col >= self ._ncols):
2431
2443
msg = " column number must be between 0 and {0} (inclusive), not {1}"
2432
- raise ValueError (msg.format(self ._ncols- 1 , col))
2444
+ raise ValueError (msg.format(self ._ncols - 1 , col))
2433
2445
2434
2446
try :
2435
2447
for i in range (self ._nrows):
@@ -2613,7 +2625,7 @@ cdef class Matrix(Matrix0):
2613
2625
return self
2614
2626
cdef Matrix A
2615
2627
A = self .new_matrix(self ._nrows, self ._ncols, self ,
2616
- coerce = False , sparse = False )
2628
+ coerce = False , sparse = False )
2617
2629
if self ._subdivisions is not None :
2618
2630
A.subdivide(self .subdivisions())
2619
2631
return A
@@ -2657,7 +2669,7 @@ cdef class Matrix(Matrix0):
2657
2669
if self .is_sparse():
2658
2670
return self
2659
2671
A = self .new_matrix(self ._nrows, self ._ncols, self ,
2660
- coerce = False , sparse = True )
2672
+ coerce = False , sparse = True )
2661
2673
if self ._subdivisions is not None :
2662
2674
A.subdivide(self .subdivisions())
2663
2675
return A
0 commit comments