Skip to content

Commit 557c6df

Browse files
committed
Allow negative indices for submatrices of mutable matrices
We define cover(MutableMatrix) so we can just use submatrixFree (which calls cover).
1 parent 862c59c commit 557c6df

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

M2/Macaulay2/m2/mutablemat.m2

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ promote(MutableMatrix,Number) := Matrix => (f,S) -> (
9999
--------------------------------
100100
-- submatrices -----------------
101101
--------------------------------
102-
MutableMatrix _ List := Matrix => (f,v) -> submatrix(f,listZ splice v) -- get some columns
103-
MutableMatrix ^ List := Matrix => (f,v) -> submatrix(f,listZ splice v,) -- get some rows
104-
submatrix(MutableMatrix,VisibleList,VisibleList) := (m,rows,cols) -> map(ring m,rawSubmatrix(raw m, listZ toList splice rows, listZ toList splice cols))
105-
submatrix(MutableMatrix,VisibleList ) := (m,cols ) -> map(ring m,rawSubmatrix(raw m, listZ toList splice cols))
106-
submatrix(MutableMatrix,Nothing ,VisibleList) := (m,null,cols) -> submatrix(m,cols)
107-
submatrix(MutableMatrix, VisibleList, Nothing) := (m, rows, null) -> map(ring m, rawSubmatrix(raw m, listZZ rows, 0 .. numColumns m - 1))
108-
submatrix(MutableMatrix, Nothing, Nothing) := (m, null, null) -> m
102+
MutableMatrix _ List := Matrix => (f,v) -> submatrix(f, v) -- get some columns
103+
MutableMatrix ^ List := Matrix => (f,v) -> submatrix(f, v,) -- get some rows
104+
submatrix(MutableMatrix, VisibleList, VisibleList) := (m, rows, cols) -> submatrixFree(m, rows, cols)
105+
submatrix(MutableMatrix, VisibleList) := (m, cols) -> submatrixFree(m, null, cols)
106+
submatrix(MutableMatrix, Nothing, VisibleList) := (m, rows, cols) -> submatrix(m, cols)
107+
submatrix(MutableMatrix, VisibleList, Nothing) := (m, rows, cols) -> submatrixFree(m, rows, null)
108+
submatrix(MutableMatrix, Nothing, Nothing) := (m, rows, cols) -> m
109109

110110
--------------------------------
111111
numRows(RawMutableMatrix) := (m) -> rawNumberOfRows m
@@ -306,6 +306,8 @@ QRDecomposition Matrix := A -> (
306306
(Q,R) := QRDecomposition A;
307307
(matrix Q,matrix R))
308308

309+
cover MutableMatrix := MutableMatrix => identity
310+
309311
rank MutableMatrix := (M) -> (
310312
if isField ring M then
311313
rawLinAlgRank raw M

M2/Macaulay2/packages/Macaulay2Doc/functions/cover-doc.m2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ document {
88
SeeAlso => {"ambient", "super"}}
99

1010
document {
11-
Key => {(cover,Matrix)},
11+
Key => {(cover,Matrix), (cover,MutableMatrix)},
1212
Headline => "get the map between the covering free modules",
1313
Usage => "cover f",
1414
Inputs => {"f"},

M2/Macaulay2/tests/normal/mutmat.m2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@ assert(ring mutableMatrix(ZZ/101, {{1,2,3}}) === ZZ/101)
7272
M = mutableMatrix {{1, 2, 3}, {4, 5, 6}}
7373
assert Equation(target M, ZZ^2)
7474
assert Equation(source M, ZZ^3)
75+
76+
-- submatrices
77+
assert Equation(M_{0, -1}, mutableMatrix {{1, 3}, {4, 6}})
78+
assert Equation(M^{-1}, mutableMatrix {{4, 5, 6}})

0 commit comments

Comments
 (0)