Skip to content

Commit

Permalink
used ??= to cache image, coker, coimage
Browse files Browse the repository at this point in the history
  • Loading branch information
mahrud committed Oct 18, 2024
1 parent b0c50d2 commit 48c979d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions M2/Macaulay2/m2/matrix1.m2
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,13 @@ Matrix#AfterPrint = Matrix#AfterNoPrint = f -> (

-- precedence Matrix := x -> precedence symbol x

image Matrix := Module => f -> (
if f.cache.?image then f.cache.image else f.cache.image = subquotient(f,)
)
coimage Matrix := Module => f -> (
if f.cache.?coimage then f.cache.coimage else f.cache.coimage = cokernel inducedMap(source f, kernel f)
)
cokernel Matrix := Module => m -> (
if m.cache.?cokernel then m.cache.cokernel else m.cache.cokernel = subquotient(,m)
)
-- source and target are defined in modules.m2
-- image caches f in M.cache.Monomials
image Matrix := Module => f -> f.cache.image ??= subquotient(f, null)
cokernel Matrix := Module => f -> f.cache.cokernel ??= subquotient(null, f)
-- kernel is defined in pushforward.m2
coimage Matrix := Module => f -> f.cache.coimage ??= cokernel inducedMap(source f, kernel f)
-- homology is defined further down

cokernel RingElement := Module => f -> cokernel matrix {{f}}
image RingElement := Module => f -> image matrix {{f}}
Expand Down
4 changes: 2 additions & 2 deletions M2/Macaulay2/m2/modules.m2
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ ring Matrix := f -> (
if R =!= S then error "expected module map with source and target over the same ring";
if f.?RingMap then error "expected module map with no ring map";
R)
source Matrix := f -> f.source
target Matrix := f -> f.target
source Matrix := Module => f -> f.source
target Matrix := Module => f -> f.target

precision Matrix := precision @@ ring

Expand Down

0 comments on commit 48c979d

Please sign in to comment.