static idxint infeasible(Data * d, Sol * sol, Info * info) { strcpy(info->status, info->statusVal != 0 ? "Infeasible" : "Infeasible/Inaccurate"); /*scaleArray(sol->y,-1/ip_y,d->m); */ scaleArray(sol->x, NAN, d->n); scaleArray(sol->s, NAN, d->m); return INFEASIBLE; }
static idxint solved(Data * d, Sol * sol, Info * info, pfloat tau) { strcpy(info->status, info->statusVal != 0 ? "Solved" : "Solved/Inaccurate"); scaleArray(sol->x, 1.0 / tau, d->n); scaleArray(sol->y, 1.0 / tau, d->m); scaleArray(sol->s, 1.0 / tau, d->m); return SOLVED; }
static idxint indeterminate(Data * d, Sol * sol, Info * info) { strcpy(info->status, "Indeterminate"); scaleArray(sol->x, NAN, d->n); scaleArray(sol->y, NAN, d->m); scaleArray(sol->s, NAN, d->m); return INDETERMINATE; }
static scs_int pcg(const AMatrix * A, const Settings * stgs, Priv * pr, const scs_float * s, scs_float * b, scs_int max_its, scs_float tol) { scs_int i, n = A->n; scs_float ipzr, ipzrOld, alpha; scs_float *p = pr->p; /* cg direction */ scs_float *Gp = pr->Gp; /* updated CG direction */ scs_float *r = pr->r; /* cg residual */ scs_float *z = pr->z; /* for preconditioning */ scs_float *M = pr->M; /* inverse diagonal preconditioner */ if (s == NULL) { memcpy(r, b, n * sizeof(scs_float)); memset(b, 0, n * sizeof(scs_float)); } else { matVec(A, stgs, pr, s, r); addScaledArray(r, b, n, -1); scaleArray(r, -1, n); memcpy(b, s, n * sizeof(scs_float)); } /* check to see if we need to run CG at all */ if (calcNorm(r, n) < MIN(tol, 1e-18)) { return 0; } applyPreConditioner(M, z, r, n, &ipzr); memcpy(p, z, n * sizeof(scs_float)); for (i = 0; i < max_its; ++i) { matVec(A, stgs, pr, p, Gp); alpha = ipzr / innerProd(p, Gp, n); addScaledArray(b, p, n, alpha); addScaledArray(r, Gp, n, -alpha); if (calcNorm(r, n) < tol) { #if EXTRAVERBOSE > 0 scs_printf("tol: %.4e, resid: %.4e, iters: %li\n", tol, calcNorm(r, n), (long) i+1); #endif return i + 1; } ipzrOld = ipzr; applyPreConditioner(M, z, r, n, &ipzr); scaleArray(p, ipzr / ipzrOld, n); addScaledArray(p, z, n, 1); } return i; }
static void updateWork(Data * d, Work * w, Sol * sol) { /* before normalization */ idxint n = d->n; idxint m = d->m; w->nm_b = calcNorm(d->b, m); w->nm_c = calcNorm(d->c, n); #ifdef EXTRAVERBOSE printArray(d->b, d->m, "b"); scs_printf("pre-normalized norm b = %4f\n", calcNorm(d->b, d->m)); printArray(d->c, d->n, "c"); scs_printf("pre-normalized norm c = %4f\n", calcNorm(d->c, d->n)); #endif if (d->NORMALIZE) { normalizeBC(d, w); #ifdef EXTRAVERBOSE printArray(d->b, d->m, "bn"); scs_printf("sc_b = %4f\n", w->sc_b); scs_printf("post-normalized norm b = %4f\n", calcNorm(d->b, d->m)); printArray(d->c, d->n, "cn"); scs_printf("sc_c = %4f\n", w->sc_c); scs_printf("post-normalized norm c = %4f\n", calcNorm(d->c, d->n)); #endif } if (d->WARM_START) { warmStartVars(d, w, sol); } else { coldStartVars(d, w); } memcpy(w->h, d->c, n * sizeof(pfloat)); memcpy(&(w->h[d->n]), d->b, m * sizeof(pfloat)); memcpy(w->g, w->h, (n + m) * sizeof(pfloat)); solveLinSys(d, w->p, w->g, NULL, -1); scaleArray(&(w->g[d->n]), -1, m); w->gTh = innerProd(w->h, w->g, n + m); }
JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_SwsContextNative_scaleByteArray (JNIEnv *env, jclass jc, jobject jptr, jobject jsrc, jint srcSliceY, jint srcSliceH, jintArray jdst, jint fmt, jint width, jint height) { struct SwsContext *sws = ADDR(jptr); struct AVFrame *src = ADDR(jsrc); return scaleArray(env, sws, src, srcSliceY, srcSliceH, jdst, 1, fmt, width, height); }
/* status < 0 indicates failure */ static idxint projectLinSys(Data * d, Work * w, idxint iter) { /* ut = u + v */ idxint n = d->n, m = d->m, l = n + m + 1, status; memcpy(w->u_t, w->u, l * sizeof(pfloat)); addScaledArray(w->u_t, w->v, l, 1.0); scaleArray(w->u_t, d->RHO_X, n); addScaledArray(w->u_t, w->h, l - 1, -w->u_t[l - 1]); addScaledArray(w->u_t, w->h, l - 1, -innerProd(w->u_t, w->g, l - 1) / (w->gTh + 1)); scaleArray(&(w->u_t[n]), -1, m); status = solveLinSys(d, w->p, w->u_t, w->u, iter); w->u_t[l - 1] += innerProd(w->u_t, w->h, l - 1); return status; }
static idxint failureDefaultReturn(Data * d, Work * w, Sol * sol, Info * info, char * msg) { info->relGap = NAN; info->resPri = NAN; info->resDual = NAN; info->pobj = NAN; info->dobj = NAN; info->iter = -1; info->statusVal = FAILURE; info->solveTime = NAN; strcpy(info->status, "Failure"); if (!sol->x) sol->x = scs_malloc(sizeof(pfloat) * d->n); scaleArray(sol->x, NAN, d->n); if (!sol->y) sol->y = scs_malloc(sizeof(pfloat) * d->m); scaleArray(sol->y, NAN, d->m); if (!sol->s) sol->s = scs_malloc(sizeof(pfloat) * d->m); scaleArray(sol->s, NAN, d->m); scs_printf("FAILURE:%s\n", msg); return FAILURE; }
static void getInfo(Data * d, Work * w, Sol * sol, Info * info) { pfloat cTx, bTy, nmAxs, nmATy, nmpr, nmdr; pfloat * x = sol->x, *y = sol->y, *s = sol->s; /* unNomalized */ nmpr = calcPrimalResid(d, w, x, s, 1, &nmAxs); /* pr = Ax + s - b */ nmdr = calcDualResid(d, w, y, 1, &nmATy); /* dr = A'y + c */ cTx = innerProd(x, d->c, d->n); bTy = innerProd(y, d->b, d->m); if (d->NORMALIZE) { cTx /= (d->SCALE * w->sc_c * w->sc_b); bTy /= (d->SCALE * w->sc_c * w->sc_b); } info->pobj = cTx; info->dobj = -bTy; if (info->statusVal == SOLVED) { info->relGap = ABS(cTx + bTy) / (1 + ABS(cTx) + ABS(bTy)); info->resPri = nmpr / (1 + w->nm_b); info->resDual = nmdr / (1 + w->nm_c); } else { if (info->statusVal == UNBOUNDED) { info->dobj = NAN; info->relGap = NAN; info->resPri = w->nm_c * nmAxs / -cTx; info->resDual = NAN; scaleArray(x, -1 / cTx, d->n); scaleArray(s, -1 / cTx, d->m); info->pobj = -1; } else { info->pobj = NAN; info->relGap = NAN; info->resPri = NAN; info->resDual = w->nm_b * nmATy / -bTy; scaleArray(y, -1 / bTy, d->m); info->dobj = -1; } } }
static void cgCustom(Data *d, Work *w, const double * s, int max_its, double tol) { /* solves (I+A'A)x = b */ /* warm start cg with s */ int i = 0, n = d->n; double *x = w->p->x; double *p = w->p->p; // cg direction double *Ap = w->p->Ap; // updated CG direction double *r = w->p->r; // cg residual double *G = w->p->G; // Gram matrix double alpha, beta, rsnew=0; if (s==NULL) { memset(x,0,n*sizeof(double)); } else { memcpy(x,s,n*sizeof(double)); cblas_dsymv(CblasColMajor, CblasUpper,n, -1, G, n, x,1, 1, r, 1); //b_dsymv('U', n, -1, G, n, x,1, 1, r, 1); } memcpy(p, r, n*sizeof(double)); //double rsold=cblas_dnrm2(n,r,1); double rsold=calcNorm(r,n); for (i=0; i< max_its; i++) { cblas_dsymv(CblasColMajor, CblasUpper,n, 1, G, n, p, 1, 0, Ap, 1); //b_dsymv('U', n, 1, G, n, p, 1, 0, Ap, 1); //beta = cblas_ddot(n, p, 1, Ap, 1); beta = innerProd(p,Ap,n); alpha=(rsold*rsold)/beta; addScaledArray(x,p,n,alpha); //cblas_daxpy(n,alpha,p,1,x,1); addScaledArray(r,Ap,n,-alpha); //cblas_daxpy(n,-alpha,Ap,1,r,1); //rsnew=cblas_dnrm2(n,r,1); rsnew=calcNorm(r,n); if (rsnew<tol) { break; } scaleArray(p,(rsnew*rsnew)/(rsold*rsold),n); //cblas_dscal(n,(rsnew*rsnew)/(rsold*rsold),p,1); addScaledArray(p,r,n,1); //cblas_daxpy(n,1,r,1,p,1); rsold=rsnew; } //printf("terminating cg residual = %4f, took %i itns\n",rsnew,i); }
shared_ptr<Image> IndexedImage::scaled( int width, int height ) { int srcWidth = getWidth(); int srcHeight = getHeight(); // no need to scale if(srcWidth == width && srcHeight == height){ return this->shared_from_this(); } Dimension d(width, height); shared_ptr<Image> i = getCachedImage(d); // currently we only support byte data... i = new IndexedImage(width, height, palette, scaleArray(imageDataByte, width, height)); cacheImage(d, i); return i; }
void prepChar ( int * cImageRaw, int w, int h, int * cImageSS, int *error ) { int * temp; temp = (int *) malloc ( sizeof(int) *STANDARD_WIDTH *STANDARD_HEIGHT); if ( temp == 0 ) { *error = 1; return; } scaleArray(cImageRaw, w, h, temp , STANDARD_WIDTH, STANDARD_HEIGHT, error); normalizeToWideSpectrum2(temp,STANDARD_WIDTH, STANDARD_HEIGHT,cImageSS); // stretch the values from 0-255 to -500 to + 500 for the correlations to work free (temp); }
scs_int solveLinSys(const AMatrix * A, const Settings * stgs, Priv * p, scs_float * b, const scs_float * s, scs_int iter) { scs_int cgIts; scs_float cgTol = calcNorm(b, A->n) * (iter < 0 ? CG_BEST_TOL : CG_MIN_TOL / POWF((scs_float) iter + 1, stgs->cg_rate)); tic(&linsysTimer); /* solves Mx = b, for x but stores result in b */ /* s contains warm-start (if available) */ accumByAtrans(A, p, &(b[A->n]), b); /* solves (I+A'A)x = b, s warm start, solution stored in b */ cgIts = pcg(A, stgs, p, s, b, A->n, MAX(cgTol, CG_BEST_TOL)); scaleArray(&(b[A->n]), -1, A->m); accumByA(A, p, b, &(b[A->n])); if (iter >= 0) { totCgIts += cgIts; } totalSolveTime += tocq(&linsysTimer); #if EXTRAVERBOSE > 0 scs_printf("linsys solve time: %1.2es\n", tocq(&linsysTimer) / 1e3); #endif return 0; }
JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_SwsContextNative_scaleIntArray (JNIEnv *env, jclass jc, jobject jptr, jobject jsrc, jint srcSliceY, jint srcSliceH, jintArray jdst, jint fmt, jint width, jint height) { struct SwsContext *sws = ADDR(jptr); struct AVFrame *src = ADDR(jsrc); return scaleArray(env, sws, src, srcSliceY, srcSliceH, jdst, 4, fmt, width, height); /* cdst = (*env)->GetPrimitiveArrayCritical(env, jdst, NULL); if (!cdst) // FIXME: exception return res; CALLDL(avpicture_fill)(&dst, cdst, fmt, width, height); res = CALLDL(sws_scale)(sws, (const uint8_t * const *)src->data, src->linesize, srcSliceY, srcSliceH, dst.data, dst.linesize); (*env)->ReleasePrimitiveArrayCritical(env, jdst, cdst, 0); return res; */ }
static idxint unbounded(Data * d, Sol * sol, Info * info) { strcpy(info->status, info->statusVal != 0 ? "Unbounded" : "Unbounded/Inaccurate"); /*scaleArray(sol->x,-1/ip_x,d->n); */ scaleArray(sol->y, NAN, d->m); return UNBOUNDED; }