Created
May 4, 2021 13:13
-
-
Save benjeffery/b9c03646252dafdab75c25586e32f739 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static PyObject * | |
IndividualTable_extend(IndividualTable *self, PyObject *args, PyObject *kwds) | |
{ | |
PyObject *ret = NULL; | |
IndividualTable *other = NULL; | |
PyObject *obj_row_indexes = Py_None; | |
PyArrayObject *row_indexes = NULL; | |
tsk_id_t *row_indexes_data = NULL; | |
tsk_size_t num_rows = 0; | |
int err; | |
static char *kwlist[] = { "", "num_rows", "row_indexes", NULL }; | |
if (IndividualTable_check_state(self) != 0) { | |
goto out; | |
} | |
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|$nO", kwlist, &IndividualTableType, | |
&other, &num_rows, &obj_row_indexes)) { | |
goto out; | |
} | |
if (IndividualTable_check_state(other) != 0) { | |
goto out; | |
} | |
// We check this here as for the C API method n can be the size of the | |
// row_indexes array, but for python we know that size so n can only be | |
// a number of rows from other | |
if (num_rows > other->table->num_rows || num_rows < 0) { | |
PyErr_SetString(PyExc_ValueError, "num_rows must be 0 <= n <= other.num_rows"); | |
goto out; | |
} | |
if (obj_row_indexes != Py_None) { | |
row_indexes = (PyArrayObject *) PyArray_FromAny(obj_row_indexes, | |
PyArray_DescrFromType(NPY_INT32), 1, 1, NPY_ARRAY_IN_ARRAY, NULL); | |
if (row_indexes == NULL) { | |
goto out; | |
} | |
num_rows = PyArray_DIMS(row_indexes)[0]; | |
row_indexes_data = PyArray_DATA(row_indexes); | |
} | |
err = tsk_individual_table_extend( | |
self->table, other->table, num_rows, row_indexes_data, 0); | |
if (err != 0) { | |
handle_library_error(err); | |
goto out; | |
} | |
ret = Py_BuildValue(""); | |
out: | |
Py_XDECREF(row_indexes); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment