Ask Your Question
1

Making a dictionary of matrices, and save the session

asked 7 years ago

Symbol 1 gravatar image

updated 2 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 7 years ago

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]

Preview: (hide)
link
1

answered 7 years ago

tmonteil gravatar image

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

Preview: (hide)
link

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: 7 years ago

Seen: 422 times

Last updated: Jan 24 '18