Rob Beezer wrote: > I am trying to add some functionality to the matrix kernel routines > (and I'm learning more about contributing to SAGE along the way). > Briefly, I want to make some alternative bases possible as output. In > matrix/matrix2.pyx, there are three methods defined for a matrix: > kernel(), left_kernel() and right_kernel(). > > The left_kernel() function contains most of the code. > The kernel() function is defined by the single line: kernel = > left_kernel > The right_kernel() function essentially forms the transpose and then > calls kernel() on that. > > I have a new keyword added to the left_kernel() function and new code > working they way I think it should. However, if I try the following > (not showing the use of the new keyword) > > sage: a=matrix(QQ, [[1,2],[3,4]]) > sage: a.right_kernel() > > it would appear that that the call to kernel() in right_kernel() uses
Since the matrix is of type sage: a=matrix(QQ, [[1,2],[3,4]]) sage: type(a) <type 'sage.matrix.matrix_rational_dense.Matrix_rational_dense'> it first tries to call the right_kernel function in matrix_rational_dense.pyx. That function does not exist, so it falls back to the right_kernel function in matrix2.pyx. That right_kernel function in turn calls the kernel function on the (transpose of) the matrix. First, python looks for the kernel function on the more specific class (matrix_rational_dense.Matrix_rational_dense). Since that class has a kernel function, it is the one that is called. > the version of kernel() defined for dense rational matrices (as > perhaps it should), and not the modified version of left_kernel() > nearby (as the code locally might suggest one to expect). If I edit > right_kernel() to call left_kernel() on the transpose() then I see the > effect of my modifications to the left_kernel() code. This is because the Matrix_rational_dense class does not have a "left_kernel" function, so python falls back to the function in matrix2.pyx. The key ideas here involve inheritance in object-oriented programming. > > Is it "safe" to modify right_kernel() to call left_kernel()? As I > chase my way around, I see calls that compute kernels using algorithms > in Pari, IML, etc, so I'm hesitant to make changes with far-reaching > effects. Thanks in advance for the advice. Probably not. It seems like the purpose for the specialized kernel function for QQ matrices is that it works much better than the generic function. In this case, it seems like the best way to do things is to modify both the function in matrix2.pyx (for general matrices) and the function in matrix_rational_dense.pyx (for QQ matrices). Thanks, Jason --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---