>
> > The problem is that you can't actually mutate self into a new type.
> > The functions rescale_col/rescale_row change self, and changing the
> > basering of self is not allowed (because the storage format for
> > different baserings can be wildly different).

This makes a LOT of sense.

>
> > Not sure how the API should work, you'd need a function that returns
> > a copy of the matrix, in a new basering, with the row/col scaled.

I have tried this, but there must still be some problem similar to the
above.  I've modified the original
example below and show the problem. If I make it
temp.rescale_row_c(i, s, starcol)
it claims there is no method rescale_row_c, which I suppose has
something to do with how Cython interacts with Python.  So does this
mean that what I am trying is simply impossible, or is there another
layer of nesting required?   (I thought a function could call itself.)
I would have been surprised before, but now I'm not so sure.

>
> I think you should just change things so that the error message is
> much much better?
>
> Anyway, now you see a good reason why making ZZ matrices over QQ
> by default is a good idea!

This I can definitely do.  But it would be nice to truly have this,
because I still (in principle) want to be able to do
sage: a = matrix(3,range(9)); type(a)
<type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense>
sage: a.rescale_row(1,i/2)
and have the "correct" answer come out rather than just an error
message saying I need to change the base ring somehow.  Changing the
default ring, though a fine idea, wouldn't help here.

Thanks for the help - slowly I'm getting Python's nuances.

- kcrisman

In matrix0.pyx:

    def test(self, Py_ssize_t i, s, Py_ssize_t start_col=0):
        try:
            s = self._coerce_element(s)
        self.rescale_row_c(i, s, start_col)
        except TypeError:
            temp = self.copy()
            temp = temp.change_ring(Sequence([s,temp.base_ring()
(0)]).universe())
            print type(temp)
            return temp.test(i, s, start_col)

    cdef rescale_row_c(self, Py_ssize_t i, s, Py_ssize_t start_col):
        cdef Py_ssize_t j
        for j from start_col <= j < self._ncols:
            self.set_unsafe(i, j, self.get_unsafe(i, j)*s)

sage: a=matrix(3,range(9)); a

[0 1 2]
[3 4 5]
[6 7 8]
sage: a.temp(1, 1/2); a
<type 'sage.matrix.matrix_rational_dense.Matrix_rational_dense'>

[0 1 2]
[3 4 5]
[6 7 8]
sage: b = a.temp(1,1/2); type(b)
<type 'sage.matrix.matrix_rational_dense.Matrix_rational_dense'>
<type 'NoneType'>
--~--~---------~--~----~------------~-------~--~----~
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
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to