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

Matrix singular values #39831

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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: 2 additions & 6 deletions src/doc/en/prep/Quickstarts/Linear-Algebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,8 @@ eigenvectors.
::

sage: D,P=H.eigenmatrix_right()
sage: P*D-H*P
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
sage: P*D-H*P == matrix.zero(5)
True

Matrix Solving
---------------
Expand Down
33 changes: 33 additions & 0 deletions src/sage/libs/mpmath/ext_main.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,24 @@ cdef class mpf(mpf_base):
"""
return binop(OP_RICHCMP+op, self, other, global_opts)

def _mpfr_(self, RR):
"""
Return a Sage ``RealNumber``.

EXAMPLES::

sage: from mpmath import mpf
sage: mpf(3)._mpfr_(RealField(53))
3.00000000000000
sage: RR(mpf(3)) # indirect doctest
3.00000000000000
"""
signbit, man, exp, bc = self._mpf_
result = RR(man) << exp
if signbit:
result = -result
return result


cdef class constant(mpf_base):
"""
Expand Down Expand Up @@ -2571,6 +2589,21 @@ cdef class mpc(mpnumber):
"""
return binop(OP_RICHCMP+op, self, other, global_opts)

def _complex_mpfr_field_(self, CC):
"""
Return a Sage complex number.

EXAMPLES::

sage: from mpmath import mpc
sage: CC(mpc(1,2)) # indirect doctest
1.00000000000000 + 2.00000000000000*I
sage: mpc(1,2)._complex_mpfr_field_(CC)
1.00000000000000 + 2.00000000000000*I
"""
RR = CC._real_field()
return CC((self.real._mpfr_(RR), self.imag._mpfr_(RR)))


def hypsum_internal(int p, int q, param_types, str ztype, coeffs, z,
long prec, long wp, long epsshift, dict magnitude_check, kwargs):
Expand Down
27 changes: 27 additions & 0 deletions src/sage/matrix/matrix1.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,33 @@ cdef class Matrix(Matrix0):
A = numpy.matrix(self.list(), dtype=dtype, copy=copy)
return numpy.resize(A,(self.nrows(), self.ncols()))

def _mpmath_(self, prec=None, rounding=None):
"""
Return a ``mpmath`` matrix.

INPUT: See :meth:`sage.structure.element.Element._mpmath_`.

EXAMPLES::

sage: # needs mpmath
sage: m = matrix(SR, 2, 2, [1, 2, 3, pi])
sage: from mpmath import mp
sage: mp.dps = 30
sage: mp.matrix(m) # not tested (doesn't work yet)
sage: m._mpmath_(mp.prec)
matrix(
[['1.0', '2.0'],
['3.0', '3.14159265358979323846264338328']])
"""
if prec is None:
R = self.base_ring()
try:
prec = R.precision()
except AttributeError:
prec = 53
from mpmath import mp
return mp.matrix([[item._mpmath_(prec, rounding) for item in row] for row in self])

# Define the magic "__array__" function so that numpy.array(m) can convert
# a matrix m to a numpy array.
# See http://docs.scipy.org/doc/numpy/user/c-info.how-to-extend.html#converting-an-arbitrary-sequence-object
Expand Down
Loading
Loading