+1 -- I agree 100% with David Roe's response.

On 6/28/07, David Roe <[EMAIL PROTECTED]> wrote:
> Sorry I didn't reply earlier.
>
> Implementing an is_symmetric function for matrices sounds like a good idea.
> But I think it should go in the base class: something like
>
> def is_symmetric(self):
>     if self.ncols != self.nrows:
>         return False
>     cdef int i, j:
>     for i from 1 <= i < self.nrows:
>         for j from 0 <= j < i:
>             if self[i][j] != self[j][i]:
>                 return False
>     return True
>
> One can override this in a subclass if desired: if there's some special,
> faster way to test for symmetry.  I can't think of a better method in
> general than this.
> David
>
>
>  On 6/28/07, Justin C. Walker <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > I ran into a glitch, using
> QuaternionAlgebraWithGramMatrix(field,
> > matrix):
> >    - the code verifies that the second argument is a matrix
> >      with "isinstance(Matrix)", which blows up because 'Matrix'
> >      is not known.  A simple 'import' fixes that.
> >    - then the code blows up because "is_symmetric" is not an
> >      attribute of the second arg.
> >
> > Fixing this is a bit more involved.  First, it appears that
> > "is_symmetric" is supposed to be a boolean, presumably defined when
> > the matrix is created.  There are other versions, scattered through
> > the code, of a function, but nothing in the Matrix class itself.
> >
> > Seems to me that this should be a function, not a variable (matrices
> > aren't immutable), and defined in the class.
> >
> > My question: is it reasonable to implement is_symmetric() in the
> > class definition?
> >
> > Some more questions:
> >
> > The Matrix class is a pyrex module, and checking for equality is then
> > probably best done by subclasses.  Is that correct?  Is it reasonable
> > to have a generic "it can be done in Pyrex" version that must be
> > overridden by a subclass if that assumption is false?
> >
> > Is there a better (i.e., faster) way than checking for a square
> > matrix and making n(n-1)/2 comparisons?
> >
> > Is the Matrix class undergoing reconstruction, so the above are all
> > irrelevant?  :-}
> >
> > Thanks!
> >
> > Justin
> >
> > --
> > Justin C. Walker, Curmudgeon at Large
> > Institute for the Absorption of Federal Funds
> > -----------
> > If it weren't for carbon-14, I wouldn't date at all.
> > -----------
> >
> >
> >
> >
> >
> >
>
>
>  >
>


-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://www.williamstein.org

--~--~---------~--~----~------------~-------~--~----~
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-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to