diff --git a/src/sage/modules/vector_modn_dense.pyx b/src/sage/modules/vector_modn_dense.pyx index 79e27b5b3b9..f129632bd03 100644 --- a/src/sage/modules/vector_modn_dense.pyx +++ b/src/sage/modules/vector_modn_dense.pyx @@ -168,19 +168,34 @@ 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. + + TESTS: + + Note that ``coerce=False`` is dangerous:: + + 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 + 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]