clang format
This commit is contained in:
@@ -5,8 +5,7 @@
|
|||||||
|
|
||||||
//clang-format off
|
//clang-format off
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD FILE *fp;
|
||||||
FILE *fp;
|
|
||||||
int n_left;
|
int n_left;
|
||||||
} ClusterFileReader;
|
} ClusterFileReader;
|
||||||
//clang-format on
|
//clang-format on
|
||||||
@@ -57,52 +56,42 @@ static void ClusterFileReader_dealloc(ClusterFileReader *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read method
|
// read method
|
||||||
static PyObject *ClusterFileReader_read(ClusterFileReader *self, PyObject *args) {
|
static PyObject *ClusterFileReader_read(ClusterFileReader *self,
|
||||||
|
PyObject *args) {
|
||||||
|
|
||||||
const int ndim = 1;
|
const int ndim = 1;
|
||||||
Py_ssize_t size = 0;
|
Py_ssize_t size = 0;
|
||||||
PyObject *noise_obj;
|
PyObject *noise_obj;
|
||||||
if (!PyArg_ParseTuple(args, "nO", &size, &noise_obj)) {
|
if (!PyArg_ParseTuple(args, "nO", &size, &noise_obj)) {
|
||||||
PyErr_SetString(
|
PyErr_SetString(PyExc_TypeError, "Could not parse args.");
|
||||||
PyExc_TypeError,
|
|
||||||
"Could not parse args.");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
npy_intp dims[] = {size};
|
npy_intp dims[] = {size};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Create two numpy arrays from the passed objects, if possible numpy will
|
// Create two numpy arrays from the passed objects, if possible numpy will
|
||||||
// use the underlying buffer, otherwise it will create a copy, for example
|
// use the underlying buffer, otherwise it will create a copy, for example
|
||||||
// if data type is different or we pass in a list. The
|
// if data type is different or we pass in a list. The
|
||||||
// NPY_ARRAY_C_CONTIGUOUS flag ensures that we have contiguous memory.
|
// NPY_ARRAY_C_CONTIGUOUS flag ensures that we have contiguous memory.
|
||||||
PyObject *noise_array = PyArray_FROM_OTF(noise_obj, NPY_DOUBLE, NPY_ARRAY_C_CONTIGUOUS);
|
PyObject *noise_array =
|
||||||
|
PyArray_FROM_OTF(noise_obj, NPY_DOUBLE, NPY_ARRAY_C_CONTIGUOUS);
|
||||||
int nx = 0, ny = 0;
|
int nx = 0, ny = 0;
|
||||||
double *noise_map = NULL;
|
double *noise_map = NULL;
|
||||||
|
|
||||||
|
|
||||||
// If parsing of a or b fails we throw an exception in Python
|
// If parsing of a or b fails we throw an exception in Python
|
||||||
if (noise_array) {
|
if (noise_array) {
|
||||||
|
|
||||||
int ndim_noise = PyArray_NDIM((PyArrayObject *)(noise_array));
|
int ndim_noise = PyArray_NDIM((PyArrayObject *)(noise_array));
|
||||||
npy_intp *noise_shape = PyArray_SHAPE((PyArrayObject *)(noise_array));
|
npy_intp *noise_shape = PyArray_SHAPE((PyArrayObject *)(noise_array));
|
||||||
|
|
||||||
|
|
||||||
// For the C++ function call we need pointers (or another C++ type/data
|
// For the C++ function call we need pointers (or another C++ type/data
|
||||||
// structure)
|
// structure)
|
||||||
|
|
||||||
noise_map = (double *)(PyArray_DATA((PyArrayObject *)(noise_array)));
|
noise_map = (double *)(PyArray_DATA((PyArrayObject *)(noise_array)));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* for (int i=0; i< ndim_noise; i++) { */
|
/* for (int i=0; i< ndim_noise; i++) { */
|
||||||
/* printf("Dimension %d size %d pointer \n",i,noise_shape[i], noise_map); */
|
/* printf("Dimension %d size %d pointer \n",i,noise_shape[i],
|
||||||
|
* noise_map); */
|
||||||
|
|
||||||
/* } */
|
/* } */
|
||||||
|
|
||||||
@@ -113,20 +102,17 @@ static PyObject *ClusterFileReader_read(ClusterFileReader *self, PyObject *args)
|
|||||||
|
|
||||||
// printf("Noise map found size %d %d %d\n",nx,ny,noise_map);
|
// printf("Noise map found size %d %d %d\n",nx,ny,noise_map);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
nx = 0;
|
nx = 0;
|
||||||
if (ndim_noise == 1)
|
if (ndim_noise == 1)
|
||||||
nx = noise_shape[0];
|
nx = noise_shape[0];
|
||||||
ny = 0;
|
ny = 0;
|
||||||
noise_map = NULL;
|
noise_map = NULL;
|
||||||
// printf("NO Noise map found %d %d %d %d\n",ndim_noise,nx,ny,noise_map);
|
// printf("NO Noise map found %d %d %d
|
||||||
|
//%d\n",ndim_noise,nx,ny,noise_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Create an uninitialized numpy array
|
// Create an uninitialized numpy array
|
||||||
PyObject *clusters = PyArray_SimpleNewFromDescr(ndim, dims, cluster_dt());
|
PyObject *clusters = PyArray_SimpleNewFromDescr(ndim, dims, cluster_dt());
|
||||||
|
|
||||||
@@ -140,7 +126,8 @@ static PyObject *ClusterFileReader_read(ClusterFileReader *self, PyObject *args)
|
|||||||
// Here goes the looping, removing frame numbers etc.
|
// Here goes the looping, removing frame numbers etc.
|
||||||
int n_read = 0;
|
int n_read = 0;
|
||||||
if (noise_map)
|
if (noise_map)
|
||||||
read_clusters_with_cut(self->fp, size, buf, &self->n_left,noise_map, nx, ny);
|
read_clusters_with_cut(self->fp, size, buf, &self->n_left, noise_map,
|
||||||
|
nx, ny);
|
||||||
else
|
else
|
||||||
read_clusters(self->fp, size, buf, &self->n_left);
|
read_clusters(self->fp, size, buf, &self->n_left);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user