Multiple simultaneous different assignments with set #13

Closed
opened 2025-10-11 10:38:28 +00:00 by UserCurt · 2 comments
UserCurt commented 2025-10-11 10:38:28 +00:00 (Migrated from codeberg.org)

Normal usage of mpath.set is to assign a singular value to the location pointed to by one or more paths. This feature request is to generalize this to allow setting not a singular value but multiple values simultaneously. The details are yet to be determined, but the current idea is to provide a named argument like MultiSet that, when true, will require the value to be a cell array, the size of the resolution of the mpath to be compatible with the size of the cell array, and will take each mpath pointer after resolution and assign it to the corresponding value in the cell array. For example:

S = struct(A=struct(X=1, Y=2), B=struct(X=3, Y=4))
S = mpath.set(S, "/*/*", {5, 6; 7, 8}, MultiSet=true)
% S is now: struct(A=struct(X=5, Y=6), B=struct(X=7, Y=8))

The cell array is nominally identical in size to the resolution of the mpath. Having dimensions of the cell array be singular would implicitly expand this dimension so repeated assignments of the same value can be done. For example:

S = struct(A=struct(X=1, Y=2), B=struct(X=3, Y=4))
mpath.set(S, "/*/*", {5, 6}, MultiSet=true) % struct(A=struct(X=5, Y=6), B=struct(X=5, Y=6))
mpath.set(S, "/*/*", {5; 7}, MultiSet=true) % struct(A=struct(X=5, Y=5), B=struct(X=7, Y=7))

As an alternative to the named argument, the comma separated list feature could be used as mentioned here. This would be somewhat similar to how comma separated lists are used in MATLAB. For example:

S = struct(A=struct(X=1, Y=2), B=struct(X=3, Y=4))
mpath.set(S, "/*/*#list", {5, 6}) % struct(A=struct(X=5, Y=6), B=struct(X=5, Y=6))
mpath.set(S, "/*#list/*", {5, 7}) % struct(A=struct(X=5, Y=5), B=struct(X=7, Y=7))

However, the main disadvantage of this is the shape would be less obvious and perhaps even confusing when #list is used multiple times possibly along with the OutputDims (or ListDims) named argument.

As an aside, this feature request is different issue #14 which effectively incorporates mpath.get in with mpath.get during multiple assignment.

Normal usage of `mpath.set` is to assign a singular value to the location pointed to by one or more paths. This feature request is to generalize this to allow setting not a singular value but multiple values simultaneously. The details are yet to be determined, but the current idea is to provide a named argument like `MultiSet` that, when true, will require the value to be a cell array, the size of the resolution of the mpath to be compatible with the size of the cell array, and will take each mpath pointer after resolution and assign it to the corresponding value in the cell array. For example: ```matlab S = struct(A=struct(X=1, Y=2), B=struct(X=3, Y=4)) S = mpath.set(S, "/*/*", {5, 6; 7, 8}, MultiSet=true) % S is now: struct(A=struct(X=5, Y=6), B=struct(X=7, Y=8)) ``` The cell array is nominally identical in size to the resolution of the mpath. Having dimensions of the cell array be singular would implicitly expand this dimension so repeated assignments of the same value can be done. For example: ```matlab S = struct(A=struct(X=1, Y=2), B=struct(X=3, Y=4)) mpath.set(S, "/*/*", {5, 6}, MultiSet=true) % struct(A=struct(X=5, Y=6), B=struct(X=5, Y=6)) mpath.set(S, "/*/*", {5; 7}, MultiSet=true) % struct(A=struct(X=5, Y=5), B=struct(X=7, Y=7)) ``` As an alternative to the named argument, the comma separated list feature could be used [as mentioned here](https://codeberg.org/UserCurt/mpath/issues/1#issuecomment-7670506_). This would be somewhat similar to how comma separated lists are used in MATLAB. For example: ```matlab S = struct(A=struct(X=1, Y=2), B=struct(X=3, Y=4)) mpath.set(S, "/*/*#list", {5, 6}) % struct(A=struct(X=5, Y=6), B=struct(X=5, Y=6)) mpath.set(S, "/*#list/*", {5, 7}) % struct(A=struct(X=5, Y=5), B=struct(X=7, Y=7)) ``` However, the main disadvantage of this is the shape would be less obvious and perhaps even confusing when `#list` is used multiple times possibly along with the `OutputDims` (or `ListDims`) named argument. As an aside, this feature request is different issue #14 which effectively incorporates `mpath.get` in with `mpath.get` during multiple assignment.
UserCurt commented 2025-10-13 22:38:28 +00:00 (Migrated from codeberg.org)

Not discussed in the original issue post, but one closely related consideration is allowing assignment of not only fields but also elements of arrays when used in conjunction with parenthesis or brace notation in #5. For example, S = struct(A=[1 2; 3 4]); R = mpath.set(S, "/A(1,:#2)", {5, 6}) would return R = [5 6; 3 4]. Though it is unclear if the : here should not be iterated over but directly assigned, in which case it would be a single assignment using R = mpath.set(S, "/A(1,:)", [5, 6]). This may only be applicable when the last operation in the mpath expression is parenthesis or brace.

Not discussed in the original issue post, but one closely related consideration is allowing assignment of not only fields but also elements of arrays when used in conjunction with parenthesis or brace notation in #5. For example, `S = struct(A=[1 2; 3 4]); R = mpath.set(S, "/A(1,:#2)", {5, 6})` would return `R = [5 6; 3 4]`. Though it is unclear if the `:` here should not be iterated over but directly assigned, in which case it would be a single assignment using `R = mpath.set(S, "/A(1,:)", [5, 6])`. This may only be applicable when the last operation in the mpath expression is parenthesis or brace.
Owner

Completed by commit 977b9d3. The proposed MultiSet behavior has been superseded by UniformValues=false. A cell value grid must match the resolved target grid, and each cell is assigned to its corresponding target coordinate. UniformPaths controls whether input pointers form one combined target grid or separate groups. The proposed #list syntax is not needed for this behavior.

Singleton expansion of value grids remains separate and is tracked by #44.

Completed by commit `977b9d3`. The proposed `MultiSet` behavior has been superseded by `UniformValues=false`. A cell value grid must match the resolved target grid, and each cell is assigned to its corresponding target coordinate. `UniformPaths` controls whether input pointers form one combined target grid or separate groups. The proposed `#list` syntax is not needed for this behavior. Singleton expansion of value grids remains separate and is tracked by #44.
Sign in to join this conversation.
No description provided.