static bool read_poly(int dataset, VarInfo6& info) { int complex = 0; int size = getDimsNode(dataset, &complex, info.pdims); info.size = 0; //open __refs__ node int refs = getDataSetIdFromName(dataset, "__refs__"); for (int i = 0; i < size; ++i) { std::string polyname(std::to_string(i)); int poly = getDataSetIdFromName(refs, polyname.data()); //get dims complex = 0; int dims = 0; int ret = getDatasetInfo(poly, &complex, &dims, NULL); if (ret < 0) { return false; } std::vector<int> d(dims); int datasize = getDatasetInfo(poly, &complex, &dims, d.data()); info.size += datasize * sizeof(double) * (complex + 1); } closeList6(refs); closeList6(dataset); generateInfo(info); return true; }
static types::InternalType* import_cell(int dataset) { //get sparse dimensions int complex = 0; std::vector<int> pdims; int size = getDimsNode(dataset, &complex, pdims); if (size == 0) { closeList6(dataset); return new types::Cell(); } //open __refs__ node int refs = getDataSetIdFromName(dataset, "__refs__"); std::vector<types::InternalType*> data(size); for (int i = 0; i < size; ++i) { int ref = getDataSetIdFromName(refs, std::to_string(i).data()); types::InternalType* val = import_data(ref); if (val == nullptr) { return nullptr; } data[i] = val; } types::Cell* cell = new types::Cell(static_cast<int>(pdims.size()), pdims.data(), data.data()); closeList6(refs); closeList6(dataset); return cell; }
static types::InternalType* import_boolean_sparse(int dataset) { //get sparse dimensions int complex = 0; std::vector<int> pdims; int size = getDimsNode(dataset, &complex, pdims); //get non zeros count int nnz = 0; int datannz = getDataSetIdFromName(dataset, "__nnz__"); readInteger32Matrix(datannz, &nnz); if (nnz == 0) { closeList6(dataset); return new types::SparseBool(pdims[0], pdims[1]); } //get inner vector int datain = getDataSetIdFromName(dataset, "__inner__"); int dimin = 0; int sizein = getDatasetInfo(datain, &complex, &dimin, NULL); std::vector<int> dimsin(dimin); sizein = getDatasetInfo(datain, &complex, &dimin, dimsin.data()); std::vector<int> in(sizein); int ret = readInteger32Matrix(datain, in.data()); if (ret < 0) { closeList6(dataset); return nullptr; } //get outer vector int dataout = getDataSetIdFromName(dataset, "__outer__"); int dimout = 0; int sizeout = getDatasetInfo(dataout, &complex, &dimout, NULL); std::vector<int> dimsout(dimout); sizeout = getDatasetInfo(dataout, &complex, &dimout, dimsout.data()); std::vector<int> out(sizeout); ret = readInteger32Matrix(dataout, out.data()); if (ret < 0) { closeList6(dataset); return nullptr; } closeList6(dataset); return new types::SparseBool(pdims[0], pdims[1], nnz, in.data(), out.data()); }
static int getDimsNode(int dataset, int* complex, std::vector<int>& dims) { dims.clear(); int id = getDataSetIdFromName(dataset, "__dims__"); if (id < 0) { return 0; } //get dims dimension count int dim = 0; getDatasetInfo(id, complex, &dim, NULL); //get dims dimension std::vector<int> d(dim); int size = getDatasetInfo(id, complex, &dim, d.data()); //get dims value dims.resize(size); readInteger32Matrix(id, dims.data()); size = dims[0]; for (int i = 1; i < dims.size(); ++i) { size *= dims[i]; } return size; }
static bool import_variable(int file, std::string& name) { int dataset = getDataSetIdFromName(file, name.data()); if (dataset <= 0) { return false; } types::InternalType* data = import_data(dataset); if (data != nullptr) { wchar_t* var = to_wide_string(name.data()); //update macro name if (data->isMacro()) { types::Macro* macro = data->getAs<types::Macro>(); macro->setName(var); symbol::Context::getInstance()->addMacro(macro); } else { //add to context symbol::Context::getInstance()->put(symbol::Symbol(var), data); } FREE(var); return true; } return false; }
static bool import_variable(int* pvCtx, int _iFile, char* _pstVarName) { int iDataSetId = getDataSetIdFromName(_iFile, _pstVarName); if (iDataSetId <= 0) { return false; } return import_data(pvCtx, iDataSetId, 0, NULL, _pstVarName); }
static bool read_cell(int dataset, VarInfo6& info) { //get cell dimensions int complex = 0; int size = getDimsNode(dataset, &complex, info.pdims); info.dims = static_cast<int>(info.pdims.size()); if (size == 0) { info.size = 0; generateInfo(info); closeList6(dataset); return true; } //open __refs__ node int refs = getDataSetIdFromName(dataset, "__refs__"); for (int i = 0; i < size; ++i) { int ref = getDataSetIdFromName(refs, std::to_string(i).data()); VarInfo6 info2; if (read_data(ref, info2) == false) { closeList6(refs); closeList6(dataset); return false; } info.size += info2.size; } closeList6(refs); closeList6(dataset); generateInfo(info); return true; }
static types::InternalType* import_list(int dataset, types::List* lst) { int count = 0; int ret = getListDims6(dataset, &count); if (ret) { closeList6(dataset); delete lst; return nullptr; } if (count == 0) { closeList6(dataset); return lst; } //get children for (int i = 0; i < count; ++i) { int data = getDataSetIdFromName(dataset, std::to_string(i).data()); if (data <= 0) { closeList6(dataset); delete lst; return nullptr; } types::InternalType* child = import_data(data); if (child == nullptr) { closeList6(dataset); delete lst; return nullptr; } lst->append(child); if (child->isList()) { child->killMe(); } } closeList6(dataset); return lst; }
static bool read_boolean_sparse(int dataset, VarInfo6& info) { int complex = 0; std::vector<int> pdims; int size = getDimsNode(dataset, &complex, pdims); //get non zeros count int nnz = 0; int datannz = getDataSetIdFromName(dataset, "__nnz__"); readInteger32Matrix(datannz, &nnz); info.dims = 2; info.pdims[0] = pdims[0]; info.pdims[1] = pdims[1]; //rows(int) + nnz(int) info.size = info.pdims[0] * sizeof(int) + nnz * sizeof(int); generateInfo(info); closeList6(dataset); return true; }
static bool read_list(int dataset, VarInfo6& info, std::string type) { int ret = 0; int items = 0; ret = getListDims6(dataset, &items); if (ret) { return false; } info.dims = 1; info.pdims.resize(1); info.pdims[0] = items; info.size = 0; for (int i = 0; i < items; i++) { int data = getDataSetIdFromName(dataset, std::to_string(i).data()); if (data <= 0) { closeList6(dataset); return false; } VarInfo6 info2; bool bRet = read_data(data, info2); if (bRet == false) { return false; } info.size += info2.size; } closeList6(dataset); generateInfo(info); return true; }
int sci_hdf5_listvar_v2(char *fname, int* pvApiCtx) { SciErr sciErr; int *piAddr = NULL; char* pstFile = NULL; int iFile = 0; int iNbItem = 0; VarInfo* pInfo = NULL; const int nbIn = nbInputArgument(pvApiCtx); CheckInputArgument(pvApiCtx, 1, 1); CheckOutputArgument(pvApiCtx, 1, 4); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &pstFile)) { if (pstFile) { FREE(pstFile); } Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1); return 1; } char* pstFileName = expandPathVariable(pstFile); iFile = openHDF5File(pstFileName, 0); if (iFile < 0) { Scierror(999, _("%s: Unable to open file: %s\n"), fname, pstFile); FREE(pstFileName); FREE(pstFile); return 1; } FREE(pstFileName); FREE(pstFile); //manage version information int iVersion = getSODFormatAttribute(iFile); if (iVersion != SOD_FILE_VERSION) { if (iVersion > SOD_FILE_VERSION) { //can't read file with version newer that me ! closeHDF5File(iFile); Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname, SOD_FILE_VERSION, iVersion); return 1; } else { //call older import functions and exit or ... EXIT ! if (iVersion == 1 || iVersion == -1) { //sciprint("old sci_listvar_in_hdf5_v1\n"); return sci_listvar_in_hdf5_v1(fname, pvApiCtx); } } } iNbItem = getVariableNames(iFile, NULL); if (iNbItem != 0) { char** pstVarNameList = (char**)MALLOC(sizeof(char*) * iNbItem); pInfo = (VarInfo*)MALLOC(iNbItem * sizeof(VarInfo)); int b; if (Lhs == 1) { sciprint("Name Type Size Bytes\n"); sciprint("---------------------------------------------------------------\n"); } iNbItem = getVariableNames(iFile, pstVarNameList); for (int i = 0; i < iNbItem; i++) { int iDataSetId = getDataSetIdFromName(iFile, pstVarNameList[i]); if (iDataSetId == 0) { break; } strncpy(pInfo[i].varName, pstVarNameList[i], sizeof(pInfo[i].varName) - 1); pInfo[i].iSize = 0; b = read_data(iDataSetId, 0, NULL, &pInfo[i]) == false; if (b) { break; } if (Lhs == 1) { sciprint("%s\n", pInfo[i].pstInfo); } } freeArrayOfString(pstVarNameList, iNbItem); } else { //no variable returms [] for each Lhs for (int i = 0 ; i < Lhs ; i++) { createEmptyMatrix(pvApiCtx, nbIn + i + 1); AssignOutputVariable(pvApiCtx, i + 1) = nbIn + i + 1; } ReturnArguments(pvApiCtx); return 0; } closeHDF5File(iFile); //1st Lhs char** pstVarName = (char**)MALLOC(sizeof(char*) * iNbItem); for (int i = 0 ; i < iNbItem ; i++) { pstVarName[i] = pInfo[i].varName; } sciErr = createMatrixOfString(pvApiCtx, nbIn + 1, iNbItem, 1, pstVarName); FREE(pstVarName); if (sciErr.iErr) { FREE(pInfo); printError(&sciErr, 0); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbIn + 1; if (Lhs > 1) { //2nd Lhs double* pdblType; sciErr = allocMatrixOfDouble(pvApiCtx, nbIn + 2, iNbItem, 1, &pdblType); if (sciErr.iErr) { printError(&sciErr, 0); FREE(pInfo); return 1; } for (int i = 0 ; i < iNbItem ; i++) { pdblType[i] = pInfo[i].iType; } AssignOutputVariable(pvApiCtx, 2) = nbIn + 2; if (Lhs > 2) { //3rd Lhs int* pList = NULL; sciErr = createList(pvApiCtx, nbIn + 3, iNbItem, &pList); for (int i = 0 ; i < iNbItem ; i++) { double* pdblDims = NULL; allocMatrixOfDoubleInList(pvApiCtx, nbIn + 3, pList, i + 1, 1, pInfo[i].iDims, &pdblDims); for (int j = 0 ; j < pInfo[i].iDims ; j++) { pdblDims[j] = pInfo[i].piDims[j]; } } AssignOutputVariable(pvApiCtx, 3) = nbIn + 3; } if (Lhs > 3) { //4th Lhs double* pdblSize = NULL; sciErr = allocMatrixOfDouble(pvApiCtx, nbIn + 4, iNbItem, 1, &pdblSize); for (int i = 0 ; i < iNbItem ; i++) { pdblSize[i] = pInfo[i].iSize; } AssignOutputVariable(pvApiCtx, 4) = nbIn + 4; } } FREE(pInfo); ReturnArguments(pvApiCtx); return 0; }
types::Function::ReturnValue sci_hdf5_listvar_v3(types::typed_list &in, int _iRetCount, types::typed_list &out) { int rhs = static_cast<int>(in.size()); if (rhs != 1) { Scierror(999, _("%s: Wrong number of input argument(s): %d expected.\n"), fname.data(), 1); return types::Function::Error; } if (_iRetCount < 1 && _iRetCount > 4) { Scierror(999, _("%s: Wrong number of output argument(s): %d to %d expected.\n"), fname.data(), 1, 4); return types::Function::Error; } //get filename if (in[0]->getId() != types::InternalType::IdScalarString) { Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname.data(), 1); return types::Function::Error; } //open hdf5 file wchar_t* wfilename = expandPathVariableW(in[0]->getAs<types::String>()->get()[0]); char* cfilename = wide_string_to_UTF8(wfilename); std::string filename = cfilename; FREE(wfilename); FREE(cfilename); int iFile = openHDF5File(filename.data(), 0); if (iFile < 0) { Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), filename.data()); return types::Function::Error; } //manage version information int iVersion = getSODFormatAttribute(iFile); if (iVersion != SOD_FILE_VERSION) { //can't read file with version newer that me ! closeHDF5File(iFile); Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, iVersion); return types::Function::Error; } int items = getVariableNames6(iFile, nullptr); std::vector<VarInfo6> info(items); if (items != 0) { std::vector<char*> vars(items); items = getVariableNames6(iFile, vars.data()); if (_iRetCount == 1) { sciprint("Name Type Size Bytes\n"); sciprint("-------------------------------------------------------------\n"); } for (int i = 0; i < items; i++) { info[i].name = vars[i]; FREE(vars[i]); info[i].size = 0; int dset = getDataSetIdFromName(iFile, info[i].name.data()); if (dset == 0) { break; } if (_iRetCount != 2) { if (read_data(dset, info[i]) == false) { break; } if (_iRetCount == 1) { sciprint("%s\n", info[i].info); } } else // == 2 { if (read_short_data(dset, info[i]) == false) { break; } } } } else { //no variable returms [] for each Lhs for (int i = 0; i < _iRetCount; i++) { out.push_back(types::Double::Empty()); } return types::Function::OK; } closeHDF5File(iFile); //1st Lhs types::String* out1 = new types::String(items, 1); for (int i = 0; i < items; i++) { out1->set(i, info[i].name.data()); } out.push_back(out1); //2nd if (_iRetCount > 1) { types::Double* out2 = new types::Double(items, 1); double* pout2 = out2->get(); for (int i = 0; i < items; i++) { pout2[i] = info[i].type; } out.push_back(out2); } if (_iRetCount > 2) { //3rd Lhs types::List* out3 = new types::List(); for (int i = 0; i < items; i++) { int dims = info[i].dims; types::Double* item = new types::Double(1, dims); double* pitem = item->get(); for (int j = 0; j < dims; j++) { pitem[j] = static_cast<double>(info[i].pdims[j]); } out3->append(item); } out.push_back(out3); } if (_iRetCount > 3) { //4th Lhs types::Double* out4 = new types::Double(items, 1); double* pout4 = out4->get(); for (int i = 0; i < items; i++) { pout4[i] = info[i].size; } out.push_back(out4); } return types::Function::OK; }
static bool read_struct(int dataset, VarInfo6& info) { int complex = 0; int size = getDimsNode(dataset, &complex, info.pdims); info.dims = static_cast<int>(info.pdims.size()); info.size = 0; if (size == 0) { generateInfo(info); closeList6(dataset); return true; } int fieldCount = 0; int ret = getListDims6(dataset, &fieldCount); if (ret < 0) { closeList6(dataset); return false; } //open __refs__ node int refs = getDataSetIdFromName(dataset, "__refs__"); H5O_info_t oinfo; for (int i = 0; i < fieldCount; ++i) { H5Oget_info_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_NATIVE, i, &oinfo, H5P_DEFAULT); ssize_t len = H5Lget_name_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_INC, i, 0, 0, H5P_DEFAULT) + 1; char* name = (char*)MALLOC(sizeof(char) * len); H5Lget_name_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_INC, i, name, len, H5P_DEFAULT); std::string cname(name); FREE(name); if (cname != "__dims__" && cname != "__refs__") { int dataref = getDataSetIdFromName(dataset, cname.data()); if (dataref < 0) { closeList6(dataset); return false; } int refdim = 0; getDatasetInfo(dataref, &complex, &refdim, NULL); std::vector<int> refdims(refdim); int refcount = getDatasetInfo(dataref, &complex, &refdim, refdims.data()); std::vector<hobj_ref_t> vrefs(refcount); ret = H5Dread(dataref, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, vrefs.data()); if (ret < 0) { return false; } //import field for (int j = 0; j < refcount; ++j) { int data = H5Rdereference(refs, H5R_OBJECT, &vrefs[j]); if (data < 0) { return false; } VarInfo6 info2; ret = read_data(data, info2); if (ret == false) { return false; } info.size += info2.size; } closeDataSet(dataref); } } generateInfo(info); closeList6(refs); closeList6(dataset); return true; }
static types::InternalType* import_struct(int dataset) { //get struct dims node int complex = 0; std::vector<int> pdims; int size = getDimsNode(dataset, &complex, pdims); types::Struct* str = new types::Struct(static_cast<int>(pdims.size()), pdims.data()); size = str->getSize(); if (size == 0) { //empty struct closeList6(dataset); delete str; return new types::Struct(); } types::SingleStruct** sstr = str->get(); int fieldCount = 0; int ret = getListDims6(dataset, &fieldCount); if (ret < 0) { closeList6(dataset); return str; } //get fields name int dfield = getDataSetIdFromName(dataset, "__fields__"); int dim = 0; getDatasetInfo(dfield, &complex, &dim, NULL); std::vector<int> d(dim); size = getDatasetInfo(dfield, &complex, &dim, d.data()); if (size < 0) { closeList6(dataset); delete str; return nullptr; } //get dims value std::vector<char*> fields(size); readStringMatrix(dfield, fields.data()); //open __refs__ node int refs = getDataSetIdFromName(dataset, "__refs__"); for (const auto & name : fields) { wchar_t* field = to_wide_string(name); str->addField(field); int dataref = getDataSetIdFromName(dataset, name); if (dataref < 0) { closeList6(dataset); freeStringMatrix(dfield, fields.data()); FREE(field); delete str; return nullptr; } int refdim = 0; getDatasetInfo(dataref, &complex, &refdim, NULL); std::vector<int> refdims(refdim); int refcount = getDatasetInfo(dataref, &complex, &refdim, refdims.data()); std::vector<hobj_ref_t> vrefs(refcount); ret = H5Dread(dataref, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, vrefs.data()); if (ret < 0) { freeStringMatrix(dfield, fields.data()); FREE(field); delete str; return nullptr; } //import field for (int j = 0; j < refcount; ++j) { int data = H5Rdereference(refs, H5R_OBJECT, &vrefs[j]); if (data < 0) { freeStringMatrix(dfield, fields.data()); FREE(field); delete str; return nullptr; } types::InternalType* val = import_data(data); if (val == nullptr) { freeStringMatrix(dfield, fields.data()); FREE(field); delete str; return nullptr; } sstr[j]->set(field, val); } FREE(field); closeDataSet(dataref); } freeStringMatrix(dfield, fields.data()); closeList6(refs); closeList6(dataset); return str; }
static types::InternalType* import_macro(int dataset) { int complex = 0; int dims = 0; int size = 0; std::vector<int> d(2); std::list<symbol::Variable*>* inputList = new std::list<symbol::Variable*>(); std::list<symbol::Variable*>* outputList = new std::list<symbol::Variable*>(); ast::Exp* body = nullptr; symbol::Context* ctx = symbol::Context::getInstance(); //inputs int inputNode = getDataSetIdFromName(dataset, "inputs"); size = getDatasetInfo(inputNode, &complex, &dims, d.data()); if (size < 0) { delete inputList; delete outputList; closeList6(dataset); return nullptr; } std::vector<char*> inputNames(size); if (size != 0) { readStringMatrix(inputNode, inputNames.data()); for (auto & input : inputNames) { wchar_t* winput = to_wide_string(input); symbol::Variable* var = ctx->getOrCreate(symbol::Symbol(winput)); FREE(winput); inputList->push_back(var); } freeStringMatrix(inputNode, inputNames.data()); } else { closeDataSet(inputNode); } //outputs int outputNode = getDataSetIdFromName(dataset, "outputs"); size = getDatasetInfo(outputNode, &complex, &dims, d.data()); if (size < 0) { delete inputList; delete outputList; closeList6(dataset); return nullptr; } std::vector<char*> outputNames(size); if (size != 0) { readStringMatrix(outputNode, outputNames.data()); for (auto & output : outputNames) { wchar_t* woutput = to_wide_string(output); symbol::Variable* var = ctx->getOrCreate(symbol::Symbol(woutput)); FREE(woutput); outputList->push_back(var); } freeStringMatrix(outputNode, outputNames.data()); } else { closeDataSet(outputNode); } //body int bodyNode = getDataSetIdFromName(dataset, "body"); size = getDatasetInfo(bodyNode, &complex, &dims, d.data()); if (size < 0) { delete inputList; delete outputList; closeList6(dataset); return nullptr; } std::vector<unsigned char> bodybin(size); readUnsignedInteger8Matrix(bodyNode, bodybin.data()); ast::DeserializeVisitor ds(bodybin.data()); body = ds.deserialize(); //wname+1 is to remove "/" at the start of the var name from HDF5 types::Macro* macro = new types::Macro(L"", *inputList, *outputList, *body->getAs<ast::SeqExp>(), L"script"); delete body; closeList6(dataset); return macro; }
static types::InternalType* import_handles(int dataset) { //get sparse dimensions int complex = 0; std::vector<int> pdims; int size = getDimsNode(dataset, &complex, pdims); if (size == 0) { closeList6(dataset); return nullptr; } //open __refs__ node int refs = getDataSetIdFromName(dataset, "__refs__"); types::GraphicHandle* handles = new types::GraphicHandle(static_cast<int>(pdims.size()), pdims.data()); long long* h = handles->get(); if (size == 1) { //%h_copy int ref = getDataSetIdFromName(refs, std::to_string(0).data()); int val = add_current_entity(ref); if (val < 0) { return nullptr; } h[0] = getHandle(val); } else { for (int i = 0; i < size; ++i) { int ref = getDataSetIdFromName(refs, std::to_string(i).data()); int val = import_handle(ref, -1); if (val < 0) { return nullptr; } h[i] = getHandle(val); } } closeList6(refs); closeList6(dataset); //update links property of legend handle if (Links::count()) { std::list<int> legends = Links::legends(); for (auto & i : legends) { Links::PathList paths = Links::get(i); update_link_path(i, paths); } } return handles; }
static types::InternalType* import_poly(int dataset) { //get poly dims node int complex = 0; std::vector<int> pdims; int size = getDimsNode(dataset, &complex, pdims); //get variable name char* var = NULL; int varname = getDataSetIdFromName(dataset, "__varname__"); readStringMatrix(varname, &var); wchar_t* wvar = to_wide_string(var); std::wstring wvarname(wvar); FREE(wvar); freeStringMatrix(varname, &var); types::Polynom* p = new types::Polynom(wvarname, static_cast<int>(pdims.size()), pdims.data()); types::SinglePoly** pss = p->get(); //open __refs__ node int refs = getDataSetIdFromName(dataset, "__refs__"); size = p->getSize(); //loop on children for (int i = 0; i < size; ++i) { //forge name std::string polyname(std::to_string(i)); int poly = getDataSetIdFromName(refs, polyname.data()); //get dims complex = 0; int dims = 0; int ret = getDatasetInfo(poly, &complex, &dims, NULL); if (ret < 0) { return nullptr; } std::vector<int> d(dims); int datasize = getDatasetInfo(poly, &complex, &dims, d.data()); types::SinglePoly* ss = NULL; //get coef if (dims == 0 || datasize <= 0) { ss = new types::SinglePoly(); } else if (complex) { double* real = NULL; double* img = NULL; //create singlepoly ss = new types::SinglePoly(&real, &img, datasize - 1); readDoubleComplexMatrix(poly, real, img); } else { double* real = NULL; ss = new types::SinglePoly(&real, datasize - 1); readDoubleMatrix(poly, real); } pss[i] = ss; } closeList6(refs); closeList6(dataset); return p; }
static types::InternalType* import_sparse(int dataset) { types::Sparse* sp = nullptr; //get sparse dimensions int complex = 0; std::vector<int> pdims; int size = getDimsNode(dataset, &complex, pdims); //get non zeros count int nnz = 0; int datannz = getDataSetIdFromName(dataset, "__nnz__"); readInteger32Matrix(datannz, &nnz); if (nnz == 0) { closeList6(dataset); return new types::Sparse(pdims[0], pdims[1]); } //get inner vector int datain = getDataSetIdFromName(dataset, "__inner__"); int dimin = 0; int sizein = getDatasetInfo(datain, &complex, &dimin, NULL); std::vector<int> dimsin(dimin); sizein = getDatasetInfo(datain, &complex, &dimin, dimsin.data()); if (sizein < 0) { closeList6(dataset); return nullptr; } std::vector<int> in(sizein); int ret = readInteger32Matrix(datain, in.data()); if (ret < 0) { closeList6(dataset); return nullptr; } //get outer vector int dataout = getDataSetIdFromName(dataset, "__outer__"); int dimout = 0; int sizeout = getDatasetInfo(dataout, &complex, &dimout, NULL); std::vector<int> dimsout(dimout); sizeout = getDatasetInfo(dataout, &complex, &dimout, dimsout.data()); if (sizeout < 0) { closeList6(dataset); return nullptr; } std::vector<int> out(sizeout); ret = readInteger32Matrix(dataout, out.data()); if (ret < 0) { closeList6(dataset); return nullptr; } //get data int ddata = getDataSetIdFromName(dataset, "__data__"); int dimdata = 0; int sizedata = getDatasetInfo(ddata, &complex, &dimdata, NULL); std::vector<int> dimsdata(dimdata); sizedata = getDatasetInfo(ddata, &complex, &dimdata, dimsdata.data()); if (sizedata < 0) { closeList6(dataset); return nullptr; } std::vector<double> real(sizedata); if (complex) { std::vector<double> img(sizedata); ret = readDoubleComplexMatrix(ddata, real.data(), img.data()); if (ret < 0) { closeList6(dataset); return nullptr; } sp = new types::Sparse(pdims[0], pdims[1], nnz, in.data(), out.data(), real.data(), img.data()); } else { ret = readDoubleMatrix(ddata, real.data()); if (ret < 0) { closeList6(dataset); return nullptr; } sp = new types::Sparse(pdims[0], pdims[1], nnz, in.data(), out.data(), real.data(), nullptr); } closeList6(dataset); return sp; }