Whisker_Seg *read_segments_whiskpoly1( FILE *file, int *n) { typedef struct {int id; int time; int len;} trunc_WSeg; Whisker_Seg *wv; int i; static double *t = NULL; static size_t t_size = 0; *n = peek_whiskpoly1_footer(file); //read in number of whiskers #ifdef DEBUG_WHISKER_IO_POLYFIT_READ debug("Number of segments: %d\n",*n); #endif wv = (Whisker_Seg*) Guarded_Malloc( sizeof(Whisker_Seg)*(*n), "read whisker segments - format: whiskpoly1"); for( i=0; i<(*n); i++ ) { Whisker_Seg *w = wv + i; int j,len; double px[WHISKER_IO_POLY_DEGREE+1], py[WHISKER_IO_POLY_DEGREE+1]; float s; float *x, *y, *thick, *scores; fread( w, sizeof( trunc_WSeg ), 1, file ); //populates id,time (a.k.a frame id),len len = w->len; linspace_d( 0.0, 1.0, len, &t, &t_size ); x = w->x = (float*) Guarded_Malloc( sizeof(float)*(w->len), "read whisker segments (whiskpoly1 format)" ); y = w->y = (float*) Guarded_Malloc( sizeof(float)*(w->len), "read whisker segments (whiskpoly1 format)" ); thick = w->thick = (float*) Guarded_Malloc( sizeof(float)*(w->len), "read whisker segments (whiskpoly1 format)" ); scores = w->scores = (float*) Guarded_Malloc( sizeof(float)*(w->len), "read whisker segments (whiskpoly1 format)" ); fread( &s, sizeof(float), 1, file ); fread( px, sizeof(double), WHISKER_IO_POLY_DEGREE+1, file ); fread( py, sizeof(double), WHISKER_IO_POLY_DEGREE+1, file ); #ifdef DEBUG_WHISKER_IO_POLYFIT_READ debug("Row: %d\n" " fid:%5d wid:%5d len:%5d\n" " Median score: %f\n" " px[0] %5.5g px[end] %5.5g\n" " py[0] %5.5g py[end] %5.5g\n" ,i,w->time, w->id, w->len,s ,px[0],px[WHISKER_IO_POLY_DEGREE] ,py[0],py[WHISKER_IO_POLY_DEGREE] ); #endif for( j=0; j<len; j++ ) { x[j] = (float) polyval( px, WHISKER_IO_POLY_DEGREE, t[j] ); y[j] = (float) polyval( py, WHISKER_IO_POLY_DEGREE, t[j] ); thick[j] = 1.0; scores[j] = s; } } return wv; }
Trace_Workspace* New_Trace_Workspace() { Trace_Workspace *tw = (Trace_Workspace *) Guarded_Malloc(sizeof(Trace_Workspace), "New_Trace_Workspace"); Default_Trace_Workspace(tw); return tw; }
Swc_Node* New_Swc_Node() { Swc_Node *node = (Swc_Node*) Guarded_Malloc(sizeof(Swc_Node), "New_Swc_Node"); Default_Swc_Node(node); return node; }
void Construct_String_Workspace(String_Workspace * sw, int size) { sw->size = size; sw->array = (char*) Guarded_Malloc(string_workspace_asize(sw), "Construct_String_Workspace"); sw->iterator = sw->array; }
Objlabel_Workspace *New_Objlabel_Workspace() { Objlabel_Workspace *ow = (Objlabel_Workspace *) Guarded_Malloc(sizeof(Objlabel_Workspace), "New_Objlabel_Workspace"); Default_Objlabel_Workspace(ow); return ow; }
Neuron_Component *New_Neuron_Component() { Neuron_Component *nc = (Neuron_Component *) Guarded_Malloc(sizeof(Neuron_Component), "New_Neuron_Component"); Reset_Neuron_Component(nc); return nc; }
Intpair_Map* Make_Intpair_Map(int length) { Intpair_Map *map = (Intpair_Map*) Guarded_Malloc(sizeof(Intpair_Map), "New_Intpair_Map"); map->length = length; map->bucket = (Intpair_Map_Entry*) Guarded_Malloc(sizeof(Intpair_Map_Entry) * length, "New_Intpair_Map"); int i; for (i = 0; i < length; i++) { map->bucket[i].next = NULL; } Reset_Intpair_Map(map); return map; }
Trace_Record* New_Trace_Record() { Trace_Record *tr = (Trace_Record *) Guarded_Malloc(sizeof(Trace_Record), "New_Trace_Record"); Reset_Trace_Record(tr); return tr; }
unsigned int Terminator::run(IDevice *d) { Chan **q; // input queues (all input channels) void **buf; // array of token buffers size_t *szs; // array of buffer sizes unsigned int i, n, any; n = d->_in->nelem; q = (Chan **) (Guarded_Malloc(n*sizeof(Chan*), "Worker device task - Terminator")); buf = (void**) (Guarded_Malloc(n * sizeof(void*), "Worker device task - Terminator")); szs = (size_t*) (Guarded_Malloc(n * sizeof(size_t), "Worker device task - Terminator")); // alloc the token buffers for (i = 0; i < n; i++) { q[i] = Chan_Open(d->_in->contents[i],CHAN_READ); buf[i] = Chan_Token_Buffer_Alloc(q[i]); szs[i] = Chan_Buffer_Size_Bytes(q[i]); } // main loop do { #if 0 if( !Chan_Is_Empty(q[0]) ) DBG("Convenient break point\r\n"); #endif any=0; for(i=0;i<n;++i) { any |= CHAN_SUCCESS(Chan_Next(q[i],buf+i,szs[i])); szs[i] = Chan_Buffer_Size_Bytes(q[i]); } } while(any); // quits when all inputs fail to pop // cleanup for (i = 0; i < n; i++) { Chan_Token_Buffer_Free(buf[i]); Chan_Close(q[i]); } free(buf); return 0; // success }
Local_Bifold_Neuroseg* New_Local_Bifold_Neuroseg() { Local_Bifold_Neuroseg *locbn = (Local_Bifold_Neuroseg *) Guarded_Malloc(sizeof(Local_Bifold_Neuroseg), "New_Local_Bifold_Neuroseg"); Reset_Local_Bifold_Neuroseg(locbn); return locbn; }
Neuroseg_Ellipse* New_Neuroseg_Ellipse() { Neuroseg_Ellipse *np = (Neuroseg_Ellipse *) Guarded_Malloc(sizeof(Neuroseg_Ellipse), "New_Neuroseg_Ellipse"); Reset_Neuroseg_Ellipse(np); return np; }
Stack_Graph_Workspace* New_Stack_Graph_Workspace() { Stack_Graph_Workspace *sgw = (Stack_Graph_Workspace*) Guarded_Malloc(sizeof(Stack_Graph_Workspace), "New_Stack_Graph_Workspace"); Default_Stack_Graph_Workspace(sgw); return sgw; }
Receptor_Score_Workspace* New_Receptor_Score_Workspace() { Receptor_Score_Workspace *ws = (Receptor_Score_Workspace*) Guarded_Malloc(sizeof(Receptor_Score_Workspace), "New_Locseg_Score_Workspace"); Default_Receptor_Score_Workspace(ws); return ws; }
Neurocomp_Conn* New_Neurocomp_Conn() { Neurocomp_Conn *conn = (Neurocomp_Conn *) Guarded_Malloc(sizeof(Neurocomp_Conn), "New_Neurocomp_Conn"); Default_Neurocomp_Conn(conn); return conn; }
Stack_Draw_Workspace *New_Stack_Draw_Workspace() { Stack_Draw_Workspace *ws = (Stack_Draw_Workspace*) Guarded_Malloc(sizeof(Stack_Draw_Workspace), "New_Stack_Draw_Workspace"); Default_Stack_Draw_Workspace(ws); return ws; }
Local_Neuroseg_Plane* New_Local_Neuroseg_Plane() { Local_Neuroseg_Plane *locnp = (Local_Neuroseg_Plane *) Guarded_Malloc(sizeof(Local_Neuroseg_Plane), "New_Local_Neuroseg_Plane"); Reset_Local_Neuroseg_Plane(locnp); return locnp; }
Array *Make_Array( int *shape , int ndim, int bytesperpixel ) { int i = ndim; Array *a = (Array *) Guarded_Malloc ( sizeof(Array ), "array struct" ); a->ndim = ndim; a->shape = ( int*) Guarded_Malloc ( ndim * sizeof(int), "array shape" ); a->strides_bytes = ( int*) Guarded_Malloc ( (ndim+1) * sizeof(int), "array strides bytes" ); a->strides_px = ( int*) Guarded_Malloc ( (ndim+1) * sizeof(int), "array strides px" ); a->strides_bytes[ndim] = bytesperpixel; a->strides_px[ndim] = 1; while(i--) // For shape = (w,h,d): { a->strides_bytes[i] = a->strides_bytes[i+1] * shape[ndim-1 - i];// strides = (whd, wh, w, 1) a->strides_px[i] = a->strides_bytes[i] / bytesperpixel; a->shape[i] = shape[i]; } a->data = Guarded_Malloc( a->strides_bytes[0],"array data" ); return a; }
Connection_Test_Workspace* New_Connection_Test_Workspace() { Connection_Test_Workspace *ctw = (Connection_Test_Workspace*) Guarded_Malloc(sizeof(Connection_Test_Workspace), "New_Connection_Test_Workspace"); Default_Connection_Test_Workspace(ctw); return ctw; }
Locseg_Label_Workspace* New_Locseg_Label_Workspace() { Locseg_Label_Workspace *ws = (Locseg_Label_Workspace*) Guarded_Malloc(sizeof(Locseg_Label_Workspace), "New_Locseg_Label_Workspace"); Default_Locseg_Label_Workspace(ws); return ws; }
Locseg_Ellipse_Fit_Workspace* New_Locseg_Ellipse_Fit_Workspace() { Locseg_Ellipse_Fit_Workspace *ws = (Locseg_Ellipse_Fit_Workspace*) Guarded_Malloc(sizeof(Locseg_Ellipse_Fit_Workspace), "New_Locseg_Ellipse_Fit_Workspace"); ws->sws = NULL; Default_Locseg_Ellipse_Fit_Workspace(ws); return ws; }
Locseg_Chain_Knot* New_Locseg_Chain_Knot() { Locseg_Chain_Knot *knot = (Locseg_Chain_Knot*) Guarded_Malloc(sizeof(Locseg_Chain_Knot), "New_Locseg_Chain_Knot"); knot->id = -1; knot->offset = 0.0; return knot; }
Trace_Evaluate_Seed_Workspace* New_Trace_Evaluate_Seed_Workspace() { Trace_Evaluate_Seed_Workspace *ws = (Trace_Evaluate_Seed_Workspace*) Guarded_Malloc(sizeof(Trace_Evaluate_Seed_Workspace), "New_Trace_Evaluate_Seed_Workspace"); Default_Trace_Evaluate_Seed_Workspace(ws); return ws; }
Locseg_Chain_Knot_Array* New_Locseg_Chain_Knot_Array() { Locseg_Chain_Knot_Array *ka = (Locseg_Chain_Knot_Array*) Guarded_Malloc(sizeof(Locseg_Chain_Knot_Array), "New_Locseg_Chain_Knot_Array"); ka->chain = NULL; ka->knot = NULL; return ka; }
Geo3d_Ellipse* New_Geo3d_Ellipse() { Geo3d_Ellipse *ellipse = (Geo3d_Ellipse*) Guarded_Malloc(sizeof(Geo3d_Ellipse), "New_Geo3d_Ellipse"); Default_Geo3d_Ellipse(ellipse); return ellipse; }
int main(int argc, char* argv[]) { int i = N; double k = 2*M_PI/N; double *t; double *y; int j = 100; clock_t clock0; double t0,t1; t = Guarded_Malloc(sizeof(double)*N,"t"); y = Guarded_Malloc(sizeof(double)*N,"y"); progress(" w t(ms) type\n" "--- ----- ----\n"); while((j-=3)>3) { i=N; while(i--) { t[i] = i; y[i] = sin(k*i*4.0); } clock0 = clock(); maxfilt_centered_double_inplace( y, N, j ); t0 = (double)(clock()-clock0)/((double)(CLOCKS_PER_SEC)); progress("%3d %4.1f sin\n",j, 1e3*t0 ); clock0 = clock(); maxfilt_centered_double_inplace( t, N, j ); t1 = (double)(clock()-clock0)/((double)(CLOCKS_PER_SEC)); progress("%3d %2.1f ramp\n",j, 1e3*t1 ); } progress("\n" "NOTE\n" "----\n" "Timings should be constant with respect to window size (w).\n" "Each time is for an array of %g elements.\n" "Based on the last times...\n" "\tThroughput for the sin wave: %4.1f MSamples/s\n" "\tThroughput for the ramp : %4.1f MSamples/s\n",(double)N, 1e-6*((double)N)/t0, 1e-6*((double)N)/t1 ); free(t); free(y); return 0; }
Intpair_Map_Entry* New_Intpair_Map_Entry() { Intpair_Map_Entry *entry = (Intpair_Map_Entry*) Guarded_Malloc(sizeof(Intpair_Map_Entry), "New_Intpair_Map_Entry"); entry->pair[0] = -1; entry->pair[1] = -1; entry->value = -1; entry->next = NULL; return entry; }
Neuron_Component* Make_Neuron_Component_Array(int n) { Neuron_Component* nc = (Neuron_Component *) Guarded_Malloc(sizeof(Neuron_Component) * n, "New_Neuron_Component"); int i; for (i = 0; i < n; i++) { Reset_Neuron_Component(nc + i); } return nc; }
void Write_Stack_Planes(char *prefix, int num_width, int first_num, Stack *a_stack) { char *name; int n; name = (char *) Guarded_Malloc(strlen(prefix)+50,"Write_Stack_Planes"); for (n = 0; n < a_stack->depth; n++) { sprintf(name,"%s.%0*d.tif",prefix,num_width,first_num+n); Write_Image(name,Select_Plane(a_stack,n)); } free(name); }
Variable_Set *New_Variable_Set() { Variable_Set *vs = (Variable_Set *) Guarded_Malloc(sizeof(Variable_Set), "New_Variable_Set"); vs->nvar = 0; vs->var = NULL; vs->var_index = NULL; vs->link = NULL; return vs; }
Variable_Set *Construct_Variable_Set(Variable_Set *vs, const double *var, int nvar) { ASSERT(vs != NULL, "Null pointer."); vs->nvar = nvar; vs->var_index = (int *) Guarded_Malloc(sizeof(int) * nvar, "Construct_Variable_Set"); vs->var = (double *) var; return vs; }