Esempio n. 1
0
void Invocation::extractResult(const std::string& name,
                               boost::uint8_t* dst,
                               boost::uint32_t data_len,
                               boost::uint32_t data_stride,
                               dimension::Interpretation dataType,
                               boost::uint32_t numBytes)
{
    PyObject* xarr = PyDict_GetItemString(m_varsOut, name.c_str());
    if (!xarr)
    {
        throw python_error("plang output variable '" + name + "' not found");
    }
    if (!PyArray_Check(xarr))
    {
        throw python_error("plang output variable  '" + name + "' is not a numpy array");
    }

    PyArrayObject* arr = (PyArrayObject*)xarr;

    npy_intp one=0;
    const int pyDataType = getPythonDataType(dataType, numBytes);

    boost::uint8_t* p = dst;

    if (pyDataType == PyArray_DOUBLE)
    {
        double* src = (double*)PyArray_GetPtr(arr, &one);
        for (unsigned int i=0; i<data_len; i++)
        {
            *(double*)p = src[i];
            p += data_stride;
        }
    }
    else if (pyDataType == PyArray_FLOAT)
    {
        float* src = (float*)PyArray_GetPtr(arr, &one);
        for (unsigned int i=0; i<data_len; i++)
        {
            *(float*)p = src[i];
            p += data_stride;
        }
    }
    else if (pyDataType == PyArray_BYTE)
    {
        boost::int8_t* src = (boost::int8_t*)PyArray_GetPtr(arr, &one);
        for (unsigned int i=0; i<data_len; i++)
        {
            *(boost::int8_t*)p = src[i];
            p += data_stride;
        }
    }
    else if (pyDataType == PyArray_UBYTE)
    {
        boost::uint8_t* src = (boost::uint8_t*)PyArray_GetPtr(arr, &one);
        for (unsigned int i=0; i<data_len; i++)
        {
            *(boost::uint8_t*)p = src[i];
            p += data_stride;
        }
    }
    else if (pyDataType == PyArray_SHORT)
    {
        boost::int16_t* src = (boost::int16_t*)PyArray_GetPtr(arr, &one);
        for (unsigned int i=0; i<data_len; i++)
        {
            *(boost::int16_t*)p = src[i];
            p += data_stride;
        }
    }
    else if (pyDataType == PyArray_USHORT)
    {
        boost::uint16_t* src = (boost::uint16_t*)PyArray_GetPtr(arr, &one);
        for (unsigned int i=0; i<data_len; i++)
        {
            *(boost::uint16_t*)p = src[i];
            p += data_stride;
        }
    }
    else if (pyDataType == PyArray_INT)
    {
        boost::int32_t* src = (boost::int32_t*)PyArray_GetPtr(arr, &one);
        for (unsigned int i=0; i<data_len; i++)
        {
            *(boost::int32_t*)p = src[i];
            p += data_stride;
        }
    }
    else if (pyDataType == PyArray_UINT)
    {
        boost::uint32_t* src = (boost::uint32_t*)PyArray_GetPtr(arr, &one);
        for (unsigned int i=0; i<data_len; i++)
        {
            *(boost::uint32_t*)p = src[i];
            p += data_stride;
        }
    }
    else if (pyDataType == PyArray_LONGLONG)
    {
        boost::int64_t* src = (boost::int64_t*)PyArray_GetPtr(arr, &one);
        for (unsigned int i=0; i<data_len; i++)
        {
            *(boost::int64_t*)p = src[i];
            p += data_stride;
        }
    }
    else if (pyDataType == PyArray_ULONGLONG)
    {
        boost::uint64_t* src = (boost::uint64_t*)PyArray_GetPtr(arr, &one);
        for (unsigned int i=0; i<data_len; i++)
        {
            *(boost::uint64_t*)p = src[i];
            p += data_stride;
        }
    }
    else
    {
        assert(0);
    }

    return;
}
Esempio n. 2
-1
 void* raw_data(const position& pos) const {
     assert(this->validposition(pos));
     return PyArray_GetPtr(array_,const_cast<npy_intp*>(pos.position_));
 }