list(matrix) vs. matrix.list()

39 views
Skip to first unread message

Andrey Novoseltsev

unread,
Sep 14, 2012, 6:02:21 PM9/14/12
to sage-devel
Hello,

I find the following confusing:

sage: m = matrix(2)
sage: m
[0 0]
[0 0]
sage: m.list()
[0, 0, 0, 0]
sage: list(m)
[(0, 0), (0, 0)]

There can be arguments on what is a list of a matrix, but I think that
two outputs above should be the same. Are there any reasons to not
make it happen? Since m.list() already returns flat list of elements,
I think that list(m) also should do it, so that we don't break code
relying on m.list().

Thank you,
Andrey

Jason Grout

unread,
Sep 14, 2012, 6:48:46 PM9/14/12
to sage-...@googlegroups.com
But there is probably also a lot of code that relies on the list(m)
behavior. For example, this behavior is what allows m[0] to mean the
first row, which certainly is used a lot.

Maybe m.list() should be renamed to m.elements()? That way it's not
confusing, and it's also not confusing to have two ways to get the list
of elements.

Jason





Nils Bruin

unread,
Sep 14, 2012, 6:52:53 PM9/14/12
to sage-devel
On Sep 14, 3:02 pm, Andrey Novoseltsev <novos...@gmail.com> wrote:
> sage: list(m)
> [(0, 0), (0, 0)]

This is just a consequence of iter(m) yielding an iterator over the
rows of m. Changing that would break code.

Kwankyu Lee

unread,
Sep 16, 2012, 9:13:09 PM9/16/12
to sage-...@googlegroups.com
How about m.entries()? I think "entry" is quite standard.
Reply all
Reply to author
Forward
0 new messages