static PyObject *sps_getshmid(PyObject *self, PyObject *args) { char *spec_version, *array_name; int rows, cols, type, flag; int shmid; if (!PyArg_ParseTuple(args, "ss", &spec_version, &array_name)) { return NULL; } if (SPS_GetArrayInfo(spec_version, array_name, &rows, &cols, &type, &flag)) { PyErr_SetString(SPSError, "Error getting array info"); return NULL; } shmid = SPS_GetShmId(spec_version, array_name); return Py_BuildValue("i", shmid); }
static PyObject *sps_attach(PyObject *self, PyObject *args) { char *spec_version, *array_name; int rows, cols, type, flag; npy_intp dims[2]; int ptype, stype; PyArrayObject *arrobj; void *data; if (!PyArg_ParseTuple(args, "ss", &spec_version, &array_name)) { return NULL; } if (SPS_GetArrayInfo(spec_version, array_name, &rows, &cols, &type, &flag)) { struct module_state *st = GETSTATE(self); PyErr_SetString(st->SPSError, "Error getting array info"); return NULL; } if ((data = SPS_GetDataPointer(spec_version, array_name, 1)) == NULL) { struct module_state *st = GETSTATE(self); PyErr_SetString(st->SPSError, "Error getting data pointer"); return NULL; } dims[0]=rows; dims[1]=cols; ptype = sps_type2py(type); stype = sps_py2type(ptype); if (type != stype) { SPS_ReturnDataPointer(data); struct module_state *st = GETSTATE(self); PyErr_SetString(st->SPSError, "Type of data in shared memory not supported"); return NULL; } if ((arrobj = (PyArrayObject*) PyArray_SimpleNewFromData(2, dims, ptype, data)) == NULL) { SPS_ReturnDataPointer(data); struct module_state *st = GETSTATE(self); PyErr_SetString(st->SPSError, "Could not create mathematical array"); return NULL; } return (PyObject*) arrobj; }
static PyObject *sps_getdatarow(PyObject *self, PyObject *args) { char *spec_version, *array_name; int rows, cols, type, flag, in_row, in_col = 0; npy_intp dims[2]; int ptype, stype; PyArrayObject *arrobj, *arrobj_nc; if (!PyArg_ParseTuple(args, "ssi|i", &spec_version, &array_name, &in_row, &in_col)) { return NULL; } if (SPS_GetArrayInfo(spec_version, array_name, &rows, &cols, &type, &flag)) { struct module_state *st = GETSTATE(self); PyErr_SetString(st->SPSError, "Error getting array info"); return NULL; } dims[0] = (in_col == 0) ? cols : in_col; ptype = sps_type2py(type); if ((arrobj_nc = (PyArrayObject*) PyArray_SimpleNew(1, dims, ptype)) == NULL) { struct module_state *st = GETSTATE(self); PyErr_SetString(st->SPSError, "Could not create mathematical array"); return NULL; } if ((arrobj = (PyArrayObject*) PyArray_ContiguousFromObject( (PyObject*) arrobj_nc, ptype, 1, 1)) == NULL) { Py_DECREF(arrobj_nc); struct module_state *st = GETSTATE(self); PyErr_SetString(st->SPSError, "Could not make our array contiguous"); return NULL; } else Py_DECREF(arrobj_nc); stype = sps_py2type(ptype); SPS_CopyRowFromShared(spec_version, array_name, PyArray_DATA(arrobj), stype , in_row, in_col, NULL); return (PyObject*) arrobj; }
static PyObject *sps_getarrayinfo(PyObject *self, PyObject *args) { char *spec_version, *array_name; int rows, cols, type, flag; if (!PyArg_ParseTuple(args, "ss", &spec_version, &array_name)) { return NULL; } if (SPS_GetArrayInfo(spec_version, array_name, &rows, &cols, &type, &flag)) { struct module_state *st = GETSTATE(self); PyErr_SetString(st->SPSError, "Error getting array info"); return NULL; } return Py_BuildValue("(iiii)", rows, cols, type, flag); }
static PyObject *sps_getdata(PyObject *self, PyObject *args) { char *spec_version, *array_name; int rows, cols, type, flag; npy_intp dims[2]; int ptype, stype; PyArrayObject *arrobj, *arrobj_nc; if (!PyArg_ParseTuple(args, "ss", &spec_version, &array_name)) { return NULL; } if (SPS_GetArrayInfo(spec_version, array_name, &rows, &cols, &type, &flag)) { PyErr_SetString(SPSError, "Error getting array info"); return NULL; } dims[0]=rows; dims[1]=cols; ptype = sps_type2py(type); if ((arrobj_nc = (PyArrayObject*) PyArray_SimpleNew(2, dims, ptype)) == NULL) { PyErr_SetString(SPSError, "Could not create mathematical array"); return NULL; } if ((arrobj = (PyArrayObject*) PyArray_ContiguousFromObject( (PyObject*) arrobj_nc, ptype, 2, 2)) == NULL) { Py_DECREF(arrobj_nc); PyErr_SetString(SPSError, "Could not make our array contiguous"); return NULL; } else Py_DECREF(arrobj_nc); stype = sps_py2type(ptype); SPS_CopyFromShared(spec_version, array_name, arrobj->data, stype , rows * cols); return (PyObject*) arrobj; }