Robert Bradshaw wrote:
> On Apr 7, 2008, at 10:07 AM, Jason Grout wrote:
>> In trying to unify the linear algebra syntax, I came across the
>> following behavior:
>>
>>
>> sage: a=matrix(2,range(4))
>> sage: a.nrows()
>> 2
>> sage: a._nrows
>> ---------------------------------------------------------------------- 
>> -----
>> <type 'exceptions.AttributeError'>        Traceback (most recent  
>> call last)
>>
>> /home/grout/sage/devel/sage-main/sage/misc/<ipython console> in  
>> <module>()
>>
>> <type 'exceptions.AttributeError'>:
>> 'sage.matrix.matrix_integer_dense.Matrix_integer_de' object has no
>> attribute '_nrows'
>> sage: a.__dict__
>> ---------------------------------------------------------------------- 
>> -----
>> <type 'exceptions.AttributeError'>        Traceback (most recent  
>> call last)
>>
>> /home/grout/sage/devel/sage-main/sage/misc/<ipython console> in  
>> <module>()
>>
>> <type 'exceptions.AttributeError'>:
>> 'sage.matrix.matrix_integer_dense.Matrix_integer_de' object has no
>> attribute '__dict__'
>>
>>
>> I noted that the nrows() function just returned self._nrows.  So how
>> come I can't access _nrows?  Does it have to do with Cython and  
>> inheritance?
> 
> Yes, this is a Cython vs. Python issue. a._nrows is literally a c int  
> in the object structure, not a member of a dictionary. In fact,  
> Cython classes don't even have dictionaries. From Cython a._nrows is  
> probably on the order of two or three magnitudes faster than a.nrows()
> 
> We could declare _nrows and _ncols to be readonly, in which case a  
> __getattr__ (or more technically a property accessor method) method  
> would be created for them.

Thanks for the explanation.  The issue came up when I wanted to just do 
M=self.transpose() or M=self, depending on if the user wanted right or 
left action computations (e.g., right vs. left kernels).  However, then 
calls to M._nrows (which used to be calls to self._nrows) don't work.

I'll just set an M_nrows variable to either self._nrows or self._ncols, 
whichever is needed.  That way we still have the order-of-magnitude 
speedup.  Unless someone has a better idea.

Thanks,

Jason


--~--~---------~--~----~------------~-------~--~----~
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://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to