Ask Your Question
1

Making a dictionary of matrices, and save the session

asked 2018-01-23 18:32:17 -0500

Symbol 1 gravatar image

updated 2018-01-24 07:05:44 -0500

tmonteil gravatar image

Some time ago I made a dictionary of matrices with your help.

Now I like to save the session by save_session() but somehow I fail. The terminal goes as follows

sage: A=matrix(GF(2),[[1,0],[0,1]])
sage: A.set_immutable()
sage: dictA={A:1}
sage: save_session(verbose=true)
Saving A
Not saving dictA: mutable matrices are unhashable

On the other hand

sage: A=matrix([[1,0],[0,1]])
sage: A.set_immutable()
sage: dictA={A:1}
sage: save_session(verbose=true)
Saving A
Saving dictA

I have no idea why specifying GF(2) fails save_session(). Does anyone know a fix?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2018-01-24 05:50:56 -0500

nbruin gravatar image

I think this is just a bug

sage: A=matrix(GF(2),[[1,0],[0,1]])
sage: B=matrix(ZZ,[[1,0],[0,1]])
sage: A.set_immutable()
sage: B.set_immutable()
sage: loads(dumps(A)).is_immutable()
False
sage: loads(dumps(B)).is_immutable()
True

Clearly, matrices over GF(2) do not preserve their immutability upon pickle/unpickle. The bug seems specific to matrices over GF(2) [which indeed have a separate optimized implementation]

edit flag offensive delete link more
0

answered 2018-01-24 07:05:25 -0500

tmonteil gravatar image

Thanks you both @Symbol and @nbruin for reporting, this is trac ticket 24589.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-01-23 18:32:17 -0500

Seen: 37 times

Last updated: Jan 24