On 6/21/07, Robert Bradshaw <[EMAIL PROTECTED]> wrote:
> > I am trying to write a small class which implements symmetric
> > matrices,
>
> Great
>
> > but I'm unclear how to inherit from
> > sage.matrix.matrix_dense.  How can I tell what the initialization
> > does, and how to properly call it?  I tried looking at
> > sage.matrix.matrix_integer_dense.pyx to do this, but I'm still having
> > some trouble.  I have included the class and errors below.  Thanks!


You might want to take a look at

  SAGE_ROOT/devel/sage/sage/matrix/docs.py

especially near the end which discusses in detail
what to do in order to create a new matrix type.
In particular, note the sentence "New matrices types
can only be implemented in SageX."  I think when
Robert Bradshaw and I designed and implemented
the current matrix code, we designed it in such
a way that it is impossible to directly extend
Matrix_dense and Matrix_space in pure Python.

You could extend the class Matrix_dense_generic class
though, since it is fully functional, but you probably
don't want to, since it will actually use too much
memory.

Perhaps you could list your specific goals in creating
a SymmetricIntegerMatrix class?  This would help a lot
in suggesting how it should be implemented.

 -- William


>
> The second parameter of the __init__ method of the matrix classes are
> parent (i.e. matrix spaces) rather than the ring. This is why you're
> getting the errors below. The matrix() constructor that takes a ring
> is just a convenience. I'm not sure the best way to handle symmetric
> matrices, but I'd imagine the best way to do it is to pass in a
> "shape" parameter into the matrix() function.
>
> I would probably would inherit from matrix.Matrix directly. The first
> subdivision (sparse/dense) seems to be about storage format, and this
> seems to belong at that level.
>
> - Robert
>
> >
> > ----------------------------------------------------------------------
> > ----------------------------------------------------------------------
> > ------------------
> > ----------------------------------------------------------------------
> > | SAGE Version 2.6, Release Date: 2007-06-02                         |
> > | Type notebook() for the GUI, and license() for information.        |
> > ----------------------------------------------------------------------
> > Loading SAGE library. Current Mercurial branch is: qfdevel
> > sage: SymmetricMatrix(ZZ,3, [1,2,3,4,5,6])
> > ----------------------------------------------------------------------
> > -----
> > <type 'exceptions.AttributeError'>        Traceback (most recent call
> > last)
> >
> > /Users/jonhanke/Documents/sage-2.6/<ipython console> in <module>()
> >
> > /Users/jonhanke/Documents/sage-2.6/local/lib/python2.5/site-packages/
> > sage/quadratic_forms/symmetric_matrix.py in __init__(self, R, n,
> > entries)
> >      53         """
> >      54         ## Run the parent initialization
> > ---> 55         Matrix_dense.__init__(self, R)
> >      56
> >      57         ## Set the size of the matrix
> >
> > /Users/jonhanke/Documents/sage-2.6/matrix0.pyx in
> > matrix0.Matrix.__init__()
> >
> > <type 'exceptions.AttributeError'>:
> > 'sage.rings.integer_ring.IntegerRing_class' object has no attribute
> > 'nrows'
> > sage:
> >
> > ----------------------------------------------------------------------
> > ----------------------------------------------------------------------
> > ------------------
> >
> > from sage.matrix.matrix_dense import Matrix_dense
> > from sage.rings.integer import is_Integer
> >
> > class SymmetricMatrix(Matrix_dense):
> >     """
> >     SymmetricMatrix()
> >     """
> >     def __init__(self, R, n, entries):
> >         """
> >         Initialize a symmetric matrix of a given size, and possibly
> > with given
> >         entries along its (upper-triangular) rows.
> >
> >         INPUT:
> >             R -- a ring
> >             n -- an integer n >= 0
> >             entries -- a list of entries in parent of size n*(n+1)/2
> >
> >         EXAMPLES:
> >
> >         """
> >         ## Run the parent initialization
> >         Matrix_dense.__init__(self, R)
> >
> >         ## Set the size of the matrix
> >         if is_Integer(n) and (n >= 0):
> >             self._nrows = n
> >             self._ncols = n
> >         else:
> >             raise TypeError, "Oops! The size " + str(n) + "must be a
> > non-negative integer."
> >
> >         ## Check if entries is a list for the corrent size, and if so,
> > write the upper-triangular matrix
> >         if isinstance(entries, list) and (len(entries) == n*(n+1)/2):
> >             ind = 0
> >             for i in range(n):
> >                 for j in range(i, n):
> >                     self._entries[i+j] = entries[ind]
> >                     ind += 1
> >         else:
> >             raise TypeError, "Oops! The entries " + str(entries) +
> > "must be a list of size n(n+1)/2."
> >
> >
> >
>
> >
>


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

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
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