Skip to content

Commit

Permalink
Fix getRow behavior. Remove redundant tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrence-mbf committed Aug 17, 2022
1 parent e25e73d commit 01ab16f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 116 deletions.
104 changes: 0 additions & 104 deletions +tests/+system/DynamicTableTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,81 +33,6 @@ function addContainer(~, file)
end
end

function addExpandableDynamicTable(~, file, start_array, stop_array, ...
random_array, random_multi_array, ragged_data_array, ...
ragged_index_array, id_array)
% create VectorData objects with DataPipe objects
start_time_exp = types.hdmf_common.VectorData( ...
'description', 'start times', ...
'data', types.untyped.DataPipe( ...
'data', start_array, ...
'maxSize', Inf ...
) ...
);
stop_time_exp = types.hdmf_common.VectorData( ...
'description', 'stop times', ...
'data', types.untyped.DataPipe( ...
'data', stop_array, ...
'maxSize', Inf ...
) ...
);
random_exp = types.hdmf_common.VectorData( ...
'description', 'random data column', ...
'data', types.untyped.DataPipe( ...
'data', random_array', ...
'maxSize', [1, Inf], ...
'axis', 2 ...
)...
);
random_multi_exp = types.hdmf_common.VectorData( ...
'description', 'random data column', ...
'data', types.untyped.DataPipe( ...
'data', random_multi_array, ...
'maxSize', [3 , 2, Inf], ...
'axis', 3 ...
)...
);
ragged_exp = types.hdmf_common.VectorData( ...
'description', 'random data column', ...
'data', types.untyped.DataPipe( ...
'data', ragged_data_array, ...
'maxSize', [Inf, 1], ...
'axis', 1 ...
)...
);
ragged_exp_index = types.hdmf_common.VectorIndex( ...
'description', 'random data column', ...
'target',types.untyped.ObjectView(ragged_exp), ...
'data', types.untyped.DataPipe( ...
'data', ragged_index_array', ...
'maxSize', Inf ...
)...
);
ids_exp = types.hdmf_common.ElementIdentifiers( ...
'data', types.untyped.DataPipe( ...
'data', id_array, ...
'maxSize', Inf ...
) ...
);
% create expandable table
colnames = { ...
'start_time', 'stop_time', ...
'randomvalues', 'random_multi' ,'random_ragged' ...
};
file.intervals_trials = types.core.TimeIntervals( ...
'description', 'test expdandable dynamic table', ...
'colnames', colnames, ...
'start_time', start_time_exp, ...
'stop_time', stop_time_exp, ...
'randomvalues', random_exp, ...
'random_multi', random_multi_exp, ...
'random_ragged', ragged_exp, ...
'random_ragged_index', ragged_exp_index, ...
'id', ids_exp ...
);
types.util.dynamictable.checkConfig(file.intervals_trials)
end

function addContainerUnevenColumns(~, file)
% create and add a container with columns of unmatched length
colnames = {'start_time', 'stop_time', 'randomvalues'};
Expand Down Expand Up @@ -277,35 +202,6 @@ function getRowRoundtripTest(testCase)
ActualTable.getRow([13, 19], 'useId', true));
end

function ExpandableTableTest(testCase)
% define data matrices
nrows = 20;
id = 0:nrows-1; % different from row poistion
start_time_array = 1:nrows;
stop_time_array = start_time_array + 1;
rng(1); % to be able replicate random values
random_val_array = rand(nrows, 1);
random_multi_array = rand(3, 2, nrows);
% create expandable table with first half of arrays
testCase.addExpandableDynamicTable(testCase.file, ...
start_time_array(1:10), stop_time_array(1:10), ...
random_val_array(1:10), random_multi_array(:, : ,1:10), ...
rand(nrows*3,1), [sort(randi(nrows*3,9,1)); nrows*3], id(1:10));
% export and read-in expandable table
filename = ['MatNWB.' testCase.className() '.ExpandableTableTest.nwb'];
nwbExport(testCase.file, filename);
% removing addRows test until function is updated
% read in expanded table
readFile = nwbRead(filename, 'ignorecache');
% test getRow
actualData = readFile.intervals_trials.getRow(1:10, ...
'columns', {'randomvalues'});
testCase.verifyEqual( ...
random_val_array(1:10), ...
actualData.randomvalues ...
);
end

function toTableTest(testCase)
% test DynamicTable toTable method.
% 1. For a generic table, the toTable output should be very
Expand Down
31 changes: 19 additions & 12 deletions +types/+util/+dynamictable/getRow.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@
end

row{i} = select(DynamicTable, indexNames, ind);
if size(row{i},2)>1
% shift dimensions of non-row vectors. otherwise will result in
% invalid MATLAB table with uneven column height
row{i} = permute(row{i},circshift(1:ndims(row{i}),1));

% transpose row vectors
if isrow(row{i})
row{i} = row{i} .';
end
if length(ind)==1
% cell-wrap single multidimensional matrices to prevent invalid
% MATLAB tables
if ~iscell(row{i}) && length(row{i}) > 1
row{i} = {row{i}};
end

% cell-wrap single multidimensional matrices to prevent invalid
% MATLAB tables
if isscalar(ind) && ~iscell(row{i}) && ~isscalar(row{i})
row{i} = {row{i}};
end

% convert compound data type scalar struct into an array of
% structs.
if isscalar(row{i}) && isstruct(row{i})
% convert compound data type scalar struct into an array of
% structs.
structNames = fieldnames(row{i});
scalarStruct = row{i};
rowStruct = row{i}; % same as scalarStruct to maintain the field names.
Expand Down Expand Up @@ -126,6 +126,13 @@
else
selected = Vector.data(selectInd{:});
end

% shift dimensions of non-row vectors. otherwise will result in
% invalid MATLAB table with uneven column height
if isa(Vector.data, 'types.untyped.DataPipe')
selected = permute(selected, ...
circshift(1:ndims(selected), -(Vector.data.axis-1)));
end
else
assert(isa(Vector, 'types.hdmf_common.VectorIndex') || isa(Vector, 'types.core.VectorIndex'),...
'NWB:DynamicTable:GetRow:InternalError',...
Expand Down

0 comments on commit 01ab16f

Please sign in to comment.