Fix multi-dimensional indexing bug, add tests, and some convenience r… #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've been trying to use jmatio to read multi-dimensional arrays created in matlab into a scala app. It appears there is a bug in the way the indices are computed. In the MLArray constructor dimsFactors is initialized from the highest dimension to the lowest, but Matlab arrays are stored in column major format. So I think dimsFactors should really be initialized starting with dimension 0 and going up. This seems like a fatal bug for anyone trying to transfer multi-dimensional arrays between matlab and jmatio. So I'm surprised it hasn't been hit by anyone else. So maybe I'm just missing something about the library usage. Please review and let me know if you agree.
Simply fixing the way dimFactors is computed would break any s/w that needs to access multi-dimensional files previously created with this library. So I created added dimStrides and a new function getIndexCM (for column major) that can be used to compute the linear index in a Matlab compatible way. I added several convenience accessor functions as well that need to use getIndexCM rather than getIndex.
In addition to the code fixes, I added a matlab sub dir under src/test that contains matlab scripts for generating the .mat files used by the unit tests that I added.