inplace transpose

41 views
Skip to first unread message

Vincent Delecroix

unread,
May 22, 2017, 8:36:30 AM5/22/17
to sage-devel
Dear all,

I would like to have inplace version of transpose for matrices. For the
echelon form we have methods mat.echelonize vs mat.echelon_form. However
I do not see how to deal with transpose in the same way. I see three
reasonable possibilities

1) add an option inplace=True/False. There is at least one such method
in Sage: the relabel method for graphs. The behavior is as follows:

if inplace=True: returns a new graph
if inplace=False: modifies the graph inplace and does not return anything

One can do the same with .transpose for matrices. However, this would be
the first time in matrix code.

2) Make a private inplace method mat._transpose_inplace()

3) Make a public inplace method mat.transpose_inplace()

Any preference between 1), 2), 3) or a suggestion for something else is
welcome!

Vincent

Erik Bray

unread,
May 22, 2017, 8:43:27 AM5/22/17
to sage-devel
On Mon, May 22, 2017 at 2:35 PM, Vincent Delecroix
<20100.d...@gmail.com> wrote:
> Dear all,
>
> I would like to have inplace version of transpose for matrices. For the
> echelon form we have methods mat.echelonize vs mat.echelon_form. However I
> do not see how to deal with transpose in the same way. I see three
> reasonable possibilities
>
> 1) add an option inplace=True/False. There is at least one such method in
> Sage: the relabel method for graphs. The behavior is as follows:
>
> if inplace=True: returns a new graph
> if inplace=False: modifies the graph inplace and does not return anything

I like this, and there is some precedent for it elsewhere too. But I
assume you meant this the other way around?

> One can do the same with .transpose for matrices. However, this would be the
> first time in matrix code.
>
> 2) Make a private inplace method mat._transpose_inplace()
>
> 3) Make a public inplace method mat.transpose_inplace()
>
> Any preference between 1), 2), 3) or a suggestion for something else is
> welcome!
>
> Vincent
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+...@googlegroups.com.
> To post to this group, send email to sage-...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.

Vincent Delecroix

unread,
May 22, 2017, 8:44:04 AM5/22/17
to sage-...@googlegroups.com


On 22/05/2017 14:43, Erik Bray wrote:
> On Mon, May 22, 2017 at 2:35 PM, Vincent Delecroix
> <20100.d...@gmail.com> wrote:
>> Dear all,
>>
>> I would like to have inplace version of transpose for matrices. For the
>> echelon form we have methods mat.echelonize vs mat.echelon_form. However I
>> do not see how to deal with transpose in the same way. I see three
>> reasonable possibilities
>>
>> 1) add an option inplace=True/False. There is at least one such method in
>> Sage: the relabel method for graphs. The behavior is as follows:
>>
>> if inplace=True: returns a new graph
>> if inplace=False: modifies the graph inplace and does not return anything
>
> I like this, and there is some precedent for it elsewhere too. But I
> assume you meant this the other way around?

Indeed!

Thierry

unread,
May 22, 2017, 8:50:47 AM5/22/17
to sage-...@googlegroups.com
Hi,

On Mon, May 22, 2017 at 02:35:43PM +0200, Vincent Delecroix wrote:
> Dear all,
>
> I would like to have inplace version of transpose for matrices. For the
> echelon form we have methods mat.echelonize vs mat.echelon_form. However I
> do not see how to deal with transpose in the same way. I see three
> reasonable possibilities
>
> 1) add an option inplace=True/False. There is at least one such method in
> Sage: the relabel method for graphs. The behavior is as follows:
>
> if inplace=True: returns a new graph
> if inplace=False: modifies the graph inplace and does not return anything

Do you mean the converse ?

Ciao,
Thierry

> One can do the same with .transpose for matrices. However, this would be the
> first time in matrix code.
>
> 2) Make a private inplace method mat._transpose_inplace()
>
> 3) Make a public inplace method mat.transpose_inplace()
>
> Any preference between 1), 2), 3) or a suggestion for something else is
> welcome!
>
> Vincent
>

Jori Mäntysalo

unread,
May 22, 2017, 10:01:56 AM5/22/17
to sage-devel
On Mon, 22 May 2017, Vincent Delecroix wrote:

> 1) add an option inplace=True/False. There is at least one such method in
> Sage: the relabel method for graphs. The behavior is as follows:

inplace is mentioned at
http://doc.sagemath.org/html/en/developer/coding_basics.html#miscellanous-minor-things

So yes, I think "inplace=True" should be preferred over
"return_copy=False" or similar.

> 2) Make a private inplace method mat._transpose_inplace()
>
> 3) Make a public inplace method mat.transpose_inplace()
>
> Any preference between 1), 2), 3) or a suggestion for something else is
> welcome!

I think 1 would be most natural.

--
Jori Mäntysalo

Erik Bray

unread,
May 22, 2017, 10:45:12 AM5/22/17
to sage-devel
Though I'd also add that something like 2) makes perfect sense as an
*implementation* detail.
Reply all
Reply to author
Forward
0 new messages