This function has six arguments, the order of which can be challenging to keep in mind:
CopySubMatrix( src, dst, srows, drows, scols, dcols )
Two very common usecases are extracting a submatrix, or setting a submatrix:
A{rows}{cols} := B;
C := D{rows}{cols};
These are turned into
CopySubMatrix( B, A, [1..NrRows(B)], rows, [1..NrCols(B)], cols );
CopySubMatrix( D, C, rows, [1..NrRows(C)], cols, [1.. NrCols(C)] );
I am wondering if we can offer some argument variants or additional functions that make these cases a bit more convenient.
Now, if the argument order was
CopySubMatrix( src, srows, scols, dst, drows, dcols )
I'd find it a bit easier to remember, and also to propose suggestions. (Actually: if we only consider "real" MatrixObj inputs, in the filter IsMatrxObj, then we could simply allow both argument orders. It is more tricky if we also intend to support old-style list-of-list matrices...)
Anyway: with that argument order, it would be quite natural to add other methods with arguments like this (implementationwise, we'd only have to implement this once, they'd then just call the full 6-arg version):
CopySubMatrix( src, dst, drows, dcols )
CopySubMatrix( src, srows, scols, dst )
and then our examples above could become
CopySubMatrix( B, A, rows, cols )
CopySubMatrix( B, rows, cols, C )
A less invasive approach, without changing argument orders, would be to allow a single integer instead of a range. This would then indicate the start of a range, with its endpoint being automatically calculated "to fit". Our examples would thus become
CopySubMatrix( B, A, 1, rows, 1, cols );
CopySubMatrix( D, C, rows, 1, cols, 1 );
Here, "to fit" would mean that 1 is turned into a range which has the same length as its counterpart range (so if 1 is passed for srows, then it is turned into [1..Length(drows)].
We could even allow replacing all ranges by integers; then the sizes of the ranges would be derived from Minimum(NrRows(src), NrRows(dst)) resp. Minimum(NrCols(src), NrCols(dst)) ... So this would then also work (assuming rows and cols are ranges with stepsize 1):
CopySubMatrix( B, A, 1, rows[1], 1, cols[1] );
CopySubMatrix( D, C, rows[1], 1, cols[1], 1 );
This function has six arguments, the order of which can be challenging to keep in mind:
Two very common usecases are extracting a submatrix, or setting a submatrix:
These are turned into
I am wondering if we can offer some argument variants or additional functions that make these cases a bit more convenient.
Now, if the argument order was
I'd find it a bit easier to remember, and also to propose suggestions. (Actually: if we only consider "real" MatrixObj inputs, in the filter
IsMatrxObj, then we could simply allow both argument orders. It is more tricky if we also intend to support old-style list-of-list matrices...)Anyway: with that argument order, it would be quite natural to add other methods with arguments like this (implementationwise, we'd only have to implement this once, they'd then just call the full 6-arg version):
and then our examples above could become
A less invasive approach, without changing argument orders, would be to allow a single integer instead of a range. This would then indicate the start of a range, with its endpoint being automatically calculated "to fit". Our examples would thus become
Here, "to fit" would mean that
1is turned into a range which has the same length as its counterpart range (so if1is passed forsrows, then it is turned into[1..Length(drows)].We could even allow replacing all ranges by integers; then the sizes of the ranges would be derived from
Minimum(NrRows(src), NrRows(dst))resp.Minimum(NrCols(src), NrCols(dst))... So this would then also work (assumingrowsandcolsare ranges with stepsize 1):