Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toExternalString(MutableMatrix) #3362

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions M2/Macaulay2/m2/enginering.m2
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,12 @@ reduce := (r,s) -> (
);
(a,b))

-- printing
expression EngineRing := R -> if hasAttribute(R,ReverseDictionary) then expression getAttribute(R,ReverseDictionary) else expression toString R.RawRing -- should never be used
texMath EngineRing := R -> texMath expression R

toString EngineRing := toString @@ expression
net EngineRing := net @@ expression
net EngineRing := net @@ expression
texMath EngineRing := texMath @@ expression

ZZ _ EngineRing :=
RR _ EngineRing :=
Expand Down Expand Up @@ -279,7 +281,6 @@ coefficientRing FractionField := F -> coefficientRing last F.baseRings
dim FractionField := F -> 0
expression FractionField := F -> if hasAttribute(F,ReverseDictionary) then expression getAttribute(F,ReverseDictionary) else (expression frac) (expression last F.baseRings)
describe FractionField := F -> Describe (expression frac) (describe last F.baseRings)
toExternalString FractionField := F -> toString describe F

-- freduce := (f) -> (numerator f)/(denominator f)

Expand Down
3 changes: 0 additions & 3 deletions M2/Macaulay2/m2/galois.m2
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ needs "polyrings.m2"
GaloisField = new Type of EngineRing
GaloisField.synonym = "Galois field"

toExternalString GaloisField := k -> toString describe k
toString GaloisField := toString @@ expression
net GaloisField := net @@ expression
expression GaloisField := F -> if hasAttribute(F,ReverseDictionary) then expression getAttribute(F,ReverseDictionary) else (expression GF) (expression F.order)
describe GaloisField := F -> Describe (expression GF) (expression F.order)

Expand Down
1 change: 1 addition & 0 deletions M2/Macaulay2/m2/mutablemat.m2
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ precision MutableMatrix := precision @@ ring
expression MutableMatrix := m -> MatrixExpression append(applyTable(entries m, expression), symbol MutableMatrix => true)
texMath MutableMatrix := m -> texMath expression m
net MutableMatrix := m -> net expression m
toExternalString MutableMatrix := lookup(toExternalString, MutableHashTable)

