On Wed, Jul 13, 2011 at 6:51 PM, hdevalence <hdevale...@gmail.com> wrote:
> Hello,
>
> I'm having some trouble with some matrix calculations in SAGE. I'd
> like to find the kernel of some matrices, but I think I'm doing
> something wrong, because it's very slow.
>
> For example:
> sage: M = matrix(RDF, 200,400, lambda i,j: i+j)
> sage: %time M.right_kernel()
> CPU times: user 379.39 s, sys: 0.55 s, total: 379.94 s
> Wall time: 380.66 s
> Vector space of degree 400 and dimension 398 over Real Double Field
> Basis matrix:
> 398 x 400 dense matrix over Real Double Field
>
> whereas, say, this small C++ program using the Eigen2 libraries:
> #include <Eigen/Eigen>
> using namespace Eigen;
> int main()
> {
>    MatrixXd m(200,400);
>    for(int i = 0; i < 200; ++i)
>        for(int j = 0; j < 400; ++j)
>            m(i,j) = i+j;
>    LU<MatrixXd> lu(m);
>    MatrixXd ker(m.rows(), lu.dimensionOfKernel());
>    lu.computeKernel(&ker);
>    return 0;
> }
>
> does the following:
> time ./matrix
>
> real    0m0.014s
> user    0m0.000s
> sys     0m0.010s
>
> Is there something I'm missing about how to use the SAGE matrix
> classes? Five orders of magnitude faster in C++ seems a bit surprising
> to me; perhaps SAGE isn't reaching ATLAS or numpy or whatever it's
> supposed to use internally?

Sage is probably just using some completely generic general
implementation of "kernel" for matrices.
There is an SVD implementation in Sage, which computes the Singular
Value Decomposition of your matrix quickly:

sage: M = matrix(RDF, 200,400, lambda i,j: i+j)
sage: time S = M.SVD()
Time: CPU 0.10 s, Wall: 0.07 s
sage:

One can read off the kernel of a matrix from the SVD (exercise in
google or linear algebra).
Hopefully you can consider writing a little function for yourself to
do this, and even better submit
a patch to trac.sagemath.org...

http://sagemath.org/doc/developer/walk_through.html

>
> Henry de Valence
>
> --
> To post to this group, send email to sage-support@googlegroups.com
> To unsubscribe from this group, send email to 
> sage-support+unsubscr...@googlegroups.com
> For more options, visit this group at 
> http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>



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

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to