davidclemens / Dingi

Dingi is a toolbox for processing data collected by marine research gear.
MIT License
1 stars 0 forks source link

When calling `DataKit.bitmask.setNum` with only an index that exceeds the number of elements, the bitmask grows along the last dimension #132

Closed davidclemens closed 1 year ago

davidclemens commented 1 year ago

System information

-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.3.0.713579 (R2017b)
MATLAB License Number: STUDENT
Operating System: Mac OS X  Version: 10.15.7 Build: 19H2 
Java Version: Java 1.8.0_121-b13 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB                                                Version 9.3         (R2017b)    
Simulink                                              Version 9.0         (R2017b)    
Aerospace Toolbox                                     Version 2.20        (R2017b)    
Control System Toolbox                                Version 10.3        (R2017b)    
Curve Fitting Toolbox                                 Version 3.5.6       (R2017b)    
DSP System Toolbox                                    Version 9.5         (R2017b)    
Dingi                                                 Version 0.1.0b1     (2022.5.0b1)
Image Processing Toolbox                              Version 10.1        (R2017b)    
Instrument Control Toolbox                            Version 3.12        (R2017b)    
Mapping Toolbox                                       Version 4.5.1       (R2017b)    
Optimization Toolbox                                  Version 8.0         (R2017b)    
Signal Processing Toolbox                             Version 7.5         (R2017b)    
Simulink Control Design                               Version 5.0         (R2017b)    
Statistics and Machine Learning Toolbox               Version 11.2        (R2017b)    
Symbolic Math Toolbox                                 Version 8.0         (R2017b)    
Utilities                                             Version 1.5.1       (2022.11.1) 

Bug description

What should have happened?

The bitmask should grow along the first dimension, according to the documentation.

What did actually happened?

The bitmask grows along the last dimension.

Steps to reproduce the bug

Run the following:

bm = DataKit.bitmask(ones(2,3))

returns a bitmask bm of size [2,3].

Then setting a number at an index that exceeds the number of elements in the bitmask

bm.setNum(0,8)

returns a bitmask bm of size [2,4]

Causes & solutions

The cause is the convention of the builtin ind2sub function as it is called in line 105 of DataKit.bitmask.setNum: It has the convention to grow the array size along the last dimension.

The easiest solution is to change the expected behaviour of DataKit.bitmask.setNum to match the one of ind2sub.