map(Ring,RawMutableMatrix) := opts -> (R,m) -> (
new MutableMatrix from {
Expand Down
19 changes: 7 additions & 12 deletions M2/Macaulay2/m2/nets.m2
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ toExternalString Net := x -> if height x + depth x == 0 then
concatenate("(horizontalJoin())", "^", toString height x) else
concatenate(format toString x, "^", toString(height x - 1))

toExternalString MutableHashTable := s -> (
if hasAttribute(s,ReverseDictionary) then return toString getAttribute(s,ReverseDictionary);
error "anonymous mutable hash table cannot be converted to external string";
)
toExternalString Type := s -> (
if hasAttribute(s,ReverseDictionary) then return toString getAttribute(s,ReverseDictionary);
error "anonymous type cannot be converted to external string";
)
toExternalString MutableHashTable :=
toExternalString MutableList := s -> (
if hasAttribute(s,ReverseDictionary)
then toString getAttribute(s,ReverseDictionary)
else error("anonymous ", synonym class s,
" cannot be converted to external string"))

toExternalString HashTable := s -> (
concatenate (
"new ", toExternalString class s,
Expand All @@ -86,10 +85,6 @@ toExternalString HashTable := s -> (
then demark(", ", apply(pairs s, (k,v) -> toExternalString k | " => " | toExternalString v) )
else "",
"}"))
toExternalString MutableList := s -> (
error "anonymous mutable list cannot be converted to external string";
-- concatenate("new ",toExternalString class s, " from {...", toString(#s), "...}" )
)
mid := s -> (
if #s === 1 then toExternalString s#0
else between(",",apply(toSequence s,x -> if x === null then "" else toExternalString x))
Expand Down
2 changes: 0 additions & 2 deletions M2/Macaulay2/m2/polyrings.m2
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ expression PolynomialRing := R -> (
if hasAttribute(R, ReverseDictionary)
then expression getAttribute(R, ReverseDictionary)
else(expression last R.baseRings) expressionPolynomialRing R)

toExternalString PolynomialRing := toString @@ describe
-- the rest are inherited from EngineRing

-----------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion M2/Macaulay2/m2/quotring.m2
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ expression QuotientRing := S -> (
if hasAttribute(S, ReverseDictionary)
then expression getAttribute(S, ReverseDictionary)
else new Divide from { unhold expression ambient S, unhold expression printRels S })
toExternalString QuotientRing := toString @@ describe
-- TODO: add AfterPrint for QuotientRing

-----------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions M2/Macaulay2/m2/rings.m2
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ isHomogeneous Ring := R -> (
degreeLength R == 0
)

-- printing
-- technically this should not be allowed, since rings are mutable
-- and therefore "R === value toExternalString R" will always be false,
-- however, this is good enough to serialize a ring for another session.
toExternalString Ring := toString @@ describe
-- the rest of the printing methods will inherit from methods on Type

-----------------------------------------------------------------------------
-- promote, lift, liftable, and isConstant
-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion M2/Macaulay2/packages/LocalRings/doc.m2
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ importFrom_Core { "headline" }
scan({ baseRing, char, coefficientRing, degreeLength, degrees, dim, frac, generators, isCommutative, numgens },
m -> document { Key => (m, LocalRing), Headline => headline makeDocumentTag (m, Ring), PARA {"See ", TO (m, Ring)} })

undocumented apply({describe, expression, precision, presentation, toExternalString}, m -> (m, LocalRing))
undocumented apply({describe, expression, precision, presentation}, m -> (m, LocalRing))

end--

Expand Down
4 changes: 2 additions & 2 deletions M2/Macaulay2/packages/LocalRings/localring.m2
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
---------------------------------------------------------------------------

importFrom_Core {
"unhold",
"getAttribute", "hasAttribute", "ReverseDictionary", "indexStrings", "indexSymbols",
"generatorExpressions", "generatorSymbols", "commonEngineRingInitializations",
"rawFraction", "rawNumerator", "rawDenominator", "rawIsLocalUnit", "rawLocalRing" }
Expand All @@ -36,8 +37,7 @@ LocalRing#{Standard,AfterPrint} = RP -> (

localRing = method(TypicalValue => LocalRing)
describe LocalRing := RP -> Describe (expression localRing) (expression last RP.baseRings, expression RP.maxIdeal)
expression LocalRing := RP -> if hasAttribute(RP, ReverseDictionary) then expression getAttribute(RP, ReverseDictionary) else describe RP
toExternalString LocalRing:= RP -> toString describe RP
expression LocalRing := RP -> if hasAttribute(RP, ReverseDictionary) then expression getAttribute(RP, ReverseDictionary) else new FunctionApplication from unhold describe RP
coefficientRing LocalRing := RP -> coefficientRing ring RP.maxIdeal
isWellDefined LocalRing := RP -> isPrime RP.maxIdeal
isCommutative LocalRing := RP -> isCommutative ring RP.maxIdeal -- FIXME make sure this is correct
Expand Down
21 changes: 7 additions & 14 deletions M2/Macaulay2/packages/SchurRings.m2
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,14 @@ SchurRing.synonym = "Schur ring"
ClassFunction = new Type of HashTable
ClassFunction.synonym = "Class function"

expression SchurRing := S -> new FunctionApplication from { schurRing, (expression last S.baseRings, S.Symbol, S.numgens ) }
undocumented (expression, SchurRing)

toExternalString SchurRing := R -> toString expression R
undocumented (toExternalString, SchurRing),
describe SchurRing := S -> Describe (expression schurRing) (expression last S.baseRings, S.Symbol, S.numgens)
undocumented (describe, SchurRing)

toString SchurRing := R -> (
if hasAttribute(R,ReverseDictionary) then toString getAttribute(R,ReverseDictionary)
else toString expression R)
undocumented (toString, SchurRing)

net SchurRing := R -> (
if hasAttribute(R,ReverseDictionary) then toString getAttribute(R,ReverseDictionary)
else net expression R)
undocumented (net, SchurRing)
expression SchurRing := S -> (
if hasAttribute(S, ReverseDictionary)
then toString getAttribute(S, ReverseDictionary)
else new FunctionApplication from unhold describe S)
undocumented (expression, SchurRing)

rawmonom2partition = (m) -> (
reverse splice apply(rawSparseListFormMonomial m, (x,e) -> e:x)
Expand Down
Loading