Skip to content

Commit 2ca141c

Browse files
committed
fixDataTypeErrors: fix String Matlab crash
1 parent 376cb97 commit 2ca141c

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

+nix/DataArray.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ function write_all(obj, data) % TODO add (optional) offset
9494
tmp = permute(data, length(size(data)):-1:1);
9595
nix_mx('DataArray::writeAll', obj.nix_handle, tmp);
9696
end;
97-
97+
9898
end;
9999
end

src/nixdataarray.cc

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,29 @@ namespace nixdataarray {
4242

4343
void read_all(const extractor &input, infusor &output)
4444
{
45-
//nix::DataArray da = input.entity<nix::DataArray>(1);
46-
mexPrintf("[PURGE_ME] DA.cc read_all 01\n");
4745
nix::DataArray da = input.entity<nix::DataArray>(1);
48-
mexPrintf("[PURGE_ME] DA.cc read_all 02\n");
4946
mxArray *data = make_mx_array_from_ds(da);
50-
mexPrintf("[PURGE_ME] DA.cc read_all 03\n");
5147
output.set(0, data);
5248
}
5349

5450
void write_all(const extractor &input, infusor &output)
5551
{
56-
mexPrintf("[PURGE_ME] DA.cc write_all 01\n");
5752
nix::DataArray da = input.entity<nix::DataArray>(1);
58-
mexPrintf("[PURGE_ME] DA.cc write_all 02\n");
5953
nix::DataType dtype = input.dtype(2);
60-
mexPrintf("[PURGE_ME] DA.cc write_all 03\n");
54+
6155
nix::NDSize count = input.ndsize(2);
62-
mexPrintf("[PURGE_ME] DA.cc write_all 04\n");
6356
nix::NDSize offset(0);
64-
mexPrintf("[PURGE_ME] DA.cc write_all 05\n");
6557
double *ptr = input.get_raw(2);
66-
mexPrintf("[PURGE_ME] DA.cc write_all 06\n");
67-
da.setData(dtype, ptr, count, offset);
68-
mexPrintf("[PURGE_ME] DA.cc write_all 07\n");
58+
59+
if (dtype == nix::DataType::String)
60+
{
61+
//da.setData(ptr);
62+
throw std::domain_error("Writing strings is not supported as of yet.");
63+
}
64+
else
65+
{
66+
da.setData(dtype, ptr, count, offset);
67+
}
6968
}
7069

7170
void delete_dimension(const extractor &input, infusor &output) {
@@ -77,4 +76,4 @@ namespace nixdataarray {
7776
output.set(0, res);
7877
}
7978

80-
} // namespace nixdataarray
79+
} // namespace nixdataarray

src/utils/mkarray.cc

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
#include <nix.hpp>
44

55
mxArray* make_mx_array_from_ds(const nix::DataSet &da) {
6-
mexPrintf("[PURGE_ME] mkArray.cc 01\n");
76
nix::NDSize size = da.dataExtent();
8-
mexPrintf("[PURGE_ME] mkArray.cc 02\n");
97
const size_t len = size.size();
10-
mexPrintf("[PURGE_ME] mkArray.cc 03\n");
118
std::vector<mwSize> dims(len);
12-
mexPrintf("[PURGE_ME] mkArray.cc 03\n");
139

1410
//NB: matlab is column-major, while HDF5 is row-major
1511
// data is correct with this, but dimensions don't
@@ -18,26 +14,27 @@ mxArray* make_mx_array_from_ds(const nix::DataSet &da) {
1814
for (size_t i = 0; i < len; i++) {
1915
dims[len - (i + 1)] = static_cast<mwSize>(size[i]);
2016
}
21-
mexPrintf("[PURGE_ME] mkArray.cc 04\n");
2217
nix::DataType da_type = da.dataType();
23-
mexPrintf("[PURGE_ME] mkArray.cc 05\n");
2418
DType2 dtype = dtype_nix2mex(da_type);
25-
mexPrintf("[PURGE_ME] mkArray.cc 06\n");
2619

2720
if (!dtype.is_valid) {
28-
mexPrintf("[PURGE_ME] mkArray.cc 07\n");
2921
throw std::domain_error("Unsupported data type");
3022
}
3123

32-
mexPrintf("[PURGE_ME] mkArray.cc 08\n");
33-
mxArray *data = mxCreateNumericArray(dims.size(), dims.data(), dtype.cid, dtype.clx);
34-
mexPrintf("[PURGE_ME] mkArray.cc 09\n");
35-
double *ptr = mxGetPr(data);
36-
mexPrintf("[PURGE_ME] mkArray.cc 10\n");
37-
nix::NDSize offset(size.size(), 0);
38-
mexPrintf("[PURGE_ME] mkArray.cc 11\n");
39-
da.getData(da_type, ptr, size, offset);
40-
mexPrintf("[PURGE_ME] mkArray.cc 12\n");
24+
mxArray *data;
25+
if (dtype.cid == mxCHAR_CLASS)
26+
{
27+
data = mxCreateCharArray(dims.size(), dims.data());
28+
// double *ptr = mxGetPr(data);
29+
// da.getData(ptr);
30+
}
31+
else
32+
{
33+
data = mxCreateNumericArray(dims.size(), dims.data(), dtype.cid, dtype.clx);
34+
double *ptr = mxGetPr(data);
35+
nix::NDSize offset(size.size(), 0);
36+
da.getData(da_type, ptr, size, offset);
37+
}
4138

4239
return data;
4340
}
@@ -105,4 +102,3 @@ mxArray* make_mx_array(const nix::Value &v)
105102
return res;
106103

107104
}
108-

0 commit comments

Comments
 (0)