Sage: Ticket #3838: [with patch, positive review] Element access for RElement
https://trac.sagemath.org/ticket/3838
<p>
On <a class="ext-link" href="http://groups.google.com/group/sage-support/browse_thread/thread/4868d601510e9642?hl=en"><span class="icon"></span>http://groups.google.com/group/sage-support/browse_thread/thread/4868d601510e9642?hl=en</a>, Alexandr Batalshikov pointed out that
</p>
<pre class="wiki">> v = c(3,5,9,1)
> v[c(2,3)]
[1] 5 9
</pre><p>
works in R, but the corresponding statement in Sage does not:
</p>
<pre class="wiki">sage: v = r.c(3,5,9,1)
sage: n = r.c(2,3)
sage: v[n]
[1] 3
</pre><p>
I believe this is a defect. With the attached patch, the following works:
</p>
<pre class="wiki">sage: v = r.c(3,5,9,1)
sage: n = r.c(2,3)
sage: v[n]
[1] 5 9
sage: v[-2]
[1] 3 9 1
sage: v['c(2,3)']
[1] 5 9
sage: v[2,4,3]
[1] 5 1 9
sage: v[2]
[1] 5
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/3838
Trac 1.1.6SimonKingWed, 13 Aug 2008 17:27:53 GMTattachment set
https://trac.sagemath.org/ticket/3838
https://trac.sagemath.org/ticket/3838
<ul>
<li><strong>attachment</strong>
set to <em>RElementAccess.patch</em>
</li>
</ul>
<p>
Patch relative to 3.1.alpha0
</p>
TicketmabshoffWed, 13 Aug 2008 17:29:16 GMTsummary changed
https://trac.sagemath.org/ticket/3838#comment:1
https://trac.sagemath.org/ticket/3838#comment:1
<ul>
<li><strong>summary</strong>
changed from <em>Element access for RElement</em> to <em>[with patch, needs review] Element access for RElement</em>
</li>
</ul>
TicketSimonKingWed, 13 Aug 2008 20:00:50 GMTattachment set
https://trac.sagemath.org/ticket/3838
https://trac.sagemath.org/ticket/3838
<ul>
<li><strong>attachment</strong>
set to <em>RElementAccess2.patch</em>
</li>
</ul>
<p>
Correction for the first patch
</p>
TicketSimonKingWed, 13 Aug 2008 20:02:04 GMT
https://trac.sagemath.org/ticket/3838#comment:2
https://trac.sagemath.org/ticket/3838#comment:2
<p>
I just realized that it is not a good idea to make <code>v[2,3]</code> return a vector, because if <code>v</code> is an array, <code>v[2,3]</code> should return a single entry of the array.
</p>
<p>
The new patch (that should be applied after the first one) takes this into account. Now we have:
</p>
<pre class="wiki">sage: v = r.c(3,5,9,1)
sage: n = r.c(2,3)
sage: v[n]
[1] 5 9
sage: v[-n]
[1] 3 1
</pre><p>
as above, and
</p>
<pre class="wiki">sage: m = r.array('1:3', r.c(2,4))
sage: m
[,1] [,2] [,3] [,4]
[1,] 1 3 2 1
[2,] 2 1 3 2
sage: m[1,2]
[1] 3
sage: m[n]
[1] 2 3
</pre><p>
I think this is better than the first approach, but still allows to use an RElement as index.
</p>
TicketschillyWed, 13 Aug 2008 22:58:36 GMT
https://trac.sagemath.org/ticket/3838#comment:3
https://trac.sagemath.org/ticket/3838#comment:3
<p>
hi, I like the second approach, but just for the sake of completeness and with the future in mind: could you add a doctest for accessing elements of a three dimensional array? I know they can happen and i think it would be good to cover them.
</p>
TicketSimonKingThu, 14 Aug 2008 06:53:45 GMTattachment set
https://trac.sagemath.org/ticket/3838
https://trac.sagemath.org/ticket/3838
<ul>
<li><strong>attachment</strong>
set to <em>RElementAccess3.patch</em>
</li>
</ul>
<p>
To be applied after the two previous patches
</p>
TicketSimonKingThu, 14 Aug 2008 07:04:14 GMT
https://trac.sagemath.org/ticket/3838#comment:4
https://trac.sagemath.org/ticket/3838#comment:4
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/3838#comment:3" title="Comment 3">schilly</a>:
</p>
<blockquote class="citation">
<p>
hi, I like the second approach, but just for the sake of completeness and with the future in mind: could you add a doctest for accessing elements of a three dimensional array? I know they can happen and i think it would be good to cover them.
</p>
</blockquote>
<p>
No problem, that works already with the previous version:
</p>
<pre class="wiki">sage: m = r.array('1:3', r.c(2,4,2))
sage: m
, , 1
[,1] [,2] [,3] [,4]
[1,] 1 3 2 1
[2,] 2 1 3 2
, , 2
[,1] [,2] [,3] [,4]
[1,] 3 2 1 3
[2,] 1 3 2 1
sage: m[1,2,2]
[1] 2
sage: m[1,3,2]
[1] 1
</pre><p>
I changed the doc-tests accordingly (by the third patch).
</p>
<p>
However, i just realize that mixing integer and r.c does not work:
</p>
<pre class="wiki">sage: m = r.array('1:3', r.c(2,4,2))
sage: r(m.name()+'[1,c(1,2),1]')
[1] 1 3 # the output how it should be
sage: m[1,r.c(1,2),1]
[1] 2 # wrong output
</pre><p>
I'll work on this problem.
</p>
TicketSimonKingThu, 14 Aug 2008 07:17:12 GMTattachment set
https://trac.sagemath.org/ticket/3838
https://trac.sagemath.org/ticket/3838
<ul>
<li><strong>attachment</strong>
set to <em>RElementAccessNew.patch</em>
</li>
</ul>
<p>
Replaces all previous patches
</p>
TicketSimonKingThu, 14 Aug 2008 07:24:01 GMT
https://trac.sagemath.org/ticket/3838#comment:5
https://trac.sagemath.org/ticket/3838#comment:5
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/3838#comment:4" title="Comment 4">SimonKing</a>:
</p>
<blockquote class="citation">
<p>
I'll work on this problem.
</p>
</blockquote>
<p>
The most recent patch replaces all previous patches and should apply to 3.1.alpha0. Here is the new feature:
</p>
<pre class="wiki">sage: m = r.array('1:3', r.c(2,4,2))
sage: m
, , 1
[,1] [,2] [,3] [,4]
[1,] 1 3 2 1
[2,] 2 1 3 2
, , 2
[,1] [,2] [,3] [,4]
[1,] 3 2 1 3
[2,] 1 3 2 1
sage: m[1,r.c(1,2),1]
[1] 1 3
sage: m[1,r.c(1,3),r.c(1,2)]
[,1] [,2]
[1,] 1 3
[2,] 2 1
</pre><p>
The doctests provide examples for that type of usage.
</p>
TicketAlexGhitzaSat, 20 Sep 2008 23:35:51 GMTcc set
https://trac.sagemath.org/ticket/3838#comment:6
https://trac.sagemath.org/ticket/3838#comment:6
<ul>
<li><strong>cc</strong>
<em>AlexGhitza</em> added
</li>
</ul>
TicketAlexGhitzaTue, 23 Sep 2008 07:57:32 GMTsummary changed
https://trac.sagemath.org/ticket/3838#comment:7
https://trac.sagemath.org/ticket/3838#comment:7
<ul>
<li><strong>summary</strong>
changed from <em>[with patch, needs review] Element access for RElement</em> to <em>[with patch, positive review] Element access for RElement</em>
</li>
</ul>
<p>
applies to 3.1.3.alpha0
</p>
TicketmabshoffTue, 23 Sep 2008 10:24:33 GMTstatus changed; resolution set
https://trac.sagemath.org/ticket/3838#comment:8
https://trac.sagemath.org/ticket/3838#comment:8
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
<p>
Merged RElementAccessNew.patch in Sage 3.1.3.alpha1
</p>
Ticket