On Fri, Oct 9, 2009 at 4:28 AM, DMonniaux <[email protected]> wrote:
>
> I have very sparse systems of equations, with sparse kernels (I mean,
> if one performs Gaussian elimination, one tends to still obtain a
> sparse result). Yet when I compute the kernel matrix with Sage, I end
> up with a dense matrix:
>
> $ sage -v
> | Sage Version 4.1.1, Release Date: 2009-08-14
>
> sage: m=Matrix(QQ,100,sparse=True)
> sage: m[0,0]=1
> sage: ker=m.right_kernel(sparse=True)
> sage: ker.basis_matrix()
> 99 x 100 dense matrix over Rational Field
>
> Is this normal?
> Can I get a sparse matrix instead?

The "sparse=True" option you are passing to right_kernel isn't
implemented at all.

In fact, the way right_kernel is implemented you can make up an
options you want and they will be silently ignored:


sage: ker=m.right_kernel(foobar=True, stand_on_your_head=True,
use_the_force=True, super_sparse=True, dumb=False)

In the meantime you can get a sparse matrix as follows:

sage: ker=m.right_kernel().basis_matrix().sparse_matrix()
sage: type(ker)
<type 'sage.matrix.matrix_rational_sparse.Matrix_rational_sparse'>
sage: ker.row_module()
Sparse vector space of degree 100 and dimension 99 over Rational Field
Basis matrix:
99 x 100 sparse matrix over Rational Field

Here's the relevant code for "right_kernel", which as you can see does
nothing with sparseness...

Obviously it would be desirable for somebody to fix the right_kernel
command so one gets errors for all unused options, and all options
that should be supported are supported.


        if R.is_field():
            E = self.echelon_form(*args, **kwds)
            pivots = E.pivots()
            pivots_set = set(pivots)
            basis = []
            V = R ** self.ncols()
            ONE = R(1)
            for i in xrange(self._ncols):
                if not (i in pivots_set):
                    v = V(0)
                    v[i] = ONE
                    for r in range(len(pivots)):
                        v[pivots[r]] = -E[r,i]
                    basis.append(v)
            W = V.submodule(basis)
            if W.dimension() != len(basis):
                raise RuntimeError, "bug in right_kernel function in
matrix2.pyx -- basis from echelon form is not a basis."
            self.cache('right_kernel', W)
            return W




>
> >
>



-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to