# Ticket #10837: trac-10837-norms-condition-CDF-review.patch

File trac-10837-norms-condition-CDF-review.patch, 4.2 KB (added by mraum, 22 months ago)
• ## sage/matrix/matrix_double_dense.pyx

# HG changeset patch
# Parent 0f68eda0c74927c0761cd9ac93b962cd20d03bde
#10837: Fix doctest failures due to rounding errors and fix the 0-norm for vectors.

diff -r 0f68eda0c749 sage/matrix/matrix_double_dense.pyx
 a \left(\sum_{i,j}\left\lvert{a_{i,j}}\right\rvert^2\right)^{1/2} - p = 'sv': the quotient of the maximal and minimal singular value. - p = Infinity or p = oo: the maximum row sum. - p = -Infinity or p = -oo: the minimum column sum. - p = 1: the maximum column sum. sage: A = matrix(RDF, 10, [1/(i+j+1) for i in range(10) for j in range(10)]) sage: A.condition() 1.63346888329e+13 1.633...e+13 sage: id = identity_matrix(CDF, 10) sage: id.condition(p=1) 1.0 sage: A.condition() in RDF True Rectangular and singular matrices raise errors.  :: Rectangular and singular matrices raise errors if p is not 'sv'.  :: sage: A = matrix(RDF, 2, 3, range(6)) sage: A.condition() Traceback (most recent call last): ... TypeError: matrix must be square, not 2 x 3 TypeError: matrix must be square if p is not 'sv', not 2 x 3 sage: A.condition('sv') 7.34... sage: A = matrix(QQ, 5, range(25)) sage: A.is_singular() sage: A.condition(p='bogus') Traceback (most recent call last): ... ValueError: condition number 'p' must be +/- infinity, 'frob' or an integer, not bogus ValueError: condition number 'p' must be +/- infinity, 'frob', 'sv' or an integer, not bogus sage: A.condition(p=632) Traceback (most recent call last): ... sage: abs(c-d) < 1.0e-14 True """ if not self.is_square(): raise TypeError("matrix must be square, not %s x %s" % (self.nrows(), self.ncols())) if not self.is_square() and p != 'sv': raise TypeError("matrix must be square if p is not 'sv', not %s x %s" % (self.nrows(), self.ncols())) global numpy if numpy is None: import numpy p = -numpy.inf elif p == 'frob': p = 'fro' elif p == 'sv' : p = None else: try: p = sage.rings.integer.Integer(p) except: raise ValueError("condition number 'p' must be +/- infinity, 'frob' or an integer, not %s" % p) raise ValueError("condition number 'p' must be +/- infinity, 'frob', 'sv' or an integer, not %s" % p) if p not in [-2,-1,1,2]: raise ValueError("condition number integer values of 'p' must be -2, -1, 1 or 2, not %s" % p) # may raise a LinAlgError if matrix is singular
• ## sage/modules/vector_double_dense.pyx

diff -r 0f68eda0c749 sage/modules/vector_double_dense.pyx
 a sage: v.norm(p=-oo) 0.0 sage: v.norm(p=0) 8 8.0 sage: v.norm(p=0.3) 4099.153615... sage: w.norm(p=2) 13.9283882... sage: w.norm(p=0) 2 2.0 sage: w.norm(p=4.2) 13.0555695... sage: w.norm(p=oo) raise ValueError("vector norm 'p' must be +/- infinity or a real number, not %s" % p) n = numpy.linalg.norm(self._vector_numpy, ord=p) # p = 0 returns integer *count* of non-zero entries if n.dtype == numpy.int64: return sage.rings.integer.Integer(n) else: return RDF(n) return RDF(n) #############################