Currently AffineGroup elements do not implement hash and so can not be used as dictionary keys.
Currently the internal variables of AffineGroupElement are mutable, but the matrix method is cached suggesting that the values are expected to be immutable. This makes it possible to produce (far fetched) bugs where matrix returns something incompatible with the current state of the transformation:
sage: from sage.groups.affine_gps.affine_group import AffineGroup
sage: G = AffineGroup(2, QQ)
sage: G
Affine Group of degree 2 over Rational Field
sage: g = G([[1, 2], [3, 4]], [5,6])
sage: g.matrix()
[1 2|5]
[3 4|6]
[---+-]
[0 0|1]
sage: g.A()[0,0] = 9
sage: g.A()[0,0] = 9
sage: g
[9 2] [5]
x |-> [3 4] x + [6]
sage: g.matrix()
[1 2|5]
[3 4|6]
[---+-]
[0 0|1]
sage: hash(g)
TypeError
Proposed Solution
Make affine group elements immutable by calling set_immutable() on the parameters _A and _b in the constructor.
Implement a hash.
Alternatives Considered
If mutability is desired (for some reason I'm not aware of), then the matrix method should not be cached to avoid the bug above. In this case, I would imagine we'd also want to implement something explaining how to change the values.
Additional Information
No response
Is there an existing issue for this?
[X] I have searched the existing issues for a bug report that matches the one I want to file, without success.
Problem Description
Currently
AffineGroup
elements do not implement hash and so can not be used as dictionary keys.Currently the internal variables of
AffineGroupElement
are mutable, but thematrix
method is cached suggesting that the values are expected to be immutable. This makes it possible to produce (far fetched) bugs wherematrix
returns something incompatible with the current state of the transformation:Proposed Solution
set_immutable()
on the parameters_A
and_b
in the constructor.Alternatives Considered
If mutability is desired (for some reason I'm not aware of), then the
matrix
method should not be cached to avoid the bug above. In this case, I would imagine we'd also want to implement something explaining how to change the values.Additional Information
No response
Is there an existing issue for this?