/** * v_error_free: * @error: a #VError to free. * * Free's @error and its contents. */ void v_error_free (VError *error) { v_free (error->module); v_free (error->message); v_free (error); }
//-------------------------------------------------------------------------- Omu_IntRKsuite::~Omu_IntRKsuite() { v_free(_thres); v_free(_work); v_free(_u); v_free(_yp); }
static void calc_rhs_Tr_m(int n_models, MAT **Vk,MAT *VinvIminAw, VEC *y, VEC *rhs, MAT *Tr_m) { int j, k; MAT **Pr = NULL, *Tmp = MNULL; VEC *v_tmp = VNULL, *v_tmp2; Pr = (MAT **) emalloc(n_models * sizeof(MAT *)); v_tmp2 = vm_mlt(VinvIminAw, y, VNULL); /* Vw-(I-Aw)Y == Y'(I-Aw)'Vw- */ for (j = 0; j < n_models; j++) { Pr[j] = m_mlt(Vk[j], VinvIminAw, MNULL); Tmp = m_mlt(Pr[j], Pr[j], Tmp); Tr_m->me[j][j] = trace_matrix(Tmp); /* diagonal */ /* using Tr(A B) == Tr(B A) */ for (k = 0; k < j; k++) { /* we did Pr[k] and Pr[j], so */ Tmp = m_mlt(Pr[j], Pr[k], Tmp); /* off-diagonal */ Tr_m->me[j][k] = Tr_m->me[k][j] = trace_matrix(Tmp); } v_tmp = vm_mlt(Vk[j], v_tmp2, v_tmp); /* Vw-1(I-Aw)Y */ rhs->ve[j] = in_prod(v_tmp2, v_tmp); } for (j = 0; j < n_models; j++) m_free(Pr[j]); efree(Pr); m_free(Tmp); v_free(v_tmp); v_free(v_tmp2); return; }
/** * v_frame_free: * @frame: a #VFrame to free. * * Free's @frame and its contents. */ void v_frame_free (VFrame *frame) { /* free frame data */ switch (frame->type) { case V_FRAME_TYPE_RAW: v_free (V_FRAME_RAW (frame)->data); break; case V_FRAME_TYPE_AUDIO: v_free (V_FRAME_AUDIO (frame)->samples); break; case V_FRAME_TYPE_VIDEO: //v_free (V_FRAME_VIDEO (frame)->data); break; case V_FRAME_TYPE_SUBTITLE: break; } /* destroy frame */ v_free (frame); }
// kernelRegression // x:data // dimention: x's dimention // y: label of x // num: number of data // result: coeffience double *kernelRegression(double **x,int dimention,double *y,int num,double gamma,double regilarization){ VEC *label; MAT *gram,*ident,*inv; int i,j; double *result; ident = m_get(num,num); label = v_get(num); memcpy(label->ve,y,sizeof(double)*num); gram = m_get(num,num); ident = m_get(num,num); for(i=0;i<num;i++){ for(j=0;j<num;j++){ gram->me[i][j]=kernel(x[i],x[j],dimention,gamma); } } inv=m_add(gram,sm_mlt(regilarization,m_ident(ident),NULL),NULL); inv=m_inverse(inv,NULL); //memory leak. VEC *coefficient=v_get(num); mv_mlt(inv,label,coefficient); result=malloc(sizeof(double)*num); memcpy(result,coefficient->ve,sizeof(double)*num); m_free(ident); m_free(gram); m_free(inv); v_free(label); v_free(coefficient); return result; }
//------------------------------------------------------------------------- Prg_ASCEND::~Prg_ASCEND() { iv_free(_var_solver_idxs); iv_free(_var_master_idxs); v_free(_derivatives); iv_free(_var_asc2hqp); v_free(_var_ub); v_free(_var_lb); }
void v_connection_free(v_connection_t *c) { v_free(c->local_addr); v_free(c->remote_addr); v_free(c->read_callback); v_free(c->write_callback); v_free(c); }
/* * resize an existing array */ void v_resize_array(var_t *v, dword size) { if (v->type == V_ARRAY) { if ((int)size < 0) { err_evargerr(); return; } int i; if (size == 0) { v_free(v); v->type = V_ARRAY; v->v.a.size = 0; v->v.a.data = NULL; v->v.a.ubound[0] = v->v.a.lbound[0] = opt_base; v->v.a.maxdim = 1; } else if (v->v.a.size > size) { // resize down // free vars for (i = size; i < v->v.a.size; i++) { var_t *elem = v_elem(v, i); v_free(elem); } // array data v->v.a.size = size; v->v.a.ubound[0] = v->v.a.lbound[0] + (size - 1); v->v.a.maxdim = 1; } else if (v->v.a.size < size) { // resize up, if there is space do not resize int prev_size = v->v.a.size; if (prev_size == 0) { v_new_array(v, size); } else if (prev_size < size) { // resize & copy v->v.a.data = (var_t *)realloc(v->v.a.data, sizeof(var_t) * size); v->v.a.size = size; } // init vars for (i = prev_size; i < size; i++) { var_t *elem = v_elem(v, i); v_init(elem); } // array data v->v.a.size = size; v->v.a.ubound[0] = v->v.a.lbound[0] + (size - 1); v->v.a.maxdim = 1; } } else { err_varisnotarray(); } }
void v_connection_idle(v_connection_t *c) { c->next = v_config.free_connections; v_config.free_connections = c; v_config.free_connections_count++; v_free(c->local_addr); v_free(c->remote_addr); c->local_addr = NULL; c->remote_addr = NULL; c->event->type = V_IO_NONE; c->status = V_CONNECTION_NONE; }
//-------------------------------------------------------------------------- Omu_IntODE::~Omu_IntODE() { m_free(_Y2); m_free(_X2); v_free(_v); v_free(_x); v_free(_u); v_free(_y); m_free(_Yx); m_free(_Yu); }
/** * cleanup the given element */ void tree_delete_node(Node *node) { // cleanup v_new v_free(node->key); v_detach(node->key); // cleanup v_new if (node->value) { v_free(node->value); v_detach(node->value); } // cleanup the node free(node); }
static MAT *calc_VinvIminAw(MAT *Vw, MAT *X, MAT *VinvIminAw, int calc_Aw) { /* * calculate V_w^-1(I-A_w) (==VinvIminAw), * A = X(X'X)^-1 X' (AY = XBeta; Beta = (X'X)^-1 X'Y) * * on second thought (Nov 1998 -- more than 4 years later :-)) * calc (I-Aw) only once and keep this constant during iteration. */ MAT *tmp = MNULL, *V = MNULL; VEC *b = VNULL, *rhs = VNULL; int i, j; if (X->m != Vw->n || VinvIminAw->m != X->m) ErrMsg(ER_IMPOSVAL, "calc_VinvIminAw: sizes don't match"); if (calc_Aw) { IminAw = m_resize(IminAw, X->m, X->m); tmp = m_resize(tmp, X->n, X->n); tmp = mtrm_mlt(X, X, tmp); /* X'X */ m_inverse(tmp, tmp); /* (X'X)-1 */ /* X(X'X)-1 -> X(X'X)-1 X') */ IminAw = XVXt_mlt(X, tmp, IminAw); for (i = 0; i < IminAw->m; i++) /* I - Aw */ for (j = 0; j <= i; j++) if (i == j) IminAw->me[i][j] = 1.0 - IminAw->me[i][j]; else IminAw->me[i][j] = IminAw->me[j][i] = -IminAw->me[i][j]; } V = m_copy(Vw, V); LDLfactor(V); rhs = v_resize(rhs, X->m); b = v_resize(b, X->m); for (i = 0; i < X->m; i++) { /* solve Vw X = (I-A) for X -> V-1(I-A) */ rhs = get_col(IminAw, i, rhs); LDLsolve(V, rhs, b); set_col(VinvIminAw, i, b); } v_free(rhs); v_free(b); m_free(V); if (tmp) m_free(tmp); return VinvIminAw; }
// assign error to variable or match with next expression int err_throw_catch(const char *err) { var_t *arg; var_t v_catch; int caught = 1; switch (code_peek()) { case kwTYPE_VAR: arg = code_getvarptr(); v_setstr(arg, err); break; case kwTYPE_STR: v_init(&v_catch); eval(&v_catch); // catch is conditional on matching error caught = (v_catch.type == V_STR && strstr(err, v_catch.v.p.ptr) != NULL); v_free(&v_catch); break; case kwTYPE_EOC: case kwTYPE_LINE: break; default: rt_raise(ERR_INVALID_CATCH); break; } return caught; }
/* * create array */ void v_toarray1(var_t *v, dword r) { var_t *e; dword i; v_free(v); v->type = V_ARRAY; if (r > 0) { // create data v->v.a.size = r; v->v.a.ptr = malloc(sizeof(var_t) * (v->v.a.size + ARR_ALLOC)); for (i = 0; i < r; i++) { e = (var_t *)(v->v.a.ptr + (sizeof(var_t) * i)); v_init(e); } // array info v->v.a.maxdim = 1; v->v.a.lbound[0] = opt_base; v->v.a.ubound[0] = opt_base + (r - 1); } else { v->v.a.size = 0; v->v.a.ptr = NULL; v->v.a.lbound[0] = v->v.a.ubound[0] = opt_base; v->v.a.maxdim = 1; } }
/* * convert's a user's string to variable * * its decides in what format to store the value * its used mostly by 'input' functions */ void v_input2var(const char *str, var_t *var) { v_free(var); if (strlen(str) == 0) { // no data v_setstr(var, str); } else { char *np, *sb; char buf[64]; int type; var_int_t lv; var_num_t dv; sb = strdup(str); np = get_numexpr(sb, buf, &type, &lv, &dv); if (type == 1 && *np == '\0') { v_setint(var, lv); } else if (type == 2 && *np == '\0') { v_setreal(var, dv); } else { v_setstr(var, str); } free(sb); } }
/* * set an empty string */ void v_zerostr(var_t *r) { v_free(r); r->type = V_STR; r->v.p.ptr = malloc(1); r->v.p.ptr[0] = '\0'; r->v.p.size = 1; }
void v_setstr(var_t *var, const char *string) { v_free(var); var->type = V_STR; var->v.p.size = strlen(string) + 1; var->v.p.ptr = tmp_alloc(var->v.p.size); strcpy(var->v.p.ptr, string); }
/* *release variable */ void v_free(var_t *v) { int i; var_t *elem; switch (v->type) { case V_STR: if (v->v.p.ptr) { tmp_free(v->v.p.ptr); } v->v.p.ptr = NULL; v->v.p.size = 0; break; case V_ARRAY: if (v->v.a.size) { if (v->v.a.ptr) { for (i = 0; i < v->v.a.size; i++) { elem = (var_t *) (v->v.a.ptr + (sizeof(var_t) *i)); v_free(elem); } tmp_free(v->v.a.ptr); v->v.a.ptr = NULL; v->v.a.size = 0; } } break; case V_UDS: break; } v_init(v); }
//-------------------------------------------------------------------------- Hqp_IpRedSpBKP::~Hqp_IpRedSpBKP() { sp_free(_CT); sp_free(_J); sp_free(_J_raw); px_free(_QP2J); px_free(_J2QP); px_free(_pivot); px_free(_blocks); v_free(_zw); v_free(_scale); v_free(_r12); v_free(_xy); iv_free(_CTC_degree); iv_free(_CTC_neigh_start); iv_free(_CTC_neighs); }
/* * create RxC array */ void v_tomatrix(var_t *v, int r, int c) { v_free(v); v_new_array(v, r * c); v->v.a.lbound[0] = v->v.a.lbound[1] = opt_base; v->v.a.ubound[0] = opt_base + (r - 1); v->v.a.ubound[1] = opt_base + (c - 1); v->v.a.maxdim = 2; }
/****************************************************************************** * MAIN function ******************************************************************************/ int main ( int argc, char **argv ) { Widget appShell = init_application(&argc, argv ); catch_sigterm(); trace_main = TRACE_MAIN; signal(SIGPIPE, SIG_IGN); /* ignore broken pipe on write */ /* -- Register all application specific callbacks and widget classes */ RegisterApplication ( appShell ); add_winmove_translations(appShell); /* -- Create widget tree below toplevel shell using Xrm database register callbacks,actions, widget classe before */ WcWidgetCreation ( appShell ); /* get application resources and widget ptr */ XtGetApplicationResources( appShell, (XtPointer)&SETTINGS, basicSettingRes, XtNumber(basicSettingRes), (ArgList)0, 0 ); SETTINGS.app = XtWidgetToApplicationContext(appShell); SETTINGS.vset = v_init(); /* init widgets */ trace_level = SETTINGS.traceLevel; TRACE(1,"Thermal1 %s\nThermal2 %s", SETTINGS.p[0], SETTINGS.p[1] ); /* init application functions All widgets are created, but not visible. functions can now communicate with widgets */ update_cb(0,0); /* start timer */ /* -- Realize the widget tree and enter the main application loop */ XtRealizeWidget ( appShell ); grab_window_quit( appShell ); make_borderless_window(appShell); make_stay_above(appShell); int x0,y0; if( load_window_position(&x0,&y0) == 0 ) XMoveWindow(XtDisplay(appShell),XtWindow(appShell), x0, y0 ); XtAppMainLoop(XtWidgetToApplicationContext(appShell)); /* use XtAppSetExitFlag */ Dimension x,y; XtVaGetValues( appShell, "x", &x, "y", &y, NULL ); save_window_position(x,y); XtDestroyWidget(appShell); v_free( SETTINGS.vset ); m_destruct(); return EXIT_SUCCESS; }
extern int v_free_vars(VEC **pv,...) { va_list ap; int i=1; VEC **par; v_free(*pv); *pv = VNULL; va_start(ap, pv); while (par = va_arg(ap,VEC **)) { /* NULL ends the list*/ v_free(*par); *par = VNULL; i++; } va_end(ap); return i; }
/* * set the value of 'var' to string */ void v_setstr(var_t *var, const char *string) { if (var->type != V_STR || strcmp(string, var->v.p.ptr) != 0) { v_free(var); var->type = V_STR; var->v.p.size = strlen(string) + 1; var->v.p.ptr = malloc(var->v.p.size); strcpy(var->v.p.ptr, string); } }
void v_setstrn(var_t *var, const char *string, int len) { if (var->type != V_STR || strncmp(string, var->v.p.ptr, len) != 0) { v_free(var); var->type = V_STR; var->v.p.size = len + 1; var->v.p.ptr = malloc(var->v.p.size); strncpy(var->v.p.ptr, string, len); var->v.p.ptr[len] = '\0'; } }
int16_t peakiness(int16_t input[], int16_t npts) { register int16_t i; int16_t peak_fact, scale = 4; int32_t sum_abs, L_temp; int16_t temp1, temp2, *temp_buf; temp_buf = v_get(npts); v_equ_shr(temp_buf, input, scale, npts); L_temp = L_v_magsq(temp_buf, npts, 0, 1); if (L_temp) { temp1 = melpe_norm_l(L_temp); scale = melpe_sub(scale, melpe_shr(temp1, 1)); if (scale < 0) scale = 0; } else scale = 0; sum_abs = 0; for (i = 0; i < npts; i++) { L_temp = melpe_L_deposit_l(melpe_abs_s(input[i])); sum_abs = melpe_L_add(sum_abs, L_temp); } /* Right shift input signal and put in temp buffer. */ if (scale) v_equ_shr(temp_buf, input, scale, npts); if (sum_abs > 0) { /* peak_fact = sqrt(npts * v_magsq(input, npts))/sum_abs */ /* = sqrt(npts) * (sqrt(v_magsq(input, npts))/sum_abs) */ if (scale) L_temp = L_v_magsq(temp_buf, npts, 0, 0); else L_temp = L_v_magsq(input, npts, 0, 0); L_temp = melpe_L_deposit_l(L_sqrt_fxp(L_temp, 0)); /* L_temp in Q0 */ peak_fact = L_divider2(L_temp, sum_abs, 0, 0); if (peak_fact > LIMIT_PEAKI) { peak_fact = SW_MAX; } else { /* shl 7 is mult , other shift is Q7->Q12 */ temp1 = melpe_add(scale, 5); temp2 = melpe_shl(npts, 7); temp2 = sqrt_fxp(temp2, 7); L_temp = melpe_L_mult(peak_fact, temp2); L_temp = melpe_L_shl(L_temp, temp1); peak_fact = melpe_extract_h(L_temp); } } else peak_fact = 0; v_free(temp_buf); return (peak_fact); }
/* * assign (dest = src) */ void v_set(var_t *dest, const var_t *src) { int i; var_t *dest_vp, *src_vp; if (src->type == V_UDS) { uds_set(dest, (const var_p_t) src); return; } else if (dest->type == V_UDS) { // lvalue struct assigned to non-struct rvalue uds_clear(dest); return; } else if (src->type == V_HASH) { hash_set(dest, (const var_p_t) src); return; } else if (dest->type == V_HASH) { // lvalue struct assigned to non-struct rvalue hash_clear(dest); return; } v_free(dest); *dest = *src; dest->const_flag = 0; switch (src->type) { case V_STR: dest->v.p.ptr = (byte *) tmp_alloc(strlen((char *)src->v.p.ptr) + 1); strcpy((char *) dest->v.p.ptr, (char *) src->v.p.ptr); break; case V_ARRAY: if (src->v.a.size) { dest->v.a.ptr = tmp_alloc(src->v.a.size * sizeof(var_t)); // copy each element for (i = 0; i < src->v.a.size; i++) { src_vp = (var_t *) (src->v.a.ptr + (sizeof(var_t) * i)); dest_vp = (var_t *) (dest->v.a.ptr + (sizeof(var_t) * i)); v_init(dest_vp); v_set(dest_vp, src_vp); } } else { dest->v.a.size = 0; dest->v.a.ptr = NULL; dest->v.a.ubound[0] = dest->v.a.lbound[0] = opt_base; dest->v.a.maxdim = 1; } break; case V_PTR: dest->v.ap = src->v.ap; dest->type = src->type; break; } }
/** * initialise the variable as a map */ void hashmap_create(var_p_t map, int size) { v_free(map); map->type = V_MAP; map->v.m.count = 0; if (size == 0) { map->v.m.size = MAP_SIZE; } else { map->v.m.size = (size * 100) / 75; } map->v.m.map = calloc(map->v.m.size, sizeof(Node *)); }
/* * assign (dest = src) */ void v_set(var_t *dest, const var_t *src) { v_free(dest); dest->const_flag = 0; dest->type = src->type; switch (src->type) { case V_INT: dest->v.i = src->v.i; break; case V_STR: dest->v.p.size = strlen(src->v.p.ptr) + 1; dest->v.p.ptr = (char *)malloc(dest->v.p.size); strcpy(dest->v.p.ptr, src->v.p.ptr); break; case V_NUM: dest->v.n = src->v.n; break; case V_MAP: map_set(dest, (const var_p_t)src); break; case V_PTR: dest->v.ap.p = src->v.ap.p; dest->v.ap.v = src->v.ap.v; break; case V_REF: dest->v.ref = src->v.ref; break; case V_FUNC: dest->v.fn.cb = src->v.fn.cb; dest->v.fn.self = src->v.fn.self; break; case V_ARRAY: if (src->v.a.size) { memcpy(&dest->v.a, &src->v.a, sizeof(src->v.a)); dest->v.a.ptr = malloc(src->v.a.size * sizeof(var_t)); // copy each element int i; var_t *dest_vp, *src_vp; for (i = 0; i < src->v.a.size; i++) { src_vp = (var_t *)(src->v.a.ptr + (sizeof(var_t) * i)); dest_vp = (var_t *)(dest->v.a.ptr + (sizeof(var_t) * i)); v_init(dest_vp); v_set(dest_vp, src_vp); } } else { dest->v.a.size = 0; dest->v.a.ptr = NULL; dest->v.a.ubound[0] = dest->v.a.lbound[0] = opt_base; dest->v.a.maxdim = 1; } break; } }
/** * free parameter table */ void slib_free_ptable(slib_par_t *ptable, int pcount) { #if defined(LNX_EXTLIB) || defined(WIN_EXTLIB) int i; for (i = 0; i < pcount; i++) { if (ptable[i].byref == 0) { v_free(ptable[i].var_p); v_detach(ptable[i].var_p); } } #endif }
/** * execute a procedure */ int sblmgr_procexec(int lib_id, int index) { #if defined(LNX_EXTLIB) || defined(WIN_EXTLIB) slib_t *lib; var_t ret; slib_par_t *ptable = NULL; int (*pexec) (int, int, slib_par_t *, var_t *); int pcount = 0; int success = 0; if (lib_id < 0 || lib_id >= slib_count) { return 0; } lib = &slib_table[lib_id]; pexec = slib_getoptptr(lib, "sblib_proc_exec"); if (pexec == NULL) { return 0; } // build parameter table ptable = malloc(sizeof(slib_par_t) * MAX_PARAM); pcount = slib_build_ptable(ptable); if (prog_error) { slib_free_ptable(ptable, pcount); free(ptable); return 0; } // exec v_init(&ret); success = pexec(index - lib->first_proc, pcount, ptable, &ret); // error if (!success) { if (ret.type == V_STR) { err_throw("lib:%s: %s\n", lib->name, ret.v.p.ptr); } else { err_throw("lib:%s: Unspecified error\n", lib->name); } } // clean-up if (ptable) { slib_free_ptable(ptable, pcount); free(ptable); } v_free(&ret); return success; #else return 0; #endif }