Skip to content

Commit e948800

Browse files
committed
range dim fix create_data_array
1 parent 021afca commit e948800

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

+nix/Block.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
end;
5454

5555
function da = create_data_array(obj, name, nixtype, datatype, shape)
56+
%-- Quick fix to enable alias range dimension with
57+
%-- 1D data arrays created with this function.
58+
%-- e.g. size([1 2 3]) returns shape [1 3], which would not
59+
%-- be accepted when trying to add an alias range dimension.
60+
if(shape(1) == 1)
61+
shape(2:size(shape,2));
62+
end;
63+
5664
errorStruct.identifier = 'Block:unsupportedDataType';
5765
if(~isa(datatype, 'nix.DataType'))
5866
errorStruct.message = 'Please provide a valid nix.DataType';

src/nixdataarray.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ namespace nixdataarray {
5656

5757
mwSize ndims = mxGetNumberOfDimensions(arr);
5858
const mwSize *dims = mxGetDimensions(arr);
59-
59+
60+
mwSize tmp = ndims;
61+
62+
// Quick fix for writing data arrays that have exactly one row.
63+
// This fix does not resolve more complex arrays that have a
64+
// last dimension of exactly one row.
65+
if (dims[ndims-1] == 1) {
66+
ndims--;
67+
}
6068
nix::NDSize count(ndims);
6169

6270
for (mwSize i = 0; i < ndims; i++) {

tests/TestDataArray.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
charData = ['a' 'b' 'c' 'd' 'e'];
150150
cellData = {1 2 3 4 5};
151151

152-
da = b.create_data_array('numericArray', typeDA, nix.DataType.Double, [1 5]);
152+
da = b.create_data_array('numericArray', typeDA, nix.DataType.Double, 5);
153153
da.write_all(numData);
154154
assert(isequal(da.read_all(), numData));
155155

@@ -185,7 +185,7 @@
185185
numData = [1 2 3 4 5];
186186
charData = ['a' 'b' 'c' 'd' 'e'];
187187

188-
da = b.create_data_array('logicalArray', typeDA, nix.DataType.Bool, [1 5]);
188+
da = b.create_data_array('logicalArray', typeDA, nix.DataType.Bool, 5);
189189
da.write_all(logData);
190190
assert(isequal(da.read_all, logData));
191191
try
@@ -213,7 +213,7 @@
213213

214214
numData = [1.3 2.4143 3.9878 4.1239 5];
215215

216-
da = b.create_data_array('floatArray', typeDA, nix.DataType.Float, [1 5]);
216+
da = b.create_data_array('floatArray', typeDA, nix.DataType.Float, 5);
217217
da.write_all(numData);
218218
assert(isequal(da.read_all, single(numData)));
219219

0 commit comments

Comments
 (0)