#10793: Matrices can be "constructed" from matrices of wrong dimensions
------------------------------+---------------------------------------------
   Reporter:  vbraun          |       Owner:  jason, was
       Type:  defect          |      Status:  new       
   Priority:  critical        |   Milestone:  sage-4.6.2
  Component:  linear algebra  |    Keywords:            
     Author:                  |    Upstream:  N/A       
   Reviewer:                  |      Merged:            
Work_issues:                  |  
------------------------------+---------------------------------------------

Comment(by jason):

 Around line 361 in `matrix/matrix_space.py`, we see:

 {{{
         if isinstance(entries, (list, tuple)) and len(entries) > 0 and \
 sage.modules.free_module_element.is_FreeModuleElement(entries[0]):
             #Try to determine whether or not the entries should
             #be rows or columns
             if rows is None:
                 #If the matrix is square, default to rows
                 if self.__ncols == self.__nrows:
                     rows = True
                 elif len(entries[0]) == self.__ncols:
                     rows = True
                 elif len(entries[0]) == self.__nrows:
                     rows = False
                 else:
                     raise ValueError, "incorrect dimensions"

             if self.__is_sparse:
                 e = {}
                 zero = self.base_ring()(0)
                 for i in xrange(len(entries)):
                     for j, x in entries[i].iteritems():
                         if x != zero:
                             if rows:
                                 e[(i,j)] = x
                             else:
                                 e[(j,i)] = x
                 entries = e
             else:
                 entries = sum([v.list() for v in entries],[])
 }}}

 So:

 1. I think it tries to be too intelligent about guessing whether you have
 rows or columns.  That leads to inconsistent behavior when you have code
 dealing with different matrix spaces with different dimensions.

 2. It indeed does flatten the list if all else fails (that's the
 sum([v.list()... line).  I agree that that looks dangerous as well.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10793#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.

Reply via email to