#13949: Make mutability on matrices a simple bint flag
---------------------------------+------------------------------------------
Reporter: nbruin | Owner: tbd
Type: PLEASE CHANGE | Status: new
Priority: major | Milestone: sage-5.6
Component: PLEASE CHANGE | Resolution:
Keywords: | Work issues:
Report Upstream: N/A | Reviewers:
Authors: | Merged in:
Dependencies: | Stopgaps:
---------------------------------+------------------------------------------
Comment (by nbruin):
Unfortunately, following `integer_dense.__cinit__` example to put a call
to `__init__` in the cinit method of `2x2` doubles the reported time taken
by
{{{
from sage.matrix.matrix_integer_2x2 import Matrix_integer_2x2 as mi2x2
M2Z = MatrixSpace(ZZ,2)
null = mi2x2(M2Z,None,false,false)
timeit("null+null")
}}}
so that's not really reasonable. However, after reading cython's
documentation, I don't think `__cinit__` should ever call `__init__`.
Those are separate initialization phases. So I think that
`sage/matrix/matrix_integer_dense.pyx:187`:
{{{
def __cinit__(self, parent, entries, coerce, copy):
...
matrix_dense.Matrix_dense.__init__(self, parent)
...
}}}
is a bug, or at least a breach of protocol. Getting to a "cinited" state
should note require `__init__` on a previous one. The `__init__` methods
get called separately, after `cinit` is done.
(incidentally, `Matrix_dense` doesn't have an `__init__`, so this is just
`Matrix.__init__` being called)
I guess the trick here is that some code can get away with avoiding
`__init__`. Then some code couldn't quite, so this line was added in as a
hack. Changeset responsible:
{{{
changeset: 2250:797bd1fc80d9
user: William Stein <[email protected]>
date: Mon Dec 18 16:06:31 2006 -0800
summary: Fast copy of matrices over ZZ.
}}}
so this is ''old''. Cython has evolved since, so perhaps the organization
here needs reconsidering. If it's absolutely necessary to create usable
matrices via `__new__`, shouldn't we just put the required initializations
in `__cinit__`? Those are guaranteed to be called, but it's generally
recommended to put off as much as possible to `__init__`.
It seems to me that `2x2` is really just following in the footsteps of the
rest of the matrix classes in only loosely following protocol for
initialization. It should just do whatever is fastest. Incidentally,
making the change as proposed on this ticket solves the initialization
problem of the mutability, since such attributes are set to 0 anyway.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13949#comment:3>
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.