-
Notifications
You must be signed in to change notification settings - Fork 32
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
Refactor addRawData to flip append dims #387
Conversation
Now only supports up to 2D matrices when adding in memory.
Since we no longer assume that the first dimension is necessariily the append dimension.
Since this is an ambiguous case where we have no idea which dimension to actually use until a second piece of data is appended.
…ders/matnwb into 364-addrow-flip-dims
Will now only check the config right before instantiation instead at every abstraction level.
- Refactored a lot of checkConfig. - Added Index infinite loop check case. - Added error IDs to errors.
- Fix weird case where the file generation did not include the right class type check. - Fix case where `id` column was not in-memory.
Not necessarily only called by addRow.
Forgot these IDs were actually used somewhere.
- Did not populate the ragged array properly.
- Checked for the existence of hdmf_common before checking config despite that being supported in the function itself.
Codecov Report
@@ Coverage Diff @@
## master #387 +/- ##
==========================================
+ Coverage 85.69% 85.74% +0.04%
==========================================
Files 125 125
Lines 4698 4714 +16
==========================================
+ Hits 4026 4042 +16
Misses 672 672
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
off to a strong start!
DynamicTable tests should be expanded to test expected addRow behavior. Currently getting the errors in the following scenarios:
- adding row to multidimensional column of table in memory
% Define 1D column
simple_col = types.hdmf_common.VectorData( ...
'description', '1D column',...
'data', rand(10,1) ...
);
% Define ND column
multi_col = types.hdmf_common.VectorData( ...
'description', 'multidimensional column',...
'data', rand(3,2,10) ...
);
% construct table
multi_dim_table = types.hdmf_common.DynamicTable( ...
'description','test table', ...
'colnames', {'simple','multi'}, ...
'simple', simple_col, ...
'multi', multi_col, ...
'id', types.hdmf_common.ElementIdentifiers('data', (0:9)') ... % 0-indexed, for compatibility with Python
);
% add row
multi_dim_table.addRow( ...
'simple', 1, ...
'multi', rand(3,2), ...
'id', 10 ...
);
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in types.util.dynamictable.addRawData>add2MemData (line 140)
VectorData.data = cat(catDim, VectorData.data, data);
Error in types.util.dynamictable.addRawData>nestedAdd (line 118)
numRows = add2MemData(Vector, data);
Error in types.util.dynamictable.addRawData>nestedAdd (line 105)
numRows = nestedAdd(DynamicTable, indChain(2:end), data);
Error in types.util.dynamictable.addRawData (line 38)
nestedAdd(DynamicTable, flip(indexChain), data);
Error in types.util.dynamictable.addVarargRow (line 41)
types.util.dynamictable.addRawData(DynamicTable, rn, rv);
Error in types.util.dynamictable.addRow (line 45)
types.util.dynamictable.addVarargRow(DynamicTable, varargin{:});
Error in types.hdmf_common.DynamicTable/addRow (line 117)
types.util.dynamictable.addRow(obj, varargin{:});
Error in ind_tests (line 22)
multi_dim_table.addRow( ...
- adding row to multidimensional column of expandable table
% Create file
file= NwbFile( ...
'session_start_time', '2021-01-01 00:00:00', ...
'identifier', 'ident1', ...
'session_description', 'test_file' ...
);
% Define Vector Data Objects with first row of table
start_time_exp = types.hdmf_common.VectorData( ...
'description', 'start times column', ...
'data', types.untyped.DataPipe( ...
'data', 1, ...
'maxSize', Inf ...
) ...
);
stop_time_exp = types.hdmf_common.VectorData( ...
'description', 'stop times column', ...
'data', types.untyped.DataPipe( ...
'data', 10, ...
'maxSize', Inf ...
) ...
);
random_exp = types.hdmf_common.VectorData( ...
'description', 'random data column', ...
'data', types.untyped.DataPipe( ...
'data', rand(3,2,5), ... #random data
'maxSize', [3, 2, Inf], ...
'axis', 3 ...
) ...
);
random_exp_index = types.hdmf_common.VectorIndex( ...
'description', 'index to random data column', ...
'target',types.untyped.ObjectView(random_exp), ...
'data', types.untyped.DataPipe( ...
'data', [5], ...
'maxSize', [Inf, 1], ...
'axis', 1 ...
) ...
);
ids_exp = types.hdmf_common.ElementIdentifiers( ...
'data', types.untyped.DataPipe( ...
'data', 0, ... # data must be numerical
'maxSize', Inf ...
) ...
);
% Create expandable table
colnames = {'start_time', 'stop_time', 'randomvalues'};
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, ...
'randomvalues_index', random_exp_index, ...
'id', ids_exp ...
);
% Export file
nwbExport(file, 'multiRaggedExpandableTableTest.nwb');
% Read in file
read_file = nwbRead('multiRaggedExpandableTableTest.nwb');
% add individual rows
read_file.intervals_trials.addRow( ...
'start_time', 2, ...
'stop_time', 20, ...
'randomvalues', rand(3,2,6), ...
'id', 1 ...
);
Error using types.util.dynamictable.addVarargRow>validateType (line 69)
Expected input to be two-dimensional.
Error in types.util.dynamictable.addVarargRow (line 38)
validateType(TypeMap(rn), rv);
Error in types.util.dynamictable.addRow (line 45)
types.util.dynamictable.addVarargRow(DynamicTable, varargin{:});
Error in types.hdmf_common.DynamicTable/addRow (line 117)
types.util.dynamictable.addRow(obj, varargin{:});
Error in ind_tests (line 91)
read_file.intervals_trials.addRow( ...
Unless I read you wrong, I believe we agreed that we wanted to limit the dimensions for in-memory concatenation to 2D matrices. Did you mean 3D matrices or should I just make the error message more clear? |
Thanks for adding that helpful error message. The error on that point was on my part. I forgot that we had agreed on to use However, there's still some issues with the behavior of % Create file
file= NwbFile( ...
'session_start_time', '2021-01-01 00:00:00', ...
'identifier', 'ident1', ...
'session_description', 'test_file' ...
);
% Define Vector Data Objects with first row of table
start_time_exp = types.hdmf_common.VectorData( ...
'description', 'start times column', ...
'data', types.untyped.DataPipe( ...
'data', 1, ...
'maxSize', Inf ...
) ...
);
stop_time_exp = types.hdmf_common.VectorData( ...
'description', 'stop times column', ...
'data', types.untyped.DataPipe( ...
'data', 10, ...
'maxSize', Inf ...
) ...
);
random_exp = types.hdmf_common.VectorData( ...
'description', 'random data column', ...
'data', types.untyped.DataPipe( ...
'data', rand(3,2,5), ... #random data
'maxSize', [3, 2, Inf], ...
'axis', 3 ...
) ...
);
random_exp_index = types.hdmf_common.VectorIndex( ...
'description', 'index to random data column', ...
'target',types.untyped.ObjectView(random_exp), ...
'data', types.untyped.DataPipe( ...
'data', [5], ...
'maxSize', [Inf, 1], ...
'axis', 1 ...
) ...
);
ids_exp = types.hdmf_common.ElementIdentifiers( ...
'data', types.untyped.DataPipe( ...
'data', 0, ... # data must be numerical
'maxSize', Inf ...
) ...
);
% Create expandable table
colnames = {'start_time', 'stop_time', 'randomvalues'};
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, ...
'randomvalues_index', random_exp_index, ...
'id', ids_exp ...
);
% Export file
nwbExport(file, 'multiRaggedExpandableTableTest.nwb');
% Read in file
read_file = nwbRead('multiRaggedExpandableTableTest.nwb');
% add individual rows
read_file.intervals_trials.addRow( ...
'start_time', 2, ...
'stop_time', 20, ...
'randomvalues', rand(3,2,6), ...
output after >> read_file.intervals_trials.vectordata.get('randomvalues').data.internal
ans =
BoundPipe with properties:
config: [1×1 types.untyped.datapipe.Configuration]
pipeProperties: {1×2 cell}
stub: [1×1 types.untyped.DataStub]
axis: 3
offset: 11
dataType: 'double'
maxSize: [3 2 Inf]
dims: [3 2 11]
filename: 'multiRaggedExpandableTableTest.nwb'
path: '/intervals/trials/randomvalues'
>> read_file.intervals_trials.vectordata.get('randomvalues_index').data(:)
ans =
5
6 Second entry of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment above for requested changes.
@cechava you have to include the |
A Blueprint pipe requires two things: the shape of the data structure and an axis for appending.
|
I did set the 'axis' argument for the |
@cechava Oh I just missed that then. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works great. Thanks @ln-vidrio
Fixes #390, Fixes #364