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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
19 changes: 16 additions & 3 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
cdef mod_int a
if isinstance(x, xrange):
user202729 marked this conversation as resolved.
Show resolved Hide resolved
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