You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure what's the best approach here, but I think this example makes it hard to realize that three methods are really the same code:
i1 : codemethods(map, Module, List)
o1 = -- code for method: map(Module,Module,List)
../linuxbrew/.linuxbrew/share/Macaulay2/Core/matrix1.m2:93:45-158:10: --source code:map(Module,Module,List) := Matrix => options -> (M,N,p) -> (
R := ring M;
local rankN;
local k;
if N === nullthen (
k = R;
if #p === 0thenerror"expected non-empty list of entries for matrix";
rankN = #p#0;
)
elseifclass N === ZZthen (
k = R;
rankN = N;
)
else (
k = ring N;
trypromote(1_k,R) elseerror"modules over incompatible rings";
-- later, allow a ring homomorphism
rankN = numgens N;
);
ifnotinstance(N,Module) andoptions.Degree =!= nullthenerror"Degree option given with indeterminate source module";
deg := ifoptions.Degree === nullthentoList ((degreeLength R):0) elseoptions.Degree;
deg = degreeCheck(deg,R);
p = splice p;
ifall(p, o -> (
instance(o,Option)
and #o == 2andclass o#0 === Sequenceand #o#0 == 2andclass o#0#0 === ZZandclass o#0#1 === ZZ
)
) then ( -- sparse list of entries
rows := apply(p, o -> o#0#0);
cols := apply(p, o -> o#0#1);
ents := toSequenceapply(p, o -> raw promote(o#1,R));
pref := 0; -- ???
m := (
ifclass N === Modulethen rawSparseMatrix2(raw cover M, raw cover N, deg, rows, cols, ents, pref)
else rawSparseMatrix1(raw cover M, rankN, rows, cols, ents, pref)
);
newMatrixfrom {
symboltarget => M,
symbol RawMatrix => reduce(M,m),
symbolsource => ifclass N === Modulethen N elsenewModulefrom (R, rawSource m),
symbolring => R,
symbolcache => newCacheTable
})
elseifall(p, o -> instance(o,List)) then ( -- dense list of entries or blocks
p = apply(splice p,splice);
if #p != numgens M or #p > 0and ( notisTable p or # p#0 != rankN )
thenerror( "expected ", toStringnumgens M, " by ", toString rankN, " table");
p = toSequence makeRawTable(R,p);
h := (
ifinstance(N,Module)
then rawMatrix2(raw cover M, raw cover N, deg, flatten p,0)
else rawMatrix1(raw cover M, rankN, flatten p, 0)
);
newMatrixfrom {
symboltarget => M,
symbol RawMatrix => reduce(M,h),
symbolsource => ifclass N === Modulethen N elsenewModulefrom (R, rawSource h),
symbolring => R,
symbolcache => newCacheTable
})
elseerror"expected a list of lists or a list of options (i,j)=>r")
--------------------------------------------------------------------------------------------------------------------------- code for method: map(Module,Module,RingMap,List)
../linuxbrew/.linuxbrew/share/Macaulay2/Core/ringmap.m2:568:47-568:94: --source code:map(Module,Module,RingMap,List) := Matrix => o -> (M,N,p,f) -> map(M,N,p,map(M,ring M ** N,f),o)
--------------------------------------------------------------------------------------------------------------------------- code for method: map(Module,Nothing,List)
../linuxbrew/.linuxbrew/share/Macaulay2/Core/matrix1.m2:93:45-158:10: --source code:map(Module,Module,List) := Matrix => options -> (M,N,p) -> (
R := ring M;
local rankN;
local k;
if N === nullthen (
k = R;
if #p === 0thenerror"expected non-empty list of entries for matrix";
rankN = #p#0;
)
elseifclass N === ZZthen (
k = R;
rankN = N;
)
else (
k = ring N;
trypromote(1_k,R) elseerror"modules over incompatible rings";
-- later, allow a ring homomorphism
rankN = numgens N;
);
ifnotinstance(N,Module) andoptions.Degree =!= nullthenerror"Degree option given with indeterminate source module";
deg := ifoptions.Degree === nullthentoList ((degreeLength R):0) elseoptions.Degree;
deg = degreeCheck(deg,R);
p = splice p;
ifall(p, o -> (
instance(o,Option)
and #o == 2andclass o#0 === Sequenceand #o#0 == 2andclass o#0#0 === ZZandclass o#0#1 === ZZ
)
) then ( -- sparse list of entries
rows := apply(p, o -> o#0#0);
cols := apply(p, o -> o#0#1);
ents := toSequenceapply(p, o -> raw promote(o#1,R));
pref := 0; -- ???
m := (
ifclass N === Modulethen rawSparseMatrix2(raw cover M, raw cover N, deg, rows, cols, ents, pref)
else rawSparseMatrix1(raw cover M, rankN, rows, cols, ents, pref)
);
newMatrixfrom {
symboltarget => M,
symbol RawMatrix => reduce(M,m),
symbolsource => ifclass N === Modulethen N elsenewModulefrom (R, rawSource m),
symbolring => R,
symbolcache => newCacheTable
})
elseifall(p, o -> instance(o,List)) then ( -- dense list of entries or blocks
p = apply(splice p,splice);
if #p != numgens M or #p > 0and ( notisTable p or # p#0 != rankN )
thenerror( "expected ", toStringnumgens M, " by ", toString rankN, " table");
p = toSequence makeRawTable(R,p);
h := (
ifinstance(N,Module)
then rawMatrix2(raw cover M, raw cover N, deg, flatten p,0)
else rawMatrix1(raw cover M, rankN, flatten p, 0)
);
newMatrixfrom {
symboltarget => M,
symbol RawMatrix => reduce(M,h),
symbolsource => ifclass N === Modulethen N elsenewModulefrom (R, rawSource h),
symbolring => R,
symbolcache => newCacheTable
})
elseerror"expected a list of lists or a list of options (i,j)=>r")
--------------------------------------------------------------------------------------------------------------------------- code for method: map(Module,Nothing,RingMap,List)
../linuxbrew/.linuxbrew/share/Macaulay2/Core/ringmap.m2:569:48-569:84: --source code:map(Module,Nothing,RingMap,List) := Matrix => o -> (M,N,p,f) -> map(M,N,p,map(M,,f),o)
--------------------------------------------------------------------------------------------------------------------------- code for method: map(Module,ZZ,List)
../linuxbrew/.linuxbrew/share/Macaulay2/Core/matrix1.m2:93:45-158:10: --source code:map(Module,Module,List) := Matrix => options -> (M,N,p) -> (
R := ring M;
local rankN;
local k;
if N === nullthen (
k = R;
if #p === 0thenerror"expected non-empty list of entries for matrix";
rankN = #p#0;
)
elseifclass N === ZZthen (
k = R;
rankN = N;
)
else (
k = ring N;
trypromote(1_k,R) elseerror"modules over incompatible rings";
-- later, allow a ring homomorphism
rankN = numgens N;
);
ifnotinstance(N,Module) andoptions.Degree =!= nullthenerror"Degree option given with indeterminate source module";
deg := ifoptions.Degree === nullthentoList ((degreeLength R):0) elseoptions.Degree;
deg = degreeCheck(deg,R);
p = splice p;
ifall(p, o -> (
instance(o,Option)
and #o == 2andclass o#0 === Sequenceand #o#0 == 2andclass o#0#0 === ZZandclass o#0#1 === ZZ
)
) then ( -- sparse list of entries
rows := apply(p, o -> o#0#0);
cols := apply(p, o -> o#0#1);
ents := toSequenceapply(p, o -> raw promote(o#1,R));
pref := 0; -- ???
m := (
ifclass N === Modulethen rawSparseMatrix2(raw cover M, raw cover N, deg, rows, cols, ents, pref)
else rawSparseMatrix1(raw cover M, rankN, rows, cols, ents, pref)
);
newMatrixfrom {
symboltarget => M,
symbol RawMatrix => reduce(M,m),
symbolsource => ifclass N === Modulethen N elsenewModulefrom (R, rawSource m),
symbolring => R,
symbolcache => newCacheTable
})
elseifall(p, o -> instance(o,List)) then ( -- dense list of entries or blocks
p = apply(splice p,splice);
if #p != numgens M or #p > 0and ( notisTable p or # p#0 != rankN )
thenerror( "expected ", toStringnumgens M, " by ", toString rankN, " table");
p = toSequence makeRawTable(R,p);
h := (
ifinstance(N,Module)
then rawMatrix2(raw cover M, raw cover N, deg, flatten p,0)
else rawMatrix1(raw cover M, rankN, flatten p, 0)
);
newMatrixfrom {
symboltarget => M,
symbol RawMatrix => reduce(M,h),
symbolsource => ifclass N === Modulethen N elsenewModulefrom (R, rawSource h),
symbolring => R,
symbolcache => newCacheTable
})
elseerror"expected a list of lists or a list of options (i,j)=>r")
I'm not sure what's the best approach here, but I think this example makes it hard to realize that three methods are really the same code:
Notice:
The text was updated successfully, but these errors were encountered: