First, you're right that you don't need the "if self._initalized" line. Secondly, I'm curious as to your motivation for calling the Matrix_integer_dense directly, then calling the __init__ method later on. I would probably just create a new integer_matrix_dense in the __init__ method and (for now) treat it as a black box (for now). You don't need to worry about the fact that you're "allocating" memory in creating the integer matrix, as it will clean itself up and be garbage collected correctly. You should, however, allocate the self._relprecs in the __new__ method.
- Robert On Mar 30, 2007, at 8:34 AM, David Roe wrote: > So, I think I might want to use the __new__ function of > Matrix_integer_dense directly, but I don't really know what I'm > doing (thus contradicting the warning in the docstring for that > function). So I thought I would check with the list. > > A p-adic matrix will include an integer matrix of values. Since > I'm allocating memory, I need to do this during the __new__ phase > of creating my p-adic matrix. So I want to call > Matrix_integer_dense's __new__ method then. Here's the beginnings > of the code I'm thinking about: > > def __new__(self, parent, entries, copy, coerce): > matrix_dense.Matrix_dense.__init__(self, parent) > self._nrows = parent.nrows() > self._ncols = parent.ncols() > self._value_matrix_parent = MatrixSpace(ZZ, self._nrows, > self._ncols) > self._value_matrix = Matrix_integer_dense.__new__ > (Matrix_integer_dense, self._value_matrix_parent, 0, 0, 0) > _sig_on > self._relprecs = <uint *>sage_malloc(size_of(uint) * > (self._nrows * self._ncols)) > _sig_off > if self._relprecs == NULL: > raise MemoryError, "out of matrix allocating precisions" > > def __dealloc__(self): > self._value_matrix.__dealloc__() > if self._initialized: > sage_free(self._relprecs) #shouldn't this part always > be done, even if self is not initialized? > > def __init__(self, parent, entries, copy, coerce): > ## Call self._value_matrix.__init__ > (self._value_matrix_parent, modified_entries, copy=copy, > coerce=coerce) sometime in here. > > Am I missing something? > David > > > > --~--~---------~--~----~------------~-------~--~----~ 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/ -~----------~----~----~----~------~----~------~--~---