Ejemplo n.º 1
0
int readCommonSparseComplexMatrix(int _iDatasetId, int _iComplex, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow, int *_piColPos, double *_pdblReal, double *_pdblImg)
{
    hid_t obj = 0;
    hobj_ref_t pRef[3] = {0};
    herr_t status;

    /*
     * Read the data.
     */
    status = H5Dread(_iDatasetId, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, pRef);
    if (status < 0)
    {
        return -1;
    }

    //read Row data
    obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[0]);
    status = readInteger32Matrix(obj, _piNbItemRow);
    if (status < 0)
    {
        return -1;
    }

    //read cols data
    obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[1]);
    status = readInteger32Matrix(obj, _piColPos);
    if (status < 0)
    {
        return -1;
    }

    //read sparse data
    obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[2]);

    if (_iComplex)
    {
        status = readDoubleComplexMatrix(obj, _pdblReal, _pdblImg);
    }
    else
    {
        status = readDoubleMatrix(obj, _pdblReal);
    }

    if (status < 0)
    {
        return -1;
    }

    status = H5Dclose(_iDatasetId);
    if (status < 0)
    {
        return -1;
    }

    return 0;
}
Ejemplo n.º 2
0
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());
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
int readBooleanSparseMatrix(int _iDatasetId, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow, int *_piColPos)
{
    hid_t obj = 0;
    hobj_ref_t pRef[2] = {0};
    herr_t status;

    /*
     * Read the data.
     */
    status = H5Dread(_iDatasetId, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, pRef);
    if (status < 0)
    {
        return -1;
    }

    //read Row data
    obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[0]);
    status = readInteger32Matrix(obj, _piNbItemRow);
    if (status < 0)
    {
        return -1;
    }

    if (_iNbItem != 0)
    {
        //read cols data
        obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[1]);
        status = readInteger32Matrix(obj, _piColPos);
        if (status < 0)
        {
            return -1;
        }
    }

    status = H5Dclose(_iDatasetId);
    if (status < 0)
    {
        return -1;
    }
    return 0;
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
static bool import_integer(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
{
    int iRet = 0;
    int iDims = 0;
    int* piDims = NULL;
    int iComplex = 0;
    int iSize = 0;
    int iPrec = 0;
    SciErr sciErr;

    iRet = getDatasetInfo(_iDatasetId, &iComplex, &iDims, NULL);
    if (iRet < 0)
    {
        return false;
    }

    piDims = (int*)MALLOC(sizeof(int) * iDims);
    iSize = getDatasetInfo(_iDatasetId, &iComplex, &iDims, piDims);

    iRet = getDatasetPrecision(_iDatasetId, &iPrec);
    if (iRet)
    {
        FREE(piDims);
        return false;
    }

    switch (iPrec)
    {
        case SCI_INT8:
        {
            char *pcData = NULL;

            pcData = (char *)MALLOC(sizeof(char) * iSize);
            iRet = readInteger8Matrix(_iDatasetId, pcData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfInteger8(pvCtx, _pstVarname, piDims[0], piDims[1], pcData);
            }
            else
            {
                sciErr = createMatrixOfInteger8InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pcData);
            }

            FREE(pcData);
        }
        break;
        case SCI_UINT8:
        {
            unsigned char *pucData = NULL;

            pucData = (unsigned char *)MALLOC(sizeof(unsigned char) * iSize);
            iRet = readUnsignedInteger8Matrix(_iDatasetId, pucData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfUnsignedInteger8(pvCtx, _pstVarname, piDims[0], piDims[1], pucData);
            }
            else
            {
                sciErr = createMatrixOfUnsignedInteger8InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pucData);
            }

            FREE(pucData);
        }
        break;
        case SCI_INT16:
        {
            short *psData = NULL;

            psData = (short *)MALLOC(sizeof(short) * iSize);
            iRet = readInteger16Matrix(_iDatasetId, psData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfInteger16(pvCtx, _pstVarname, piDims[0], piDims[1], psData);
            }
            else
            {
                sciErr = createMatrixOfInteger16InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], psData);
            }

            FREE(psData);
        }
        break;
        case SCI_UINT16:
        {
            unsigned short *pusData = NULL;

            pusData = (unsigned short *)MALLOC(sizeof(unsigned short) * iSize);
            iRet = readUnsignedInteger16Matrix(_iDatasetId, pusData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfUnsignedInteger16(pvCtx, _pstVarname, piDims[0], piDims[1], pusData);
            }
            else
            {
                sciErr = createMatrixOfUnsignedInteger16InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pusData);
            }

            FREE(pusData);
        }
        break;
        case SCI_INT32:
        {
            int *piData = NULL;

            piData = (int *)MALLOC(sizeof(int) * iSize);
            iRet = readInteger32Matrix(_iDatasetId, piData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfInteger32(pvCtx, _pstVarname, piDims[0], piDims[1], piData);
            }
            else
            {
                sciErr = createMatrixOfInteger32InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], piData);
            }

            FREE(piData);
        }
        break;
        case SCI_UINT32:
        {
            unsigned int *puiData = NULL;

            puiData = (unsigned int *)MALLOC(sizeof(unsigned int) * iSize);
            iRet = readUnsignedInteger32Matrix(_iDatasetId, puiData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfUnsignedInteger32(pvCtx, _pstVarname, piDims[0], piDims[1], puiData);
            }
            else
            {
                sciErr = createMatrixOfUnsignedInteger32InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], puiData);
            }

            FREE(puiData);
        }
        break;
        case SCI_INT64:
        {
#ifdef __SCILAB_INT64__
            long long *pllData = NULL;

            pllData = (long long *)MALLOC(sizeof(long long) * iSize);
            iRet = readInteger64Matrix(_iDatasetId, pllData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfInteger64(pvCtx, _pstVarname, piDims[0], piDims[1], pllData);
            }
            else
            {
                sciErr = createMatrixOfInteger64InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pllData);
            }

            FREE(pllData);
