static PyObject * lapack_lite_dgeqrf(PyObject *NPY_UNUSED(self), PyObject *args) { int lapack_lite_status; int m, n, lwork; PyObject *a, *tau, *work; int lda; int info; TRY(PyArg_ParseTuple(args,"iiOiOOii",&m,&n,&a,&lda,&tau,&work,&lwork,&info)); /* check objects and convert to right storage order */ TRY(check_object(a,NPY_DOUBLE,"a","NPY_DOUBLE","dgeqrf")); TRY(check_object(tau,NPY_DOUBLE,"tau","NPY_DOUBLE","dgeqrf")); TRY(check_object(work,NPY_DOUBLE,"work","NPY_DOUBLE","dgeqrf")); lapack_lite_status = FNAME(dgeqrf)(&m, &n, DDATA(a), &lda, DDATA(tau), DDATA(work), &lwork, &info); if (PyErr_Occurred()) { return NULL; } return Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i}","dgeqrf_", lapack_lite_status,"m",m,"n",n,"lda",lda, "lwork",lwork,"info",info); }
static PyObject* cshockCapturingCalculateNumericalDiffusion_A_1(PyObject* self, PyObject* args) { double shockCapturingFactor; PyObject *elementDiameter,*strongResidual,*mt,*df,*numDiff; if(!PyArg_ParseTuple(args,"dOOOOO", &shockCapturingFactor, &elementDiameter, &strongResidual, &mt, &df, &numDiff)) return NULL; calculateNumericalDiffusion_A_1(SHAPE(df)[0], SHAPE(df)[1], SHAPE(df)[2], shockCapturingFactor, DDATA(elementDiameter), DDATA(strongResidual), DDATA(mt), DDATA(df), DDATA(numDiff)); Py_INCREF(Py_None); return Py_None; }
static PyObject* cshockCapturingCalculateNumericalDiffusionJaffre(PyObject* self, PyObject* args) { double shockCapturingFactor,beta; PyObject *elementDiameter,*strongResidual,*grad_u,*numDiff; if(!PyArg_ParseTuple(args,"ddOOOO", &shockCapturingFactor, &beta, &elementDiameter, &strongResidual, &grad_u, &numDiff)) return NULL; calculateNumericalDiffusionJaffre(SHAPE(grad_u)[0], SHAPE(grad_u)[1], SHAPE(grad_u)[2], shockCapturingFactor, beta, DDATA(elementDiameter), DDATA(strongResidual), DDATA(grad_u), DDATA(numDiff)); Py_INCREF(Py_None); return Py_None; }
static PyObject* SparseMatrix_matvec(SparseMatrix *self, PyObject *args) { register int i,k; register double s; int_t *rowptr,*colind; double *a,*x,*y; PyObject *xp, *yp; if(!PyArg_ParseTuple(args, "OO", &xp, &yp)) return NULL; a = (double*)self->A.nzval; rowptr = self->A.rowptr; colind = self->A.colind; x = DDATA(xp); y = DDATA(yp); for (i = 0; i < self->dim[0]; i ++) { s = 0.0; for (k=rowptr[i]; k<rowptr[i+1]; k++) s += a[k]* x[colind[k]]; y[i] = s; } Py_INCREF(Py_None); return Py_None; }
static int SparseMatrix_init(SparseMatrix *self, PyObject *args, PyObject *kwds) { int i,nr,nc,nnz; PyObject *nzval,*colind,*rowptr; if(!PyArg_ParseTuple(args, "iiiOOO", &nr, &nc, &nnz, &nzval, &colind, &rowptr)) return -1; self->dim[0]=nr; self->dim[1]=nc; self->A.nnz = nnz; self->A.nzval = DDATA(nzval); self->A.colind = (int_t*)malloc(nnz*sizeof(int_t)); for (i=0;i<nnz;i++) self->A.colind[i] = IDATA(colind)[i]; self->A.rowptr = (int_t*)malloc((nr+1)*sizeof(int_t)); for (i=0;i<nr+1;i++) self->A.rowptr[i] = IDATA(rowptr)[i]; SuperMatrix Aprint; Aprint.Stype = SLU_NC; Aprint.Dtype = SLU_D; Aprint.Mtype = SLU_GE; Aprint.nrow = nr; Aprint.ncol = nc; Aprint.Store = &self->A; return 0; }
static PyObject* ctracking_getOuterNormals_affineSimplex(PyObject* self, PyObject* args) { int nSpace; PyObject *boundaryNormals, *jacobianInverseArray, *unitNormalArray; if (!PyArg_ParseTuple(args, "OOO", &boundaryNormals, &jacobianInverseArray, &unitNormalArray)) return NULL; nSpace = SHAPE(boundaryNormals)[0] -1; if (nSpace == 1) { getOuterNormals_affineSimplex_1d(SHAPE(jacobianInverseArray)[0], SHAPE(unitNormalArray)[1], SHAPE(jacobianInverseArray)[1], DDATA(boundaryNormals), DDATA(jacobianInverseArray), DDATA(unitNormalArray)); } else if (nSpace == 2) { getOuterNormals_affineSimplex_2d(SHAPE(jacobianInverseArray)[0], SHAPE(unitNormalArray)[1], SHAPE(jacobianInverseArray)[1], DDATA(boundaryNormals), DDATA(jacobianInverseArray), DDATA(unitNormalArray)); } else { assert(nSpace == 3); getOuterNormals_affineSimplex_3d(SHAPE(jacobianInverseArray)[0], SHAPE(unitNormalArray)[1], SHAPE(jacobianInverseArray)[1], DDATA(boundaryNormals), DDATA(jacobianInverseArray), DDATA(unitNormalArray)); } Py_INCREF(Py_None); return Py_None; }
/*.............................................................................. . Here is the method itself. ..............................................................................*/ static PyObject * fkepler_vt2TA (PyObject *self, PyObject *args) { PyObject *input; PyArrayObject *t_array; PyArrayObject *TA_array; int n, i; int dims[2]; double t, c, s; double *t_vec, *TA_vec; /** Initialize objects to NULL that we may have to XDECREF if a constructor ** fails so that XDECREF has an argument to work with. Strictly, this ** isn't needed for every object. */ TA_array = NULL; /** Parse the argument; make it contiguous. */ Py_TRY(PyArg_ParseTuple(args, "O", &input)); t_array = (PyArrayObject *) PyArray_ContiguousFromObject(input, PyArray_DOUBLE, 1, 1); if (t_array == NULL) goto FAIL; /** Create a 2 x n array for the result. */ n = t_array->dimensions[0]; dims[0] = n; dims[1] = 2; TA_array = (PyArrayObject *)PyArray_FromDims(2, dims, PyArray_DOUBLE); if (TA_array == NULL) goto FAIL; /** Step through the times. */ t_vec = DDATA(t_array); TA_vec = DDATA(TA_array); for (i=0; i<n; i++) { t2TA(*(t_vec+i), &c, &s); *(TA_vec + 2*i) = c; *(TA_vec + 2*i + 1) = s; } /** Clean up and return a NumPy array. */ Py_DECREF(t_array); return PyArray_Return(TA_array); /** Misbehavior ends up here! */ FAIL: Py_XDECREF(t_array); Py_XDECREF(TA_array); return NULL; }
static edge_ref connect(edge_ref a, edge_ref b) { edge_ref e = make_edge(); ODATA(e) = DEST(a); DDATA(e) = ORG(b); splice(e, LNEXT(a)); splice(SYM(e), b); return e; }
static PyObject * lapack_lite_dgelsd(PyObject *NPY_UNUSED(self), PyObject *args) { int lapack_lite_status; int m; int n; int nrhs; PyObject *a; int lda; PyObject *b; int ldb; PyObject *s; double rcond; int rank; PyObject *work; PyObject *iwork; int lwork; int info; TRY(PyArg_ParseTuple(args,"iiiOiOiOdiOiOi", &m,&n,&nrhs,&a,&lda,&b,&ldb,&s,&rcond, &rank,&work,&lwork,&iwork,&info)); TRY(check_object(a,NPY_DOUBLE,"a","NPY_DOUBLE","dgelsd")); TRY(check_object(b,NPY_DOUBLE,"b","NPY_DOUBLE","dgelsd")); TRY(check_object(s,NPY_DOUBLE,"s","NPY_DOUBLE","dgelsd")); TRY(check_object(work,NPY_DOUBLE,"work","NPY_DOUBLE","dgelsd")); TRY(check_object(iwork,NPY_INT,"iwork","NPY_INT","dgelsd")); lapack_lite_status = FNAME(dgelsd)(&m,&n,&nrhs,DDATA(a),&lda,DDATA(b),&ldb, DDATA(s),&rcond,&rank,DDATA(work),&lwork, IDATA(iwork),&info); if (PyErr_Occurred()) { return NULL; } return Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:i,s:d,s:i,s:i,s:i}","dgelsd_", lapack_lite_status,"m",m,"n",n,"nrhs",nrhs, "lda",lda,"ldb",ldb,"rcond",rcond,"rank",rank, "lwork",lwork,"info",info); }
static PyObject * lapack_lite_dorgqr(PyObject *NPY_UNUSED(self), PyObject *args) { int lapack_lite_status; int m, n, k, lwork; PyObject *a, *tau, *work; int lda; int info; TRY(PyArg_ParseTuple(args,"iiiOiOOii", &m, &n, &k, &a, &lda, &tau, &work, &lwork, &info)); TRY(check_object(a,NPY_DOUBLE,"a","NPY_DOUBLE","dorgqr")); TRY(check_object(tau,NPY_DOUBLE,"tau","NPY_DOUBLE","dorgqr")); TRY(check_object(work,NPY_DOUBLE,"work","NPY_DOUBLE","dorgqr")); lapack_lite_status = FNAME(dorgqr)(&m, &n, &k, DDATA(a), &lda, DDATA(tau), DDATA(work), &lwork, &info); if (PyErr_Occurred()) { return NULL; } return Py_BuildValue("{s:i,s:i}","dorgqr_",lapack_lite_status, "info",info); }
static PyObject * rayleigh (PyObject *self, PyObject *args) { PyObject *input; PyArrayObject *data; int ndat, i; double *times; double w; double wt, S, C, P; /** Initialize objects to NULL that we may have to XDECREF if a constructor ** fails so that XDECREF has an argument to work with. Strictly, this ** isn't needed for every object. */ data = NULL; /** Parse the args; make the data array contiguous. */ Py_TRY(PyArg_ParseTuple(args, "dO", &w, &input)); data = (PyArrayObject *) PyArray_ContiguousFromObject(input, PyArray_DOUBLE, 1, 1); if (data == NULL) goto FAIL; /** Store the # of data; make vector references to event times. */ ndat = data->dimensions[0]; times = DDATA(data); /** Calculate the statistics. */ S = 0.; C = 0.; for (i=0; i<ndat; i++) { wt = w * *(times+i); S = S + sin(wt); C = C + cos(wt); } P = (S*S + C*C)/ndat; /** Clean up and return everything in a tuple. */ Py_DECREF(data); return Py_BuildValue("fff", S, C, P); /** Misbehavior ends up here! */ FAIL: Py_XDECREF(data); return NULL; }
static PyObject* superluWrappersSparseFactorSolve(PyObject* self, PyObject* args) { trans_t trans=TRANS; int info=0; PyObject *sparseFactor,*x; if(!PyArg_ParseTuple(args,"OO", &sparseFactor, &x)) return NULL; SFP(sparseFactor)->storeX.nzval = DDATA(x); dgstrs(trans, &SFP(sparseFactor)->L, &SFP(sparseFactor)->U, SFP(sparseFactor)->perm_c, SFP(sparseFactor)->perm_r, &SFP(sparseFactor)->X, &SFP(sparseFactor)->stat, &info); Py_INCREF(Py_None); return Py_None; }
static PyObject *calc_grid_values( PyObject *self, PyObject *args ) { int i, ok, num_tri, num_vert, ncol, nrow, num_norms, num_grid_val; long *volumes; double nodata_val; double cell_size; double *x, *y; double *norms; double *result; double *grid_val; PyObject *pyobj_x; PyObject *pyobj_y; PyObject *pyobj_norms; PyObject *pyobj_volumes; PyObject *pyobj_result; PyObject *pyobj_grid_val; ok = PyArg_ParseTuple( args, "iiddOOOOOO", &nrow, &ncol, &cell_size, &nodata_val, &pyobj_x, &pyobj_y, &pyobj_norms, &pyobj_volumes, &pyobj_result, &pyobj_grid_val ); if( !ok ){ fprintf( stderr, "calc_grid_values: argument parsing error\n" ); exit(1); } // get data from python objects x = DDATA( pyobj_x ); y = DDATA( pyobj_y ); norms = DDATA( pyobj_norms ); result = DDATA( pyobj_result ); grid_val = DDATA( pyobj_grid_val ); volumes = IDATA( pyobj_volumes ); num_tri = ((PyArrayObject*)pyobj_volumes)->dimensions[0]; num_vert = ((PyArrayObject*)pyobj_x)->dimensions[0]; num_norms = ((PyArrayObject*)pyobj_norms)->dimensions[0]; num_grid_val = ((PyArrayObject*)pyobj_grid_val)->dimensions[0]; //printf("==== %d %d %d %d %d \n",num_norms,num_tri,num_vert,nrow,ncol); // init triangle array init_norms( x,y, norms, volumes, num_tri ); //printf("+++ %d\n",nrow*ncol); // evaluate grid for ( i = 0 ; i < nrow*ncol; i++ ) grid_val[i] = nodata_val; _calc_grid_values( x,y, norms, num_vert, volumes, num_tri, \ cell_size, nrow, ncol, \ result, grid_val ); return Py_BuildValue(""); }
static PyObject* ctracking_trackPointsC0P1Velocity1d(PyObject* self, PyObject* args) { int nElements_global, nNodes_global, nNodes_element, nElementBoundaries_element, nPointsToTrack; double dir, zeroTolForTracking; PyObject *nodeArray, *elementNodesArray, *elementNeighborsArray, *cvelocity_l2g, *cvelocity_dof, *x_depart_times, *x_arrive_times, *x_in, *x_element, *x_out, *flag; if (!PyArg_ParseTuple(args, "iiiiOOOOOdOOidOOOO", &nElements_global, &nNodes_global, &nNodes_element, &nElementBoundaries_element, &nodeArray, &elementNodesArray, &elementNeighborsArray, &cvelocity_l2g, &cvelocity_dof, &dir, &x_depart_times, &x_arrive_times, &nPointsToTrack, &zeroTolForTracking, &x_in, &x_element, &x_out, &flag)) return NULL; trackPointsC0P1Velocity1d(nElements_global, //mesh representation nNodes_global, nNodes_element, nElementBoundaries_element, DDATA(nodeArray), IDATA(elementNodesArray), IDATA(elementNeighborsArray), //local boundary id is associated with node across from boundary IDATA(cvelocity_l2g), DDATA(cvelocity_dof), //characteristic speed (velocity) representation dir, //direction in time DDATA(x_depart_times), //in -- time of departure for each point DDATA(x_arrive_times), //desired stopping time //out -- stopping time for each point nPointsToTrack, //number of points to track zeroTolForTracking, //ignore point if |u| < eps or |v| < eps DDATA(x_in), //points for tracking (always 3d) IDATA(x_element), //in -- element where point i is located at tIn //out -- element where point i is located at tOut DDATA(x_out), //stopping location for point i at tOut IDATA(flag)); //in: > -2 -- track point //in: -3 -- skip point //out: -1 -- point in interior at tOut //out: -2 -- point exited domain somewhere in (tIn,tOut) //out: -3 -- did not track (e.g., or u = 0) Py_INCREF(Py_None); return Py_None; }
void CodeEmitterNVC0::defId(const ValueDef& def, const int pos) { code[pos / 32] |= (def.get() ? DDATA(def).id : 63) << (pos % 32); }
static PyObject* ctracking_trackPointsRT0Velocity2dWithTrajectories(PyObject* self, PyObject* args) { int localVelocityRepresentationFlag, nElements_global, nNodes_global, nNodes_element, nElementBoundaries_element, nPointsToTrack, debugLevel; double dir, zeroTolForTracking; PyObject *nodeArray, *elementNodesArray, *elementNeighborsArray, *elementBoundariesArray, *elementBoundaryBarycentersArray, *elementLocalBoundaryOuterNormalsArray, *cvelocity_l2g, *cvelocity_dof, *x_depart_times, *x_arrive_times, *x_in, *x_element, *x_out, *flag; //try to build arrays for trajectories and return int n_traj,n_tracked; double * x_traj = 0, * t_traj = 0; int * e_traj = 0, * offsets_traj = 0; debugLevel = 0; if (!PyArg_ParseTuple(args, "iiiiiOOOOOOOOdOOidOOOO|i", &localVelocityRepresentationFlag, &nElements_global, &nNodes_global, &nNodes_element, &nElementBoundaries_element, &nodeArray, &elementNodesArray, &elementNeighborsArray, &elementBoundariesArray, &elementBoundaryBarycentersArray, &elementLocalBoundaryOuterNormalsArray, &cvelocity_l2g, &cvelocity_dof, &dir, &x_depart_times, &x_arrive_times, &nPointsToTrack, &zeroTolForTracking, &x_in, &x_element, &x_out, &flag, &debugLevel)) return NULL; trackPointsRT0Velocity2dWithTrajectories(debugLevel, localVelocityRepresentationFlag, nElements_global, nNodes_global, nNodes_element, nElementBoundaries_element, DDATA(nodeArray), IDATA(elementNodesArray), IDATA(elementNeighborsArray), IDATA(elementBoundariesArray), DDATA(elementBoundaryBarycentersArray), DDATA(elementLocalBoundaryOuterNormalsArray), IDATA(cvelocity_l2g), DDATA(cvelocity_dof), dir, DDATA(x_depart_times), DDATA(x_arrive_times), nPointsToTrack, zeroTolForTracking, DDATA(x_in), IDATA(x_element), DDATA(x_out), IDATA(flag), n_traj, n_tracked, offsets_traj, x_traj, t_traj, e_traj); npy_intp dim[1],dim2[2]; dim[0] = n_traj; PyArrayObject *t_traj_py = (PyArrayObject *)PyArray_SimpleNew(1,dim,PyArray_DOUBLE); double* t_ptr = DDATA(t_traj_py); dim2[0] = n_traj; dim2[1] = 3; PyArrayObject *x_traj_py = (PyArrayObject *)PyArray_SimpleNew(2,dim2,PyArray_DOUBLE); double* x_ptr = DDATA(x_traj_py); dim[0] = n_traj; PyArrayObject *e_traj_py = (PyArrayObject *)PyArray_SimpleNew(1,dim,PyArray_INT); int* e_ptr = IDATA(e_traj_py); dim[0] = n_tracked+1; PyArrayObject *o_traj_py = (PyArrayObject *)PyArray_SimpleNew(1,dim,PyArray_INT); int* o_ptr = IDATA(o_traj_py); for (int i=0; i < n_traj; i++) { t_ptr[i] = t_traj[i]; e_ptr[i] = e_traj[i]; for (int j=0; j < 3; j++) x_ptr[i*3+j] = x_traj[i*3+j]; } for (int i=0; i < n_tracked+1; i++) { o_ptr[i] = offsets_traj[i]; } return Py_BuildValue("(O,O,O,O)",PyArray_Return(x_traj_py),PyArray_Return(t_traj_py),PyArray_Return(e_traj_py),PyArray_Return(o_traj_py)); }
static PyObject* ctracking_trackPointsRT0Velocity2d(PyObject* self, PyObject* args) { int localVelocityRepresentationFlag, nElements_global, nNodes_global, nNodes_element, nElementBoundaries_element, nPointsToTrack, debugLevel; double dir, zeroTolForTracking; PyObject *nodeArray, *elementNodesArray, *elementNeighborsArray, *elementBoundariesArray, *elementBoundaryBarycentersArray, *elementLocalBoundaryOuterNormalsArray, *cvelocity_l2g, *cvelocity_dof, *x_depart_times, *x_arrive_times, *x_in, *x_element, *x_out, *flag; debugLevel = 0; if (!PyArg_ParseTuple(args, "iiiiiOOOOOOOOdOOidOOOO|i", &localVelocityRepresentationFlag, &nElements_global, &nNodes_global, &nNodes_element, &nElementBoundaries_element, &nodeArray, &elementNodesArray, &elementNeighborsArray, &elementBoundariesArray, &elementBoundaryBarycentersArray, &elementLocalBoundaryOuterNormalsArray, &cvelocity_l2g, &cvelocity_dof, &dir, &x_depart_times, &x_arrive_times, &nPointsToTrack, &zeroTolForTracking, &x_in, &x_element, &x_out, &flag, &debugLevel)) return NULL; trackPointsRT0Velocity2d(debugLevel, localVelocityRepresentationFlag, nElements_global, nNodes_global, nNodes_element, nElementBoundaries_element, DDATA(nodeArray), IDATA(elementNodesArray), IDATA(elementNeighborsArray), IDATA(elementBoundariesArray), DDATA(elementBoundaryBarycentersArray), DDATA(elementLocalBoundaryOuterNormalsArray), IDATA(cvelocity_l2g), DDATA(cvelocity_dof), dir, DDATA(x_depart_times), DDATA(x_arrive_times), nPointsToTrack, zeroTolForTracking, DDATA(x_in), IDATA(x_element), DDATA(x_out), IDATA(flag)); Py_INCREF(Py_None); return Py_None; }
static void rec_delaunay(site_struct * sites[], int sl, int sh, edge_ref * le, edge_ref * re) { if (sh == sl + 2) { edge_ref a = make_edge(); ODATA(a) = sites[sl]; DDATA(a) = sites[sl + 1]; *le = a; *re = SYM(a); } else if (sh == sl + 3) { edge_ref a = make_edge(); edge_ref b = make_edge(); double ct = ccw(sites[sl], sites[sl + 1], sites[sl + 2]); splice(SYM(a), b); ODATA(a) = sites[sl]; DDATA(a) = sites[sl + 1]; ODATA(b) = sites[sl + 1]; DDATA(b) = sites[sl + 2]; if (ct == 0.0) { *le = a; *re = SYM(b); } else { edge_ref c = connect(b, a); if (ct > 0.0) { *le = a; *re = SYM(b); } else { *le = SYM(c); *re = c; } } } else { edge_ref ldo, ldi, rdi, rdo; edge_ref basel, lcand, rcand; int sm = (sl + sh) / 2; rec_delaunay(sites, sl, sm, &ldo, &ldi); rec_delaunay(sites, sm, sh, &rdi, &rdo); while (1) { if (leftof(ORG(rdi), ldi)) ldi = LNEXT(ldi); else if (rightof(ORG(ldi), rdi)) rdi = ONEXT(SYM(rdi)); else break; } basel = connect(SYM(rdi), ldi); if (ORG(ldi) == ORG(ldo)) ldo = SYM(basel); if (ORG(rdi) == ORG(rdo)) rdo = basel; while (1) { lcand = ONEXT(SYM(basel)); if (rightof(DEST(lcand), basel)) while (incircle (DEST(basel), ORG(basel), DEST(lcand), DEST(ONEXT(lcand)))) { edge_ref t = ONEXT(lcand); destroy_edge(lcand); lcand = t; } rcand = OPREV(basel); if (rightof(DEST(rcand), basel)) while (incircle (DEST(basel), ORG(basel), DEST(rcand), DEST(OPREV(rcand)))) { edge_ref t = OPREV(rcand); destroy_edge(rcand); rcand = t; } if (!rightof(DEST(lcand), basel) && !rightof(DEST(rcand), basel)) break; if (!rightof(DEST(lcand), basel) || (rightof(DEST(rcand), basel) && incircle(DEST(lcand), ORG(lcand), ORG(rcand), DEST(rcand)))) basel = connect(rcand, SYM(basel)); else basel = connect(SYM(basel), SYM(lcand)); } *le = ldo; *re = rdo; } }
static PyObject * rsgrid (PyObject *self, PyObject *args) { PyObject *input; PyArrayObject *data, *P, *wvals; int ndat, nw, i, j, Pdims[1]; double *times, *Pdata, *wdata; double *sd, *cd1, *swt, *cwt; double w_l, w_u, dw, dwt, wt, w, temp; double S, C; /** Initialize objects to NULL that we may have to XDECREF if a constructor ** fails so that XDECREF has an argument to work with. Strictly, this ** isn't needed for every object. */ data = NULL; P = NULL; wvals = NULL; sd = NULL; cd1 = NULL; swt = NULL; cwt = NULL; /** Parse the args; make the data array contiguous. */ Py_TRY(PyArg_ParseTuple(args, "iddO", &nw, &w_l, &w_u, &input)); data = (PyArrayObject *) PyArray_ContiguousFromObject(input, PyArray_DOUBLE, 1, 1); if (data == NULL) goto FAIL; /** Store the # of data; make vector references to event times. */ ndat = data->dimensions[0]; times = DDATA(data); /** Make space for the trig. */ sd = (double *) malloc(ndat*sizeof(double)); cd1 = (double *) malloc(ndat*sizeof(double)); swt = (double *) malloc(ndat*sizeof(double)); cwt = (double *) malloc(ndat*sizeof(double)); /** Setup for the trig recurrences we'll use in the frequency loop. */ dw = (w_u - w_l) / (nw-1); for (j=0; j<ndat; j++) { dwt = dw * *(times+j); sd[j] = sin(dwt); cd1[j] = sin(0.5*dwt); cd1[j] = -2.*cd1[j]*cd1[j]; wt = w_l * *(times+j); swt[j] = sin(wt); cwt[j] = cos(wt); } /** Loop over frequencies. */ Pdims[0] = nw; P = (PyArrayObject *)PyArray_FromDims(1, Pdims, PyArray_DOUBLE); if (P == NULL) goto FAIL; Pdata = DDATA(P); wvals = (PyArrayObject *)PyArray_FromDims(1, Pdims, PyArray_DOUBLE); if (wvals == NULL) goto FAIL; wdata = DDATA(wvals); w = w_l; for (i=0; i<nw; i++) { wdata[i] = w; w += dw; S = C = 0.; /* Loop over data to calculate the Rayleigh power; also, use some trig to prepare for the next frequency. */ for (j=0; j<ndat; j++) { S = S + swt[j]; C = C + cwt[j]; temp = cwt[j]; cwt[j] = cwt[j] + (cwt[j]*cd1[j] - swt[j]*sd[j]); swt[j] = swt[j] + (swt[j]*cd1[j] + temp*sd[j]); } Pdata[i] = (S*S + C*C)/ndat; } /** Clean up and return everything in a tuple. */ Py_DECREF(data); free(sd); free(cd1); free(swt); free(cwt); return Py_BuildValue("NN", PyArray_Return(wvals), PyArray_Return(P)); /** Misbehavior ends up here! */ FAIL: Py_XDECREF(data); Py_XDECREF(P); Py_XDECREF(wvals); if (sd != NULL) free(sd); if (cd1 != NULL) free(cd1); if (swt != NULL) free(swt); if (cwt != NULL) free(cwt); return NULL; }