robpike/ivy

support large takes (with zero fill) and large drops for matrices

Closed this issue · 1 comments

fzipp commented

Commit 05a8373 added support for large takes (with zero fill) and large drops (returning an empty vector) for vectors, but it doesn't work with matrices:

4 4 take 3 3 rho iota 9
	take: left operand (4) out of range for 3 in shape (3 3)

4 4 drop 3 3 rho iota 9
	drop: left operand (4) out of range for 3 in shape (3 3)

Expected behavior (consistent with APL):

4 4 take 3 3 rho iota 9
	1 2 3 0
	4 5 6 0
	7 8 9 0
	0 0 0 0

4 4 drop 3 3 rho iota 9
	
fzipp commented

There is another issue with the zero fill:

x = 3 3 rho iota 9; x
1 2 3
4 5 6
7 8 9

y = 1 take x x; y
(1 2 3|
|4 5 6|
|7 8 9)

2 take y
(1 2 3| 0
|4 5 6|
|7 8 9)

The second element is a scalar, while the first element is a matrix.
Comare with APL:

x←3 3 ⍴ ⍳9
1 2 3
4 5 6
7 8 9

y←⊂x
┌─────┐
│1 2 3│
│4 5 6│
│7 8 9│
└─────┘

2↑y
┌─────┬─────┐
│1 2 3│0 0 0│
│4 5 6│0 0 0│
│7 8 9│0 0 0│
└─────┴─────┘

Here, both elements are matrices.