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.

- Robert


--~--~---------~--~----~------------~-------~--~----~
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