Ask Your Question
1

Making a dictionary of matrices, and save the session

asked 2018-01-24 01:32:17 +0100

Symbol 1 gravatar image

updated 2023-01-09 23:59:45 +0100

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
2

answered 2018-01-24 12:50:56 +0100

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
1

answered 2018-01-24 14:05:25 +0100

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-24 01:32:17 +0100

Seen: 412 times

Last updated: Jan 24 '18