On Wed, 11 Aug 2021, Sven Schreiber wrote:
Am 11.08.2021 um 17:29 schrieb Allin Cottrell:
>
> Please formulate this as a feature for msplitby(). Right now that
> function offers very general control over splitting but as you say
> it's not convenient for certain simple cases, and it probably should
> offer choice of dimension. A revised but backward-compatible signature
> might be:
feature request is what you meant, I guess. Will do.
>
> matrices msplitby (matrix M, <vector-or-scalar> by, bool alt)
>
> where @alt would switch to column-wise splitting and scalar @by would
> give the chunk size, provided the relevant dimension is divisible by @by.
Yes, that's what I had in mind, too.
>
> BTW splitting a matrix by columns will be much faster then by rows;
Right, that's one reason why I found the current status a bit surprising.
Maybe a feature request is not necessary. The signature given above
is now supported in git, available for testing.
<hansl>
set verbose off
r = 8
c = 6
matrix M = mshape(seq(1,r*c), r, c)
print M
printf "splitting via vector\n\n"
matrices MM = msplitby(M, {1,2,3,1,2,3,4,4})
loop i=1..nelem(MM)
print MM[i]
endloop
matrices MM = msplitby(M, {1,1,2,2,3,3}, 1)
loop i=1..nelem(MM)
print MM[i]
endloop
printf "splitting via chunk size\n\n"
matrices MM = msplitby(M, 2)
loop i=1..nelem(MM)
print MM[i]
endloop
matrices MM = msplitby(M, 2, 1)
loop i=1..nelem(MM)
print MM[i]
endloop
</hansl>
Allin