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

Add explicit checks to DataStub indices #514

Merged
merged 3 commits into from
Sep 5, 2023

Conversation

lawrence-mbf
Copy link
Collaborator

fix #513

Motivation

The original code probably assumed that the low-level HDF5 calls would check for valid inputs and spaces. This appears not to be the case for the following two cases:

  1. If a non-scalar index exceeds the bounds of a DataStub, it repeats the values of the first (valid) index instead.
  2. In certain cases, using a scalar index that exceeds the bounds of the DataStub returns an empty cell array.

How to test the behavior?

This example script sets up a condition where issue (1) occurs
filename = 'test.h5';
fullDatasetPath = '/data';
datasetName = 'data';
dataSize = 10;
if 2 == exist(filename, 'file')
    delete(filename);
end
h5create(filename, fullDatasetPath, dataSize);
h5write(filename, fullDatasetPath, 1:10);
h5disp(filename);

DataStub = types.untyped.DataStub(filename, fullDatasetPath);
DataStub([1, 11]) % returns [1;1] for some reason
% DataStub(11) % throws an error, complicates ticket #513

As mentioned in the code snippet, (2) is currently not reproducible. However, this PR should resolve both potential index errors anyway.

Checklist

  • Have you ensured the PR description clearly describes the problem and solutions?
  • Have you checked to ensure that there aren't other open or previously closed Pull Requests for the same change?
  • If this PR fixes an issue, is the first line of the PR description fix #XX where XX is the issue number?

@lawrence-mbf lawrence-mbf requested a review from bendichter July 12, 2023 16:01
@lawrence-mbf lawrence-mbf marked this pull request as ready for review July 12, 2023 16:02
The last index in an index "set" indicated by 100 in data(:, :, 100) can exceed the dimension
of its own dimensional bounds and "overflow" into subsequent dimensions in MATLAB.

This change allows for that feature.
isinteger literally checks the value type instead of whether or not the value has a decimal
portion. This has been changed to use eq and floor which is closer to the mustBeInteger function.
@codecov
Copy link

codecov bot commented Jul 12, 2023

Codecov Report

Merging #514 (e05ab5b) into master (92a65a3) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #514      +/-   ##
==========================================
+ Coverage   87.89%   87.92%   +0.03%     
==========================================
  Files         129      129              
  Lines        5451     5468      +17     
==========================================
+ Hits         4791     4808      +17     
  Misses        660      660              
Impacted Files Coverage Δ
+types/+untyped/DataStub.m 95.41% <100.00%> (+0.34%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected additional entry in vectordata
1 participant