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

norm method does not work for sparse matrices #10116

Open
sagetrac-victor mannequin opened this issue Oct 10, 2010 · 4 comments
Open

norm method does not work for sparse matrices #10116

sagetrac-victor mannequin opened this issue Oct 10, 2010 · 4 comments

Comments

@sagetrac-victor
Copy link
Mannequin

sagetrac-victor mannequin commented Oct 10, 2010

sage: M = matrix(ZZ,4,4,sparse=True) 
sage: M.norm() 
Traceback (click to the left of this block for traceback) 
... 
AttributeError: 
'sage.matrix.matrix_generic_sparse.Matrix_generic_sparse' object has 
no 
attribute 'SVD' 
sage: M.norm(1) 
Traceback (click to the left of this block for traceback) 
... 
TypeError: base_ring (=Category of objects) must be a ring 
and similarly for any other argument to norm. 
When I do 
sage: M.base_ring() 
Integer Ring 
But if I do 
sage: M = matrix(ZZ,4,4) # without sparse=True 
everything works ok 

Upstream: Reported upstream. No feedback yet.

CC: @orlitzky

Component: linear algebra

Keywords: matrices

Author: Victor Miller

Issue created by migration from https://trac.sagemath.org/ticket/10116

@sagetrac-victor sagetrac-victor mannequin added this to the sage-5.11 milestone Oct 10, 2010
@sagetrac-victor

This comment has been minimized.

@sagetrac-hartke
Copy link
Mannequin

sagetrac-hartke mannequin commented Apr 25, 2011

comment:2

Calculating the Frobenius norm also seems problematic with sparse matrices over higher precision floating point rings. As seen in the example below, sometimes it works and sometimes it doesn't. Note that the Frobenius norm can be calculated without using the SVD.

sage: R=RealField(200)
sage: m=10
sage: A=diagonal_matrix(R,range(m))
sage: A.norm('frob')
16.8819430161
sage: A.transpose().norm('frob')
16.8819430161
sage: (A-A.transpose()).norm('frob')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/desert/hartke/apps/<ipython console> in <module>()

/home/hartke/apps/sage/local/lib/python2.6/site-packages/sage/matrix/matrix2.so in sage.matrix.matrix2.Matrix.norm (sage/matrix/matrix2.c:36319)()

/home/hartke/apps/sage/local/lib/python2.6/site-packages/sage/matrix/matrix_sparse.so in sage.matrix.matrix_sparse.Matrix_sparse.apply_map (sage/matrix/matrix_sparse.c:6433)()

/home/hartke/apps/sage/local/lib/python2.6/site-packages/sage/matrix/matrix_space.pyc in MatrixSpace(base_ring, nrows, ncols, sparse)
    179     """
    180     if not base_ring in Rings():
--> 181         raise TypeError("base_ring (=%s) must be a ring"%base_ring)
    182                                                                                                                      
    183     if ncols is None: ncols = nrows                                                                                  
                                                                                                                             
TypeError: base_ring (=Category of objects) must be a ring                                                                   
sage: type(A)                                                                                                                
<type 'sage.matrix.matrix_generic_sparse.Matrix_generic_sparse'>

@roed314
Copy link
Contributor

roed314 commented Jun 1, 2012

Changed upstream from Reported upstream. Little or no feedback. to Reported upstream. No feedback yet.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@orlitzky
Copy link
Contributor

comment:8

The lack of a sparse SVD can kill this in another way:

sage: A = matrix(RDF, 1, 1, [[1]], sparse=True)
sage: A.norm()
...
AttributeError: 'sage.matrix.matrix_generic_sparse.Matrix_generic_sparse' object has no attribute 'SVD'

@mkoeppe mkoeppe removed this from the sage-6.4 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants