Skip to content

Commit b625a14

Browse files
author
Release Manager
committed
gh-38938: Sanity check parent of Vector_numpy_integer_dense As in the title. This appears to be what the author intend it to be, previously it's possible to construct with base_ring not ZZ but the elements being returned are ZZ anyway. (plus `self._sage_dtype = ZZ`.) ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #38938 Reported by: user202729 Reviewer(s): Travis Scrimshaw
2 parents 258a39a + 43b8c00 commit b625a14

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/sage/modules/vector_numpy_integer_dense.pyx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ EXAMPLES::
1313
sage: v.numpy()
1414
array([ 0, 42, 0]) # 64-bit
1515
array([ 0, 42, 0], dtype=int64) # 32-bit
16+
17+
TESTS::
18+
19+
sage: Vector_numpy_integer_dense(FreeModule(GF(2), 3), [0, 0, 0])
20+
Traceback (most recent call last):
21+
...
22+
ValueError: parent must have base ring ZZ
1623
"""
1724

1825
# ****************************************************************************
@@ -36,6 +43,8 @@ numpy.import_array()
3643
cdef class Vector_numpy_integer_dense(Vector_numpy_dense):
3744

3845
def __cinit__(self, parent, entries, coerce=True, copy=True):
46+
if parent.base_ring() is not ZZ:
47+
raise ValueError("parent must have base ring ZZ")
3948
self._numpy_dtype = numpy.dtype('int64')
4049
self._numpy_dtypeint = numpy.NPY_INT64
4150
self._python_dtype = int

0 commit comments

Comments
 (0)