Пример #1
0
static PyObject *rec_stalta(PyObject *self, PyObject *args) {
	PyArrayObject *a, *b;
	int ndat, Nsta, Nlta, i;
	double Csta, Clta, sta, lta;
	int b_dims[1];

	// arguments: a,Nsta,Nlta; parsing with checking the pointer types:
	if (!PyArg_ParseTuple(args, "O!ii", &PyArray_Type, &a, &Nsta, &Nlta))
		return NULL;
	NDIM_CHECK(a,1);
	TYPE_CHECK(a,NPY_DOUBLE);
	ndat = a->dimensions[0];
	DIM_CHECK(a,0,ndat);     // check if size of the traces is consistent

	// create output array
	b_dims[0] = ndat;
	b = (PyArrayObject *) PyArray_FromDims(1,b_dims, PyArray_DOUBLE);
	if (b==NULL) {
		printf("creating %d array failed\n",b_dims[0]);
		return NULL; //PyArray_FromDims raises exception
	}

	Csta = 1./Nsta; Clta = 1./Nlta;
	sta = 0; lta =0;
	for (i=1;i<ndat;i++) {
		sta = Csta * pow(IND1(a,i),2) + (1-Csta)*sta;
		lta = Clta * pow(IND1(a,i),2) + (1-Clta)*lta;
		IND1(b,i) = sta/lta;
	}

	if (Nlta < ndat) for (i=1;i<Nlta;i++) IND1(b,i) = 0;

	return PyArray_Return(b); //return array
}
Пример #2
0
static int _find_collisions_y_wrap ( 
	COLLIST_ITEM *collidables, 
	int num, 
	int (*callback) (int n, void **list),
	void *param, 
	float max_x, float max_y
)
{
	int r = 0;
	void *outbuf[outbuf_size * 2 + 1];
	int num_out = 0;
	int i, j;
	outbuf[0] = param;
	for (i = 0; i < num; i += 1) {
		float y = collidables[i].y;
		float h = collidables[i].y + collidables[i].h;
		j = i + 1;
		while (1) {
			float x = collidables[i].x;
			while (1) {
				for (; (j < num) && (collidables[j].y < h); j += 1) {
					if (DIM_CHECK(x, collidables[j].x, collidables[i].w, collidables[j].w)) continue;
					if (j == i) continue;
					if (!CHECK_PMASK_COLLISION(
						collidables[i].mask, collidables[j].mask, 
						(int)(x - collidables[j].x), 
						(int)(y - collidables[j].y)))
					{
						continue;
					}
					outbuf[num_out * 2 + 1] = collidables[i].userdata;
					outbuf[num_out * 2 + 2] = collidables[j].userdata;
					num_out += 1;
					if (num_out == outbuf_size) {
						r += num_out;
						if (callback) if (callback(num_out, outbuf)) return r;
						num_out = 0;
					}
				}
				x -= max_x;
				if (x + collidables[i].w < 0) break;
				j = 0;
			}
			h -= max_y;
			if (h < 0) break;
			y -= max_y;
			j = 0;
		}
	}
	if ((num_out > 0) && callback) callback(num_out, outbuf);
	r += num_out;
	return r;
}