Opened 12 years ago

# norm method does not work for sparse matrices

Reported by: Owned by: Victor S. Miller jason, was major sage-6.4 linear algebra matrices Michael Orlitzky Victor Miller Reported upstream. No feedback yet.

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

### comment:1 Changed 12 years ago by Victor S. Miller

Description: modified (diff)

### comment:2 Changed 12 years ago by Stephen 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 11 years ago by David Roe

Report Upstream: Reported upstream. Little or no feedback. → Reported upstream. No feedback yet.

### comment:4 Changed 9 years ago by Jeroen Demeyer

Milestone: sage-5.11 → sage-5.12

### comment:5 Changed 9 years ago by For batch modifications

Milestone: sage-6.1 → sage-6.2

### comment:6 Changed 9 years ago by For batch modifications

Milestone: sage-6.2 → sage-6.3

### comment:7 Changed 8 years ago by For batch modifications

Milestone: sage-6.3 → sage-6.4

### comment:8 Changed 12 months ago by Michael Orlitzky

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