Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant modulo operation in vector_modn_dense #38835

Merged
merged 3 commits into from
Nov 3, 2024
Merged
Changes from 2 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
21 changes: 17 additions & 4 deletions src/sage/modules/vector_modn_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,32 @@ cdef class Vector_modn_dense(free_module_element.FreeModuleElement):
self._init(parent.degree(), parent, parent.base_ring().order())

def __init__(self, parent, x, coerce=True, copy=True):
"""
Create an element.

Note that ``coerce=False`` is dangerous::
user202729 marked this conversation as resolved.
Show resolved Hide resolved

sage: V = VectorSpace(GF(7), 3)
sage: v = V([2, 9, -5], coerce=False)
sage: v[0] == v[1]
False
sage: v[0]+1 == v[1]+1
user202729 marked this conversation as resolved.
Show resolved Hide resolved
True
sage: v[0] == v[2]
False
"""
cdef Py_ssize_t i
cdef mod_int a, p
if isinstance(x, xrange):
cdef mod_int a
if isinstance(x, range):
x = tuple(x)
if isinstance(x, (list, tuple)):
if len(x) != self._degree:
raise TypeError("x must be a list of the right length")
if coerce:
R = parent.base_ring()
p = R.order()
for i from 0 <= i < self._degree:
a = int(R(x[i]))
self._entries[i] = a % p
self._entries[i] = a
else:
for i from 0 <= i < self._degree:
self._entries[i] = x[i]
Expand Down
Loading