Allow concatenation of CodimensionalCollection instances along singleton-linked dimensions #2

Open
opened 2025-11-19 01:18:52 +00:00 by UserCurt · 0 comments
UserCurt commented 2025-11-19 01:18:52 +00:00 (Migrated from codeberg.org)

Concatenation of two or more non-full CodimensionalCollection instances gives an error when concatenation along the selected dimension is incompatible due to at least one linked dimension being singleton. This feature request suggests allowing for such a concatenation.

N1 = cat(3, toeplitz(1:3), hankel(1:3));
N2 = cat(3, toeplitz(4:6), hankel(4:6));
L1 = cat(3, [true; false; true], [false; true; false]);
L2 = cat(3, [true; true; false], [false; false; true]);
S1 = cat(3, ["A", "B", "C"], ["D", "E", "F"]);
S2 = cat(3, ["G", "H", "I"], ["J", "K", "L"]);

VN = ["Numbers", "Logicals", "Strings"];
C1 = CodimensionalCollection(N1, L1, S1, VariableNames=VN);  % 3×3×2
C2 = CodimensionalCollection(N2, L2, S2, VariableNames=VN);  % 3×3×2

% Concatenating along incompatible dimension
% Current throws an error, but could return a 3×6×2 CodimensionalCollection
R2 = cat(2, C1, C2)

The simplest implementation would be to duplicate entries for the result to be consistent and as expected by the user. In this example, the Logicals variable would be affected and need to undergo repelem or something similar.

>> C1

C1 = 

  3×3×2 CodimensionalCollection with 3 fields:

     Numbers: 3×3×2 double
    Logicals: 3×1×2 logical
     Strings: 1×3×2 string
              ↑ ↑ ↑

>> C2

C2 = 

  3×3×2 CodimensionalCollection with 3 fields:

     Numbers: 3×3×2 double
    Logicals: 3×1×2 logical
     Strings: 1×3×2 string
              ↑ ↑ ↑


>> R2

R2 = 

  3×6×2 CodimensionalCollection with 3 fields:

     Numbers: 3×6×2 double
    Logicals: 3×6×2 logical
     Strings: 1×6×2 string
              ↑ ↑ ↑

An alternative would be to implement a sparse-like representation which maps supplied indices to their true internal representation indices. In this case, Logicals would be internally 3×2×2 but presented as 3×6×2. Accessing Logicals(:,i,:) for i being any of 1:3 would map to 1 and any of 4:6 would map to 2. This would effectively be a compressed version of the contents.

Concatenation of two or more non-full CodimensionalCollection instances gives an error when concatenation along the selected dimension is incompatible due to at least one linked dimension being singleton. This feature request suggests allowing for such a concatenation. ```matlab N1 = cat(3, toeplitz(1:3), hankel(1:3)); N2 = cat(3, toeplitz(4:6), hankel(4:6)); L1 = cat(3, [true; false; true], [false; true; false]); L2 = cat(3, [true; true; false], [false; false; true]); S1 = cat(3, ["A", "B", "C"], ["D", "E", "F"]); S2 = cat(3, ["G", "H", "I"], ["J", "K", "L"]); VN = ["Numbers", "Logicals", "Strings"]; C1 = CodimensionalCollection(N1, L1, S1, VariableNames=VN); % 3×3×2 C2 = CodimensionalCollection(N2, L2, S2, VariableNames=VN); % 3×3×2 % Concatenating along incompatible dimension % Current throws an error, but could return a 3×6×2 CodimensionalCollection R2 = cat(2, C1, C2) ``` The simplest implementation would be to duplicate entries for the result to be consistent and as expected by the user. In this example, the `Logicals` variable would be affected and need to undergo `repelem` or something similar. ``` >> C1 C1 = 3×3×2 CodimensionalCollection with 3 fields: Numbers: 3×3×2 double Logicals: 3×1×2 logical Strings: 1×3×2 string ↑ ↑ ↑ >> C2 C2 = 3×3×2 CodimensionalCollection with 3 fields: Numbers: 3×3×2 double Logicals: 3×1×2 logical Strings: 1×3×2 string ↑ ↑ ↑ >> R2 R2 = 3×6×2 CodimensionalCollection with 3 fields: Numbers: 3×6×2 double Logicals: 3×6×2 logical Strings: 1×6×2 string ↑ ↑ ↑ ``` An alternative would be to implement a sparse-like representation which maps supplied indices to their true internal representation indices. In this case, `Logicals` would be internally 3×2×2 but presented as 3×6×2. Accessing `Logicals(:,i,:)` for `i` being any of `1:3` would map to `1` and any of `4:6` would map to `2`. This would effectively be a compressed version of the contents.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
UserCurt/collections-toolbox#2
No description provided.