#else
            FREE(piDims);
            return false;
#endif
        }
        break;
        case SCI_UINT64:
        {
#ifdef __SCILAB_INT64__
            unsigned long long *pullData = NULL;

            pullData = (unsigned long long *)MALLOC(sizeof(unsigned long long) * iSize);
            iRet = readUnsignedInteger64Matrix(_iDatasetId, pullData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfUnsignedInteger64(pvCtx, _pstVarname, piDims[0], piDims[1], pullData);
            }
            else
            {
                sciErr = createMatrixOfUnsignedInteger64InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pullData);
            }

            FREE(pullData);
#else
            FREE(piDims);
            return false;
#endif
        }
        break;
        default:
            return false;
    }

    FREE(piDims);

    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return false;
    }

    return true;
}
Ejemplo n.º 7
0
static bool import_cell(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname)
{
    int iRet = 0;
    int iComplex = 0;
    int iDims = 0;
    int iItems = 0;
    hobj_ref_t *piItemRef = NULL;

    // an hypermatrix is stored in an mlist
    if (_iVarType != sci_mlist)
    {
        return false;
    }

    iRet = getListDims(_iDatasetId, &iItems);
    if (iRet)
    {
        return false;
    }

    if (iItems != 3)
    {
        // cell have 3 elements
        return false;
    }

    iRet = getListItemReferences(_iDatasetId, &piItemRef);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get first item
    int iItemDataset = 0;
    iRet = getListItemDataset(_iDatasetId, piItemRef, 0, &iItemDataset);
    if (iRet || iItemDataset == 0)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get first item type
    int iItemType = getScilabTypeFromDataSet(iItemDataset);
    if (iItemType != sci_strings)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get size of first item
    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
    if (iRet < 0 || iDims != 2)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    int* piDims = new int[2];
    int iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
    if (iSize != 3)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        return false;
    }

    delete[] piDims;
    piDims = NULL;

    // get data of first item for check the type of mlist
    char** pstData = new char*[iSize];
    iRet = readStringMatrix(iItemDataset, pstData);
    if (iRet || strcmp(pstData[0], "ce") != 0)
    {
        // if not the good type, do not h5close (deleteListItemReferences)
        FREE(piItemRef);
        freeStringMatrix(iItemDataset, pstData);
        delete[] pstData;
        return false;
    }

    freeStringMatrix(iItemDataset, pstData);
    delete[] pstData;
    pstData = NULL;

    // get second item, the Size of cell
    iRet = getListItemDataset(_iDatasetId, piItemRef, 1, &iItemDataset);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
    if (iRet < 0 || iDims != 2)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    piDims = new int[2];
    iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
    if (piDims[0] != 1)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        return false;
    }

    int* piDimsArray = new int[piDims[1]];
    iRet = readInteger32Matrix(iItemDataset, piDimsArray);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        delete[] piDimsArray;
        return false;
    }

    types::Cell* pCell = new types::Cell(piDims[1], piDimsArray);
    types::List* pList = new types::List();
    pList->set(0, types::Double::Empty());

    iRet = getListItemDataset(_iDatasetId, piItemRef, 2, &iItemDataset);
    if (iRet || iItemDataset == 0)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete pList;
        delete pCell;
        return false;
    }

    bool bRet = import_data(pvCtx, iItemDataset, 1, (int*)pList, NULL);
    if (bRet == false)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete pList;
        delete pCell;
        return false;
    }

    types::List* pListData = pList->get(0)->getAs<types::List>();
    for (int iWriteData = 0; iWriteData < pCell->getSize(); ++iWriteData)
    {
        pCell->set(iWriteData, pListData->get(iWriteData));
    }

    delete pList;

    if (_piAddress == NULL)
    {
        wchar_t* pwstName = to_wide_string(_pstVarname);
        symbol::Context::getInstance()->put(symbol::Symbol(pwstName), pCell);
        FREE(pwstName);
    }
    else
    {
        types::List* pParentList = (types::List*)_piAddress;
        pParentList->set(_iItemPos - 1, pCell);
    }

    iRet = deleteListItemReferences(_iDatasetId, piItemRef);

    if (iRet)
    {
        return false;
    }

    return true;
}
Ejemplo n.º 8
0
static bool import_struct(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname)
{
    int iRet = 0;
    int iComplex = 0;
    int iDims = 0;
    int iItems = 0;
    hobj_ref_t *piItemRef = NULL;

    // an struct is stored in an mlist
    if (_iVarType != sci_mlist)
    {
        return false;
    }

    iRet = getListDims(_iDatasetId, &iItems);
    if (iRet)
    {
        return false;
    }

    if (iItems < 2)
    {
        // struct have 2 elements minimal
        return false;
    }

    iRet = getListItemReferences(_iDatasetId, &piItemRef);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get first item
    int iItemDataset = 0;
    iRet = getListItemDataset(_iDatasetId, piItemRef, 0, &iItemDataset);
    if (iRet || iItemDataset == 0)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get first item type
    int iItemType = getScilabTypeFromDataSet(iItemDataset);
    if (iItemType != sci_strings)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get size of first item
    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
    if (iRet < 0 || iDims != 2)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    int* piDims = new int[2];
    int iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
    if (iSize != iItems)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        return false;
    }

    delete[] piDims;
    piDims = NULL;

    // get data of first item for check the type of mlist
    char** pstData = new char*[iSize];
    char** pstDataSave = new char*[iSize - 2];
    iRet = readStringMatrix(iItemDataset, pstData);
    if (iRet || strcmp(pstData[0], "st") != 0)
    {
        // if not the good type, do not h5close (deleteListItemReferences)
        FREE(piItemRef);
        freeStringMatrix(iItemDataset, pstData);
        delete[] pstData;
        delete[] pstDataSave;
        return false;
    }

    for (int i = 2; i < iSize; ++i)
    {
        pstDataSave[-2 + i] = new char[strlen(pstData[i]) + 1];
        strcpy(pstDataSave[-2 + i], pstData[i]);
    }

    freeStringMatrix(iItemDataset, pstData);
    delete[] pstData;
    pstData = NULL;

    // get second item, the Size of struct
    iRet = getListItemDataset(_iDatasetId, piItemRef, 1, &iItemDataset);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        for (int i = 0; i < (-2 + iItems); ++i)
        {
            delete pstDataSave[i];
        }
        delete[] pstDataSave;
        pstDataSave = NULL;
        return false;
    }

    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
    if (iRet < 0 || iDims != 2)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        for (int i = 0; i < (-2 + iItems); ++i)
        {
            delete pstDataSave[i];
        }
        delete[] pstDataSave;
        pstDataSave = NULL;
        return false;
    }

    piDims = new int[2];
    iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
    if (piDims[0] != 1)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        for (int i = 0; i < (-2 + iItems); ++i)
        {
            delete pstDataSave[i];
        }
        delete[] pstDataSave;
        pstDataSave = NULL;
        delete[] piDims;
        return false;
    }

    int* piDimsArray = new int[piDims[1]];
    iRet = readInteger32Matrix(iItemDataset, piDimsArray);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        for (int i = 0; i < (-2 + iItems); ++i)
        {
            delete pstDataSave[i];
        }
        delete[] pstDataSave;
        pstDataSave = NULL;
        delete[] piDims;
        delete[] piDimsArray;
        return false;
    }

    types::Struct* pStruct = new types::Struct(piDims[1], piDimsArray);

    wchar_t* pwstName = NULL;
    for (int i = 0; i < (-2 + iItems); ++i)
    {
        pwstName = to_wide_string(pstDataSave[i]);
        pStruct->addField(pwstName);
        delete pstDataSave[i];
        FREE(pwstName);
    }

    delete[] pstDataSave;
    pstDataSave = NULL;

    types::SingleStruct** ppSStruct =  pStruct->get();
    types::String* pStr = pStruct->getFieldNames();

    types::List* pList = new types::List();
    // fill the list to avoid api_scilab error about the list size.
    pList->set(0, types::Double::Empty());

    if (pStruct->getSize() == 1)
    {
        types::InternalType* pIT = NULL;
        for (int i = 0; i < pStr->getSize(); ++i)
        {
            int iItemDataset = 0;
            iRet = getListItemDataset(_iDatasetId, piItemRef, i + 2, &iItemDataset);
            if (iRet || iItemDataset == 0)
            {
                deleteListItemReferences(_iDatasetId, piItemRef);
                delete pList;
                delete pStruct;
                return false;
            }

            wchar_t* pwcsName = pStr->get(i);
            char* pcName = wide_string_to_UTF8(pwcsName);

            bool bRet = import_data(pvCtx, iItemDataset, 1, (int*)pList, pcName);
            if (bRet == false)
            {
                deleteListItemReferences(_iDatasetId, piItemRef);
                delete pList;
                delete pStruct;
                return false;
            }

            pIT = pList->get(0);
            ppSStruct[0]->set(pwcsName, pIT);
            FREE(pcName);
        }
    }
    else if (pStruct->getSize() > 1)
    {
        for (int i = 0; i < pStr->getSize(); ++i)
        {
            int iItemDataset = 0;
            iRet = getListItemDataset(_iDatasetId, piItemRef, i + 2, &iItemDataset);
            if (iRet || iItemDataset == 0)
            {
                deleteListItemReferences(_iDatasetId, piItemRef);
                delete pList;
                delete pStruct;
                return false;
            }

            wchar_t* pwcsName = pStr->get(i);
            char* pcName = wide_string_to_UTF8(pwcsName);

            bool bRet = import_data(pvCtx, iItemDataset, 1, (int*)pList, pcName);
            if (bRet == false)
            {
                deleteListItemReferences(_iDatasetId, piItemRef);
                delete pList;
                delete pStruct;
                return false;
            }

            types::List* pListData = pList->get(0)->getAs<types::List>();
            for (int iWriteData = 0; iWriteData < pStruct->getSize(); ++iWriteData)
            {
                ppSStruct[iWriteData]->set(pwcsName, pListData->get(iWriteData));
            }

            FREE(pcName);
        }

    }

    delete pList;
    if (_piAddress == NULL)
    {
        pwstName = to_wide_string(_pstVarname);
        symbol::Context::getInstance()->put(symbol::Symbol(pwstName), pStruct);
        FREE(pwstName);
    }
    else
    {
        types::List* pParentList = (types::List*)_piAddress;
        pParentList->set(_iItemPos - 1, pStruct);
    }

    iRet = deleteListItemReferences(_iDatasetId, piItemRef);
    if (iRet)
    {
        return false;
    }

    return true;
}
Ejemplo n.º 9
0
static bool import_hypermat(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname)
{
    int iRet = 0;
    int iComplex = 0;
    int iDims = 0;
    int iItems = 0;
    hobj_ref_t *piItemRef = NULL;

    // an hypermatrix is stored in an mlist
    if (_iVarType != sci_mlist)
    {
        return false;
    }

    iRet = getListDims(_iDatasetId, &iItems);
    if (iRet)
    {
        return false;
    }

    if (iItems != 3)
    {
        // hypermatrix have 3 elements
        return false;
    }

    iRet = getListItemReferences(_iDatasetId, &piItemRef);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get first item
    int iItemDataset = 0;
    iRet = getListItemDataset(_iDatasetId, piItemRef, 0, &iItemDataset);
    if (iRet || iItemDataset == 0)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get first item type
    int iItemType = getScilabTypeFromDataSet(iItemDataset);
    if (iItemType != sci_strings)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get size of first item
    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
    if (iRet < 0 || iDims != 2)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    int* piDims = new int[2];
    int iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
    if (iSize != 3)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        return false;
    }

    delete[] piDims;
    piDims = NULL;

    // get data of first item for check the type of mlist
    char** pstData = new char*[iSize];
    iRet = readStringMatrix(iItemDataset, pstData);
    if (iRet || strcmp(pstData[0], "hm") != 0)
    {
        // if not the good type, do not h5close (deleteListItemReferences)
        FREE(piItemRef);
        freeStringMatrix(iItemDataset, pstData);
        delete[] pstData;
        return false;
    }

    freeStringMatrix(iItemDataset, pstData);
    delete[] pstData;
    pstData = NULL;

    // get second item, the Size of hypermatrix
    iRet = getListItemDataset(_iDatasetId, piItemRef, 1, &iItemDataset);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
    if (iRet < 0 || iDims != 2)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    piDims = new int[2];
    iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
    if (piDims[0] != 1)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        return false;
    }

    int* piDimsArray = new int[piDims[1]];
    iRet = readInteger32Matrix(iItemDataset, piDimsArray);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        delete[] piDimsArray;
        return false;
    }

    // get third item, the Data of hypermatrix
    // import data like a "type" (Double, Int, ...) instead of mlist
    iRet = getListItemDataset(_iDatasetId, piItemRef, 2, &iItemDataset);
    bool bRet = import_data(pvCtx, iItemDataset, _iItemPos, _piAddress, _pstVarname);
    if (bRet == false)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        delete[] piDimsArray;
        return false;
    }

    // get imported hypermatrix from List or Context
    types::GenericType* pGT = NULL;
    types::InternalType* pIT = NULL;
    if (_piAddress)
    {
        types::List* pL = (types::List*)_piAddress;
        pIT = pL->get(_iItemPos - 1);
    }
    else
    {
        wchar_t* pwcsName = to_wide_string(_pstVarname);
        pIT = symbol::Context::getInstance()->getCurrentLevel(symbol::Symbol(pwcsName));
        FREE(pwcsName);
    }

    // reshape data with size of hypermatrix
    pGT = pIT->getAs<types::GenericType>();
    pGT->reshape(piDimsArray, piDims[1]);

    delete[] piDims;
    delete[] piDimsArray;


    iRet = deleteListItemReferences(_iDatasetId, piItemRef);
    if (iRet)
    {
        return false;
    }

    return true;
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
static types::InternalType* import_int(int dataset)
{
    types::InternalType* pOut = nullptr;
    int complex = 0;
    int dims = 0;
    int ret = getDatasetInfo(dataset, &complex, &dims, NULL);
    if (ret < 0)
    {
        closeDataSet(dataset);
        return nullptr;
    }

    std::vector<int> d(dims);
    int size = getDatasetInfo(dataset, &complex, &dims, d.data());


    if (dims == 0 || size <= 0)
    {
        closeDataSet(dataset);
        return types::Double::Empty();
    }

    int prec = 0;
    ret = getDatasetPrecision(dataset, &prec);
    if (ret != 0)
    {
        closeDataSet(dataset);
        return nullptr;
    }

    switch (prec)
    {
        case SCI_INT8:
        {
            types::Int8* pi = new types::Int8(dims, d.data());
            ret = readInteger8Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_INT16:
        {
            types::Int16* pi = new types::Int16(dims, d.data());
            ret = readInteger16Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_INT32:
        {
            types::Int32* pi = new types::Int32(dims, d.data());
            ret = readInteger32Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_INT64:
        {
            types::Int64* pi = new types::Int64(dims, d.data());
            ret = readInteger64Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_UINT8:
        {
            types::UInt8* pi = new types::UInt8(dims, d.data());
            ret = readUnsignedInteger8Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_UINT16:
        {
            types::UInt16* pi = new types::UInt16(dims, d.data());
            ret = readUnsignedInteger16Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_UINT32:
        {
            types::UInt32* pi = new types::UInt32(dims, d.data());
            ret = readUnsignedInteger32Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_UINT64:
        {
            types::UInt64* pi = new types::UInt64(dims, d.data());
            ret = readUnsignedInteger64Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        default:
            return nullptr;
            break;
    }

    return pOut;
}