Skip to content

Commit 49f37a7

Browse files
author
Release Manager
committed
gh-40283: Fix segmentation fault in module element multiplication Fixes #40282 . Explanation there. performance measurement. Before: ``` sage: a = vector(ZZ, 10000) sage: b = 2 sage: %timeit a*b 109 μs ± 3.03 μs per loop (mean ± std. dev. of 7 runs, 10,000 loops each) sage: %timeit a._lmul_(b) 110 μs ± 1.81 μs per loop (mean ± std. dev. of 7 runs, 10,000 loops each) ``` after: ``` sage: sage: %timeit a*b 107 μs ± 527 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each) sage: sage: %timeit a._lmul_(b) 107 μs ± 665 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each) ``` within measurement error. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #40283 Reported by: user202729 Reviewer(s): Travis Scrimshaw
2 parents dfb0821 + e51f5c7 commit 49f37a7

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/sage/modules/free_module_element.pyx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4539,8 +4539,17 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement):
45394539
sage: V = ZZ['x']^5
45404540
sage: 5 * V.0
45414541
(5, 0, 0, 0, 0)
4542+
4543+
TESTS:
4544+
4545+
Check :issue:`40282` is fixed::
4546+
4547+
sage: R.<x> = QQ[]
4548+
sage: M = span([[x, x^2+1], [1/x, x^3]], R)
4549+
sage: x * M.basis()[0]
4550+
(1, x^4)
45424551
"""
4543-
if left._parent is self._parent._base:
4552+
if left._parent is self._parent.coordinate_ring():
45444553
v = [left._mul_(<RingElement>x) for x in self._entries]
45454554
else:
45464555
v = [left * x for x in self._entries]
@@ -4555,8 +4564,17 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement):
45554564
(-2/3, 0, 2, 2/3*pi)
45564565
sage: v * (2/3) # needs sage.symbolic
45574566
(-2/3, 0, 2, 2/3*pi)
4567+
4568+
TESTS:
4569+
4570+
Check :issue:`40282` is fixed::
4571+
4572+
sage: R.<x> = QQ[]
4573+
sage: M = span([[x, x^2+1], [1/x, x^3]], R)
4574+
sage: M.basis()[0] * x
4575+
(1, x^4)
45584576
"""
4559-
if right._parent is self._parent._base:
4577+
if right._parent is self._parent.coordinate_ring():
45604578
v = [(<RingElement>x)._mul_(right) for x in self._entries]
45614579
else:
45624580
v = [x * right for x in self._entries]

0 commit comments

Comments
 (0)