#13949: Make mutability on matrices a simple bint flag
----------------------------------+-----------------------------------------
       Reporter:  nbruin          |         Owner:  jason, was
           Type:  enhancement     |        Status:  new       
       Priority:  major           |     Milestone:  sage-5.6  
      Component:  linear algebra  |    Resolution:            
       Keywords:                  |   Work issues:            
Report Upstream:  N/A             |     Reviewers:            
        Authors:                  |     Merged in:            
   Dependencies:                  |      Stopgaps:            
----------------------------------+-----------------------------------------

Comment (by nbruin):

 Just some notes here. In order to make usable matrices from just
 `Matrix.__new__()`, i.e., without running `__init__` we'd need to move
 some things into `Matrix.__cinit__`. The main things there are:
 {{{
         self._immutability = False
         self._cache = None
         self._parent = parent
         self._base_ring = parent.base_ring()
         self._nrows = parent.nrows()
         self._ncols = parent.ncols()
 }}}
 The first 3 instructions are fast and could be moved into
 `matrix.__cinit__` (which doesn't exist at the moment), except that some
 matrix routines call `__new__` with `parent=NULL`. They set the parent
 themselves manually afterwards. We could fix that. However, if they have
 to muck about with `_base_ring` and `_nrows,_ncols` anyway, there's not
 much to win.

 The last 3 instructions are slow, of course, because they require full-
 blown method resolutions. Many matrix subclasses can be more efficient
 about those, so it's probably good to leave those in the avoidable
 `__init__` rather than the unavoidable `__cinit__`.

 Note that the first two instructions are not necessary: Those are the
 values to which those attributes get initialized by cython already.

 The following might be reasonable:
  - Change `mutability` to a `bint` flag, as proposed to this ticket. It
 means that a mutable matrix doesn't need to touch that flag at all upon
 initialization!
  - matrix classes can avoid the base class `matrix.__init__` as long as
 they set `_parent`, `_base_ring`, `_nrows`, `_ncols` themselves.

 This is largely how currently things work, except for
 `Matrix_integer_dense`, where the `__cinit__` calls
 `Matrix_dense.__init__` already. Hence, if you inherit from
 `Matrix_integer_dense`, you cannot get super efficient `__new__` anymore.

 This is of course silly, because already setting `self._base_ring` is
 something this class could do very efficiently. So, probably this call to
 `Matrix_dense` should be removed, setting `self._base_ring` can be done in
 `Matrix_integer_dense.__cinit__` directly (because it's just `ZZ`), and
 setting `nrows` and `ncols` should probably be done explicitly (in most
 cases you KNOW how big the matrix is)

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13949#comment:6>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
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-trac?hl=en.

Reply via email to