Skip to content

dumps doesn't save immutability for Matrix_mod2_dense #14681

@sagetrac-matthew-weippert

Description

@sagetrac-matthew-weippert

Dumps doesn't save immutability for matrices over GF(2).

Simple example:

z = zero_matrix(GF(2), 3)
z.set_immutable()
print(z.is_immutable())
zstr = z.dumps()
z2 = loads(zstr)
print(z2.is_immutable())

This affects saving matrices and in particular raises TypeError('mutable matrices are unhashable',) when these matrices are used in hashed collections (set/dict etc):

z = zero_matrix(GF(2), 3)
z.set_immutable()
s = set()
s.add(z)
sstr = dumps(s)
s2 = loads(sstr)

Work Around for saving:
Saving lists of matrices works just fine, so if you need to save a set or dictionary, convert to/from a list on before/after save.

CC: @tscrim

Component: linear algebra

Keywords: immutable hashable matrix GF(2)

Issue created by migration from https://trac.sagemath.org/ticket/14681

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions