#9747: assigment to 1x1 submatrices specified by slices fails
---------------------------------+------------------------------------------
   Reporter:  phil               |       Owner:  jason, was                     
      
       Type:  defect             |      Status:  needs_review                   
      
   Priority:  major              |   Milestone:  sage-4.5.3                     
      
  Component:  linear algebra     |    Keywords:  matrix assignment slicing 
__setitem__
     Author:  Philipp Schneider  |    Upstream:  N/A                            
      
   Reviewer:                     |      Merged:                                 
      
Work_issues:                     |  
---------------------------------+------------------------------------------
Changes (by phil):

  * status:  new => needs_review


Old description:

> Assigment to 1x1 submatrices specified by slices fails:
>
> == Example ==
> {{{
> ----------------------------------------------------------------------
> | Sage Version 4.5.2, Release Date: 2010-08-05                       |
> | Type notebook() for the GUI, and license() for information.        |
> ----------------------------------------------------------------------
> sage: A=matrix([[1,2],[3,4]])
> sage: B=matrix([[1,3],[5,7]])
> sage: A[1:2,1:2]=B[1:2,1:2]
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call
> last)
>
> /Users/phil/<ipython console> in <module>()
>
> /Applications/sage/local/lib/python2.6/site-
> packages/sage/matrix/matrix0.so in sage.matrix.matrix0.Matrix.__setitem__
> (sage/matrix/matrix0.c:5926)()
>
> /Applications/sage/local/lib/python2.6/site-
> packages/sage/matrix/matrix0.so in
> sage.matrix.matrix0.Matrix._coerce_element (sage/matrix/matrix0.c:7044)()
>
> /Applications/sage/local/lib/python2.6/site-
> packages/sage/structure/parent.so in
> sage.structure.parent.Parent.__call__ (sage/structure/parent.c:6407)()
>
> /Applications/sage/local/lib/python2.6/site-
> packages/sage/structure/coerce_maps.so in
> sage.structure.coerce_maps.DefaultConvertMap_unique._call_
> (sage/structure/coerce_maps.c:3108)()
>
> /Applications/sage/local/lib/python2.6/site-
> packages/sage/structure/coerce_maps.so in
> sage.structure.coerce_maps.DefaultConvertMap_unique._call_
> (sage/structure/coerce_maps.c:3010)()
>
> /Applications/sage/local/lib/python2.6/site-
> packages/sage/rings/integer.so in sage.rings.integer.Integer.__init__
> (sage/rings/integer.c:6807)()
>
> TypeError: unable to coerce <type
> 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'> to an integer
>
> }}}
> The problem seems to be that the method !__setitem!__ treats 1x1
> submatices as elements of the rings over which the matrix is defined,
> while the method !__getitem!__ treats 1x1 submatices as 1x1 matrices.
>
> Below I will attach a patch which changes the method !__setitem!__ to
> treat 1x1 submatices specified by slices as 1x1 matrices.

New description:

 Assignment to 1x1 submatrices specified by slices fails:

 == Example ==
 {{{
 ----------------------------------------------------------------------
 | Sage Version 4.5.2, Release Date: 2010-08-05                       |
 | Type notebook() for the GUI, and license() for information.        |
 ----------------------------------------------------------------------
 sage: A=matrix([[1,2],[3,4]])
 sage: B=matrix([[1,3],[5,7]])
 sage: A[1:2,1:2]=B[1:2,1:2]
 ---------------------------------------------------------------------------
 TypeError                                 Traceback (most recent call
 last)

 /Users/phil/<ipython console> in <module>()

 /Applications/sage/local/lib/python2.6/site-
 packages/sage/matrix/matrix0.so in sage.matrix.matrix0.Matrix.__setitem__
 (sage/matrix/matrix0.c:5926)()

 /Applications/sage/local/lib/python2.6/site-
 packages/sage/matrix/matrix0.so in
 sage.matrix.matrix0.Matrix._coerce_element (sage/matrix/matrix0.c:7044)()

 /Applications/sage/local/lib/python2.6/site-
 packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__
 (sage/structure/parent.c:6407)()

 /Applications/sage/local/lib/python2.6/site-
 packages/sage/structure/coerce_maps.so in
 sage.structure.coerce_maps.DefaultConvertMap_unique._call_
 (sage/structure/coerce_maps.c:3108)()

 /Applications/sage/local/lib/python2.6/site-
 packages/sage/structure/coerce_maps.so in
 sage.structure.coerce_maps.DefaultConvertMap_unique._call_
 (sage/structure/coerce_maps.c:3010)()

 /Applications/sage/local/lib/python2.6/site-packages/sage/rings/integer.so
 in sage.rings.integer.Integer.__init__ (sage/rings/integer.c:6807)()

 TypeError: unable to coerce <type
 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'> to an integer

 }}}
 The problem seems to be that the method !__setitem!__ treats 1x1
 submatices as elements of the rings over which the matrix is defined,
 while the method !__getitem!__ treats 1x1 submatices as 1x1 matrices.

 Below I will attach a patch which changes the method !__setitem!__ to
 treat 1x1 submatices specified by slices as 1x1 matrices.

 After applying the patch assignment to submatrixes specified by slices
 works as expected:


 == Example ==

 {{{
 sage: A=matrix([[1,2],[3,4]])
 sage: B=matrix([[1,3],[5,7]])
 sage: A[1:2,1:2]=B[1:2,1:2]
 sage: A
 [1 2]
 [3 7]
 }}}

--

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