Nick and Jason,

Thanks for the replies.

> 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).

I was afraid that would be the answer.  left_kernel() already has a
conditional on the field (is_NumberField( )) to decide if to call
Pari, so I've made changes there as well.  Fortunately, Pari spits out
the basis I want (the one you get from considering the non-pivot
columns).  IIRC it is an IML call in the matrix_rational_dense class
so I'll need to investigate that.  I'll poke around some more and
survey how many locations need changes to get consistent behavior.


On Feb 2, 8:22 pm, Jason Grout <jason-s...@creativetrax.com> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to