`_acted_upon_` computes result twice

26 views
Skip to first unread message

Jonathan Kliem

unread,
Jun 9, 2020, 10:34:08 AM6/9/20
to sage-devel
If I act upon a polyhedron, the result is computed twice. Why does this happen, how can one avoid this?

Currently, in `Polyhedron_base` (the element class) the method `_acted_upon_` is defined, which is where the action is discovered.

In the following example, I try to act on a polyhedron with a matrix. If I first discover the action, I'm much faster than when I just plainly multiply.

The reason is that for discovering action manually, the method `an_element` of parent is used. Very smart, because this is an almost trivial element just to make things work.

However, if I just plainly multiply, it is not done this way. Instead it computes the result twice. Why?

Thank you,

Jonathan

sage: P = polytopes.permutahedron(6)
sage
: M = matrix(P.base_ring(), P.dim(), P.ambient_dim(),
....:                         [v.vector() - P.an_affine_basis()[0].vector() for v in P.an_affine_basis()[1:]])
sage
: %time coercion_model.analyse(M, P)
CPU times
: user 18.5 ms, sys: 0 ns, total: 18.5 ms
Wall time: 17.5 ms
(['Action discovered.',
 
Left action by Full MatrixSpace of 5 by 6 dense matrices over Integer Ring on Polyhedra in ZZ^6],
 
Polyhedra in ZZ^5)
sage
: %time M*P
CPU times
: user 137 ms, sys: 3.39 ms, total: 141 ms
Wall time: 140 ms
A
5-dimensional polyhedron in ZZ^5 defined as the convex hull of 720 vertices


sage
: coercion_model.reset_cache()
sage
: %time M*P
CPU times
: user 256 ms, sys: 3.53 ms, total: 260 ms
Wall time: 259 ms
A
5-dimensional polyhedron in ZZ^5 defined as the convex hull of 720 vertices
Reply all
Reply to author
Forward
0 new messages