Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Remove broken visualize_structure() for matrix_modn_sparse
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed Feb 11, 2016
1 parent bcb68d0 commit 2bc5dbc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 73 deletions.
6 changes: 6 additions & 0 deletions src/sage/matrix/matrix2.pyx
Expand Up @@ -8504,6 +8504,12 @@ explicitly setting the argument to `True` or `False` will avoid this message."""
sage: img.save(filename)
sage: open(filename).read().startswith('\x89PNG')
True

TESTS:

Test :trac:`17341`::

sage: random_matrix(GF(2), 8, 586, sparse=True).visualize_structure()
"""
cdef int x, y, _x, _y, v, bi, bisq
cdef int ir,ic
Expand Down
73 changes: 0 additions & 73 deletions src/sage/matrix/matrix_modn_sparse.pyx
Expand Up @@ -560,79 +560,6 @@ cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):
return list(nzp)
return nzp

def visualize_structure(self, filename=None, maxsize=512):
r"""
Write a PNG image to 'filename' which visualizes self by putting
black pixels in those positions which have nonzero entries.
White pixels are put at positions with zero entries. If 'maxsize'
is given, then the maximal dimension in either x or y direction is
set to 'maxsize' depending on which is bigger. If the image is
scaled, the darkness of the pixel reflects how many of the
represented entries are nonzero. So if e.g. one image pixel
actually represents a 2x2 submatrix, the dot is darker the more of
the four values are nonzero.
INPUT:
- ``filename`` -- String. Name of the filename to save the
resulting image.
- ``maxsize`` - integer (default: ``512``). Maximal dimension
in either x or y direction of the resulting image. If
``None`` or a maxsize larger than
``max(self.nrows(),self.ncols())`` is given the image will
have the same pixelsize as the matrix dimensions.
EXAMPLES::
sage: M = Matrix(GF(7), [[0,0,0,1,0,0,0,0],[0,1,0,0,0,0,1,0]], sparse=True); M
[0 0 0 1 0 0 0 0]
[0 1 0 0 0 0 1 0]
sage: img = M.visualize_structure(); img
8x2px 24-bit RGB image
You can use :meth:`~sage.repl.image.Image.save` to save the
resulting image::
sage: filename = tmp_filename(ext='.png')
sage: img.save(filename)
sage: open(filename).read().startswith('\x89PNG')
True
"""
cdef Py_ssize_t i, j, k
cdef float blk,invblk
cdef int delta
cdef int x,y,r,g,b
mr, mc = self.nrows(), self.ncols()
if maxsize is None:
ir = mc
ic = mr
blk = 1.0
invblk = 1.0
elif max(mr,mc) > maxsize:
maxsize = float(maxsize)
ir = int(mc * maxsize/max(mr,mc))
ic = int(mr * maxsize/max(mr,mc))
blk = max(mr,mc)/maxsize
invblk = maxsize/max(mr,mc)
else:
ir = mc
ic = mr
blk = 1.0
invblk = 1.0
delta = <int>(255.0 / blk*blk)
from sage.repl.image import Image
img = Image('RGB', (ir, ic), (255, 255, 255))
pixel = img.pixels()
for i from 0 <= i < self._nrows:
for j from 0 <= j < self.rows[i].num_nonzero:
x = <int>(invblk * self.rows[i].positions[j])
y = <int>(invblk * i)
r, g, b = pixel[x, y]
pixel[x, y] = (r-delta, g-delta, b-delta)
return img

def density(self):
"""
Return the density of self, i.e., the ratio of the number of
Expand Down

0 comments on commit 2bc5dbc

Please sign in to comment.