On Sat, Feb 7, 2009 at 1:58 PM, Florent Hivert
<florent.hiv...@univ-rouen.fr> wrote:
>
>      Hi
>
>> Yes, write code to workaround this case.
>
> This is mostly done except that on some ring the 0x3 matrix is considered to
> be invertible ! And also that the error messages are inconsistent: some raise
> a ValueError some raise an ArithmeticError, some says "self must be a square
> matrix" some other "matrix has to be square". Since I'm on it right now I can
> deal with it. Two questions:
>  1 - it's not clear from me which of the two error should be raised.

Regarding inverting a *square* matrix, the error should be ZeroDivisionError.
Take a lesson from Python:

>>> 1/0
Traceback (most recent call last):
...
ZeroDivisionError: integer division or modulo by zero
>>> 1.0/0.0
Traceback (most recent call last):
...
ZeroDivisionError: float division

For trying to invert a non-square matrix, I think the error should be
a ValueError, since you're inputing an improper value so that the
operation is meaningless.

>From http://docs.python.org/library/exceptions.html

exception ValueError
    Raised when a built-in operation or function receives an argument
that has the right type but an inappropriate value, and the situation
is not described by a more precise exception such as IndexError.

exception ArithmeticError
    The base class for those built-in exceptions that are raised for
various arithmetic errors: OverflowError, ZeroDivisionError,
FloatingPointError.


>  2 - to ensure coherency, it would be easier to have only one file where the
> results for different rings and data structures are handled. Do you think
> this is a good idea to have a file called says "coherency_tests.py" which
> contains only tests and not proper code ?
>
> My opinion is that this is not the right way to do. I think it fits perfectly
> into Nicolas check_... framework.  So that in the top class Matrix in
> matrix0.py one can make a check_trivial_matrices(self) methods and call check
> for all the doc. Unfortunately for this we have to wait for this device to be
> integrated. Any though ?

I don't really understand what you just wrote.
However, factoring out the preconditions for checking whether, e.g.,
__invert__ should work seems like a good idea to me.  This could be
either in another file, or just in a cpdef'd method that is defined in
matrix0.pyx.

    self._check_invert_conditions()

or something...

Using cpdef is a good idea for speed purposes.

William

--~--~---------~--~----~------------~-------~--~----~
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