Issue #6852 has been updated by marcandre (Marc-Andre Lafortune).

Category set to core
Target version set to 2.0.0

Hi,

alexeymuranov (Alexey Muranov) wrote:
> I think it can be agreed that all of the following represent the same "empty matrix": `[]`, `[[]]`, `[[], [], []]`.  Otherwise they all would need to be treated exceptionally (how to express the transposition of each of them?).  After all, 0 x 3 = 0 x 2 = 3 x 0 = 0 x 0 = 0.

Actually, no. Empty matrices are well defined: http://en.wikipedia.org/wiki/Matrix_(mathematics)#Empty_matrices

The matrix library handles then well too:

   require 'matrix'
   Matrix[[], [], []] == Matrix[[]] # => false
   Matrix[[], [], []].transpose.column_size # => 3

boris_stitnicky (Boris Stitnicky) wrote:
> In other words, when [] is the receiver, ... it should raise,
> or warn, or complain

Strictly speaking you are right.

I'm not sure it's that much more useful to raise, though. I think the current behavior might be more helpful.

----------------------------------------
Feature #6852: [].transpose should behave specially
https://bugs.ruby-lang.org/issues/6852#change-28768

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: core
Target version: 2.0.0


p = [1, 2, 3]
q = [4, 5, 6]
[p, q].transpose
# => [[1, 4], [2, 5], [3, 6]]
As expected, 2 x 3 vector was converted into 3 x 2.

[p].transpose
# => [[1], [2], [3]]
As expected, 1 x 3 => 3 x 1.

[].transpose
# => []
Unexpected, 0 x 3 did not become 3 x 0: [[], [], []]

In other words, when [] is the receiver, transpose has no way to know
what kind of ** 2 dimensional ** object is it - whether 0 x 3, 0 x 4, 0 x 1
or perhaps 0 x 0. #transpose should not assume it is 0 x 0. It should raise,
or warn, or complain, or require argument for this case, in short, it should
behave differently than today.


-- 
http://bugs.ruby-lang.org/