Opened 11 years ago

Last modified 2 months ago

#10116 new defect

norm method does not work for sparse matrices

Reported by: victor Owned by: jason, was
Priority: major Milestone: sage-6.4
Component: linear algebra Keywords: matrices
Cc: mjo Merged in:
Authors: Victor Miller Reviewers:
Report Upstream: Reported upstream. No feedback yet. Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by victor)

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 

Change History (9)

comment:1 Changed 11 years ago by victor

  • Description modified (diff)

comment:2 Changed 11 years ago by hartke

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'>

comment:3 Changed 10 years ago by roed

  • Report Upstream changed from Reported upstream. Little or no feedback. to Reported upstream. No feedback yet.

comment:4 Changed 8 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:5 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:6 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:7 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:8 Changed 2 months ago by mjo

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'

comment:9 Changed 2 months ago by mjo

  • Cc mjo added
Note: See TracTickets for help on using tickets.