Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/sage/modules/free_module_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4553,7 +4553,7 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement):
"""
cdef list a = left._entries
cdef list b = (<FreeModuleElement_generic_dense>right)._entries
v = [(<RingElement> a[i])._add_(<RingElement> b[i]) for i in range(left._degree)]
v = [(<Element> a[i])._add_(<Element> b[i]) for i in range(left._degree)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test for v + v should be added as well, probably similarly other operations can also be tested for.

return left._new_c(v)

@cython.boundscheck(False)
Expand All @@ -4573,7 +4573,7 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement):
"""
cdef list a = left._entries
cdef list b = (<FreeModuleElement_generic_dense>right)._entries
v = [(<RingElement> a[i])._sub_(<RingElement> b[i]) for i in range(left._degree)]
v = [(<Element> a[i])._sub_(<Element> b[i]) for i in range(left._degree)]
return left._new_c(v)

cpdef _rmul_(self, Element left):
Expand All @@ -4594,7 +4594,7 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement):
(1, x^4)
"""
if left._parent is self._parent.coordinate_ring():
v = [left._mul_(<RingElement>x) for x in self._entries]
v = [left._mul_(<Element>x) for x in self._entries]
else:
v = [left * x for x in self._entries]
return self._new_c(v)
Expand All @@ -4617,9 +4617,16 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement):
sage: M = span([[x, x^2+1], [1/x, x^3]], R)
sage: M.basis()[0] * x
(1, x^4)

Check :issue:`40611` is fixed::

sage: R = cartesian_product([ZZ, ZZ])
sage: assert R in CommutativeRings()
sage: matrix(1, 1, [R.zero()]) * vector([R.zero()])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using lmul or rmul explicitly. We can have both tests - matrix * vector and vector * matrix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by lmul/rmul you likely mean testing multiply the matrix on left/right side. Calling the internal method explicitly is fine, but not possible if the method is cdef only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method being tested is cpdef _lmul_(self, Element right):, thus I believe both matrix * vector and matrix._lmul_(vector) should be tested, similar to other tests above.

((0, 0))
"""
if right._parent is self._parent.coordinate_ring():
v = [(<RingElement>x)._mul_(right) for x in self._entries]
v = [(<Element>x)._mul_(right) for x in self._entries]
else:
v = [x * right for x in self._entries]
return self._new_c(v)
Expand All @@ -4641,7 +4648,7 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement):
right = left.parent().ambient_module()(right)
cdef list a = left._entries
cdef list b = (<FreeModuleElement_generic_dense>right)._entries
v = [(<RingElement> a[i])._mul_(<RingElement> b[i]) for i in range(left._degree)]
v = [(<Element> a[i])._mul_(<Element> b[i]) for i in range(left._degree)]
return left._new_c(v)

def __reduce__(self):
Expand Down Expand Up @@ -5029,7 +5036,7 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement):
cdef dict v = dict((<FreeModuleElement_generic_sparse>right)._entries)
for i, a in left._entries.iteritems():
if i in v:
sum = (<RingElement>a)._add_(<RingElement> v[i])
sum = (<Element>a)._add_(<Element> v[i])
if sum:
v[i] = sum
else:
Expand All @@ -5049,7 +5056,7 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement):
cdef dict v = dict(left._entries) # dict to make a copy
for i, a in (<FreeModuleElement_generic_sparse>right)._entries.iteritems():
if i in v:
diff = (<RingElement> v[i])._sub_(<RingElement>a)
diff = (<Element> v[i])._sub_(<Element>a)
if diff:
v[i] = diff
else:
Expand All @@ -5069,7 +5076,7 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement):
cdef dict v = {}
if right:
for i, a in self._entries.iteritems():
prod = (<RingElement>a)._mul_(right)
prod = (<Element>a)._mul_(right)
if prod:
v[i] = prod
return self._new_c(v)
Expand Down Expand Up @@ -5155,7 +5162,7 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement):
cdef dict v = {}
for i, a in left._entries.iteritems():
if i in e:
prod = (<RingElement>a)._mul_(<RingElement> e[i])
prod = (<Element>a)._mul_(<Element> e[i])
if prod:
v[i] = prod
return left._new_c(v)
Expand Down
Loading