From 9b29e3df4df0eecae5c34e91b1460df934d79eda Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Mon, 15 Jul 2024 13:40:17 +0200 Subject: [PATCH] used ??= to cache image, coker, coimage --- M2/Macaulay2/m2/matrix1.m2 | 16 +++++++--------- M2/Macaulay2/m2/modules.m2 | 1 + 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/M2/Macaulay2/m2/matrix1.m2 b/M2/Macaulay2/m2/matrix1.m2 index bfd968fab9..26fe033633 100644 --- a/M2/Macaulay2/m2/matrix1.m2 +++ b/M2/Macaulay2/m2/matrix1.m2 @@ -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}} diff --git a/M2/Macaulay2/m2/modules.m2 b/M2/Macaulay2/m2/modules.m2 index 6c98e9b6d0..61545e352b 100644 --- a/M2/Macaulay2/m2/modules.m2 +++ b/M2/Macaulay2/m2/modules.m2 @@ -15,6 +15,7 @@ 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) +-- FIXME: can't set the typical output type because Module isn't defined yet! source Matrix := f -> f.source target Matrix := f -> f.target