Concatenation incorrectly throws error for non-full CodimensionalCollection #1

Open
opened 2025-11-19 01:17:49 +00:00 by UserCurt · 1 comment
UserCurt commented 2025-11-19 01:17:49 +00:00 (Migrated from codeberg.org)

Concatenation of two or more CodimensionalCollection instances can incorrectly throw an error when they are not full, meaning some dimensions are linked with variables with both singleton and non-singleton sizes along the corresponding dimension. Concatenating along such a dimension should and correctly does throw an error. But concatenating along other dimensions should not give an error, but the current implementation does.

To reproduce the issue:

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 common singleton dimension
% Expected result, 3×3×2×2: CodimensionalCollection(cat(4, N1, N2), cat(4, L1, L2), cat(4, S1, S2), VariableNames=VN)
R4 = cat(4, C1, C2)

% Concatenating along common non-singleton dimension
% Expected result, 3×3×4: CodimensionalCollection(cat(3, N1, N2), cat(3, L1, L2), cat(3, S1, S2), VariableNames=VN)
R3 = cat(3, C1, C2)

As an aside, concatenation along dimension 2 currently correctly throws an error. See issue #2 for a feature request in which it returns a valid CodimensionalCollection.

Concatenation of two or more CodimensionalCollection instances can incorrectly throw an error when they are not full, meaning some dimensions are linked with variables with both singleton and non-singleton sizes along the corresponding dimension. Concatenating along such a dimension should and correctly does throw an error. But concatenating along other dimensions should not give an error, but the current implementation does. To reproduce the issue: ```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 common singleton dimension % Expected result, 3×3×2×2: CodimensionalCollection(cat(4, N1, N2), cat(4, L1, L2), cat(4, S1, S2), VariableNames=VN) R4 = cat(4, C1, C2) % Concatenating along common non-singleton dimension % Expected result, 3×3×4: CodimensionalCollection(cat(3, N1, N2), cat(3, L1, L2), cat(3, S1, S2), VariableNames=VN) R3 = cat(3, C1, C2) ``` As an aside, concatenation along dimension 2 currently correctly throws an error. See issue #2 for a feature request in which it returns a valid CodimensionalCollection.
UserCurt commented 2025-11-19 01:29:36 +00:00 (Migrated from codeberg.org)

This may be related to why C(1) and C(:) for a 2+-dimensional CodimensionalCollection C throws an error.

This may be related to why `C(1)` and `C(:)` for a 2+-dimensional CodimensionalCollection `C` throws an error.
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#1
No description provided.