Example #1
0
/* Checks that given sort function is stable. */
void check_stable(char *name, void (*sort_fun)(int **arr, size_t size), int size, int num_values) {
  int **array = malloc(sizeof(int *) * size);
  make_intp_array(array, size, num_values);
  sort_fun(array, size);
  printf("%21s -- %s\n", name, verify_stable(array, size, num_values) ? "stable" : "UNSTABLE");
  clean_intp_array(array, size);
  free(array);
}
Example #2
0
static PyObject*
PyMangleMask_contains(struct PyMangleMask* self, PyObject* args)
{
    int status=1;
    struct Point pt;
    PyObject* ra_obj=NULL;
    PyObject* dec_obj=NULL;
    PyObject* contained_obj=NULL;
    npy_intp* cont_ptr=NULL;
    double* ra_ptr=NULL;
    double* dec_ptr=NULL;
    double weight=0;
    npy_intp poly_id=0;
    npy_intp nra=0, ndec=0, i=0;

    if (!PyArg_ParseTuple(args, (char*)"OO", &ra_obj, &dec_obj)) {
        return NULL;
    }

    if (!check_ra_dec_arrays(ra_obj,dec_obj,&ra_ptr,&nra,&dec_ptr,&ndec)) {
        return NULL;
    }
    if (!(contained_obj=make_intp_array(nra, "contained", &cont_ptr))) {
        return NULL;
    }

    for (i=0; i<nra; i++) {
        point_set_from_radec(&pt, *ra_ptr, *dec_ptr);

        //status=mangle_polyid_and_weight(self->mask, 
        status=MANGLE_POLYID_AND_WEIGHT(self->mask, 
                                        &pt, 
                                        &poly_id, 
                                        &weight);

        if (status != 1) {
            goto _weight_cleanup;
        }

        if (poly_id >= 0) {
            *cont_ptr = 1;
        }
        ra_ptr++;
        dec_ptr++;
        cont_ptr++;
    }

_weight_cleanup:
    if (status != 1) {
        Py_XDECREF(contained_obj);
        return NULL;
    }
    return contained_obj;
}
Example #3
0
static PyObject*
PyMangleMask_polyid(struct PyMangleMask* self, PyObject* args)
{
    int status=1;
    struct Point pt;
    PyObject* ra_obj=NULL;
    PyObject* dec_obj=NULL;
    PyObject* poly_id_obj=NULL;

    double* ra_ptr=NULL;
    double* dec_ptr=NULL;
    double weight=0;
    npy_intp* poly_id_ptr=NULL;
    npy_intp nra=0, ndec=0, i=0;

    if (!PyArg_ParseTuple(args, (char*)"OO", &ra_obj, &dec_obj)) {
        return NULL;
    }

    if (!check_ra_dec_arrays(ra_obj,dec_obj,&ra_ptr,&nra,&dec_ptr,&ndec)) {
        return NULL;
    }
    if (!(poly_id_obj=make_intp_array(nra, "polyid", &poly_id_ptr))) {
        return NULL;
    }

    for (i=0; i<nra; i++) {
        point_set_from_radec(&pt, *ra_ptr, *dec_ptr);

        if (self->pixelres == -1) {
            status=polyid_and_weight(self, &pt, poly_id_ptr, &weight);
        } else {
            status=polyid_and_weight_pixelized(self, &pt, poly_id_ptr, &weight);
        }

        if (status != 1) {
            goto _poly_id_cleanup;
        }
        ra_ptr++;
        dec_ptr++;
        poly_id_ptr++;
    }

_poly_id_cleanup:
    if (status != 1) {
        Py_XDECREF(poly_id_obj);
        return NULL;
    }
    return poly_id_obj;
}
Example #4
0
static PyObject*
PyMangleMask_polyid_and_weight(struct PyMangleMask* self, PyObject* args)
{
    int status=1;
    struct Point pt;
    PyObject* ra_obj=NULL;
    PyObject* dec_obj=NULL;
    PyObject* poly_id_obj=NULL;
    PyObject* weight_obj=NULL;
    double* ra_ptr=NULL;
    double* dec_ptr=NULL;
    double* weight_ptr=NULL;
    npy_intp* poly_id_ptr=NULL;
    npy_intp nra=0, ndec=0, i=0;

    PyObject* tuple=NULL;

    if (!PyArg_ParseTuple(args, (char*)"OO", &ra_obj, &dec_obj)) {
        return NULL;
    }

    if (!check_ra_dec_arrays(ra_obj,dec_obj,&ra_ptr,&nra,&dec_ptr,&ndec)) {
        return NULL;
    }

    if (!(poly_id_obj=make_intp_array(nra, "polyid", &poly_id_ptr))) {
        status=0;
        goto _poly_id_and_weight_cleanup;
    }
    if (!(weight_obj=make_double_array(nra, "weight", &weight_ptr))) {
        status=0;
        goto _poly_id_and_weight_cleanup;
    }

    for (i=0; i<nra; i++) {
        point_set_from_radec(&pt, *ra_ptr, *dec_ptr);

        status=mangle_polyid_and_weight_nopix(self->mask, 
                                              &pt, 
                                              poly_id_ptr, 
                                              weight_ptr);

        if (status != 1) {
            goto _poly_id_and_weight_cleanup;
        }
        ra_ptr++;
        dec_ptr++;
        poly_id_ptr++;
        weight_ptr++;
    }

_poly_id_and_weight_cleanup:
    if (status != 1) {
        Py_XDECREF(poly_id_obj);
        Py_XDECREF(weight_obj);
        Py_XDECREF(tuple);
        return NULL;
    }

    tuple=PyTuple_New(2);
    PyTuple_SetItem(tuple, 0, poly_id_obj);
    PyTuple_SetItem(tuple, 1, weight_obj);
    return tuple;
}