Replies: 7 comments
-
Interesting idea. Of course for an |
Beta Was this translation helpful? Give feedback.
-
I need it very often, because I have buffers buf = [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ] And I want to do a sort of destructive read. So basically popping a part of this buffer : math.splice(buf, [[0, 1], [0, 1]], [[], []]) // [[1, 2], [5, 6]]
buf // [[3, 4], [7, 8]] The question is ... could it be just implemented in |
Beta Was this translation helpful? Give feedback.
-
For the (internal) implementation I think we can use the same code for the biggest part, though for the user we should offer two separate functions I really like this idea of a splice function for n-dimensional matrices, it's brilliant and fully in the spirit of JavaScript's Arrays. |
Beta Was this translation helpful? Give feedback.
-
This is a specific, cogent, and apparently worthwhile proposal (judging by the number of times related/variant issues have come up). To make it quite precise, if X is an Index object that has the full extent of a collection (Matrix/Array) in all but one dimension (we will use the example that it consists of p m-by-n "planes" of an l-by-m-by-n collection where p<l, although it could be a different number of dimensions or a different dimension that is not full, then the replacement R in a subset expression
[a.k.a As Jos has mentioned, this should not be difficult to implement; and I don't particularly see why it warrants a different operator name, as |
Beta Was this translation helpful? Give feedback.
-
Thanks for your inputs Glen. I'm not sure I understand your proposal here. Right now, |
Beta Was this translation helpful? Give feedback.
-
The point of the original proposal seems to be, and this is what I tried to capture in my more precise version, is that replacing part of a Matrix with nothing deletes that part of the matrix, and replacing part of a Matrix with differently- (but compatibly-) sized contents in effect inserts part of a matrix. So without change to the "left-hand-side" of a subset operation, we get these abilities by being more permissive on the "right-hand-side". And my latest post was to try to pin down exactly when such a non-identical-shape subset "assignment" is legal. The one case of splice specifically that does not seem to be covered by this proposal is insertion of new entries in the middle of a matrix, because there isn't any way to specify an empty subset of a matrix at a certain position. I.e., by this proposal you could change
I had shied away from something like (3) when commenting yesterday because the formulations I was thinking of seemed to overlap way too much with the existing functionality of "subset", but now the specific API in this version of (3) actually doesn't seem to overlap too much and seems pretty clean. And it has the advantage that assignment-like statements in the parser can't change the size of the matrix; any size-changing operations would be flagged by a long-form function call, in the parser So with that reflection, my vote is now for option (3) which I think is very much in the spirit of the original poster's request without being too duplicative of subset (as the OP also worried). |
Beta Was this translation helpful? Give feedback.
-
Yes, that is true. Well explained. So it boils down to whether we want to extend I have the feeling that allowing a special notation like |
Beta Was this translation helpful? Give feedback.
-
subset
is close to that, but you can't actually remove a subset from the initial matrix.Beta Was this translation helpful? Give feedback.
All reactions