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

Fix matrix coercion with numpy 2.1 #38683

Merged
merged 3 commits into from
Sep 22, 2024
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
8 changes: 6 additions & 2 deletions src/sage/matrix/matrix1.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ cdef class Matrix(Matrix0):
entries = [[sib(v, 2) for v in row] for row in self.rows()]
return sib.name('matrix')(self.base_ring(), entries)

def numpy(self, dtype=None):
def numpy(self, dtype=None, copy=True):
"""
Return the Numpy matrix associated to this matrix.

Expand All @@ -680,6 +680,10 @@ cdef class Matrix(Matrix0):
then the type will be determined as the minimum type required
to hold the objects in the sequence.

- ``copy`` -- if `self` is already an `ndarray`, then this flag
determines whether the data is copied (the default), or whether
a view is constructed.

EXAMPLES::

sage: # needs numpy
Expand Down Expand Up @@ -731,7 +735,7 @@ cdef class Matrix(Matrix0):
(3, 4)
"""
import numpy
A = numpy.matrix(self.list(), dtype=dtype)
A = numpy.matrix(self.list(), dtype=dtype, copy=copy)
return numpy.resize(A,(self.nrows(), self.ncols()))

# Define the magic "__array__" function so that numpy.array(m) can convert
Expand Down
Loading