Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getRow method for dynamic table #648

Merged
merged 8 commits into from
Jan 14, 2025
Merged
26 changes: 26 additions & 0 deletions +tests/+unit/dynamicTableTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ function testClearDynamicTableV2_1(testCase)
rehash();
end

function testToTableForNdVectorData(testCase)
import matlab.unittest.fixtures.SuppressedWarningsFixture
testCase.applyFixture(...
SuppressedWarningsFixture('NWB:DynamicTable:VectorDataAmbiguousSize'))

arrayLength = 5;
numTableRows = 3;
nDimsToTest = [2,3,4];

for nDims = nDimsToTest
vectorDataShape = repmat(arrayLength, 1, nDims-1);

dynamicTable = types.hdmf_common.DynamicTable( ...
'description', 'test table with n-dimensional VectorData', ...
'colnames', {'columnA', 'columnB'}, ...
'columnA', types.hdmf_common.VectorData('data', randi(10, [vectorDataShape, numTableRows])), ...
'columnB', types.hdmf_common.VectorData('data', randi(10, [vectorDataShape, numTableRows])), ...
'id', types.hdmf_common.ElementIdentifiers('data', (0:numTableRows-1)' ) );

T = dynamicTable.toTable();
testCase.verifyClass(T, 'table');
testCase.verifySize(T.columnA, [numTableRows, vectorDataShape])
end
end


% Non-test functions
function dtr_table = createDynamicTableWithTableRegionReferences()
% Create a dynamic table with two columns, where the data of each column is
Expand Down
11 changes: 6 additions & 5 deletions +types/+util/+dynamictable/getRow.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@
row{i} = select(DynamicTable, indexNames, ind);

if ~istable(row{i})
% transpose row vectors
if isrow(row{i})
row{i} = row{i} .';
% or permute arrays to place last dimension first
elseif ~ismatrix(row{i}) % i.e nd array where n >= 3
if iscolumn(row{i})
% keep column vectors as is
elseif isrow(row{i})
row{i} = row{i} .'; % transpose row vectors
elseif ndims(row{i}) >= 2 % i.e nd array where ndims >= 2
% permute arrays to place last dimension first
array_size = size(row{i});
num_rows = numel(ind);

Expand Down
Loading