static void coldStartVars(Data * d, Work * w) { idxint l = d->n + d->m + 1; memset(w->u, 0, l * sizeof(pfloat)); memset(w->v, 0, l * sizeof(pfloat)); w->u[l - 1] = SQRTF((pfloat) l); w->v[l - 1] = SQRTF((pfloat) l); }
/** * Compute mipmap LOD from partial derivatives. * This the ideal solution, as given in the OpenGL spec. */ GLfloat _swrast_compute_lambda(GLfloat dsdx, GLfloat dsdy, GLfloat dtdx, GLfloat dtdy, GLfloat dqdx, GLfloat dqdy, GLfloat texW, GLfloat texH, GLfloat s, GLfloat t, GLfloat q, GLfloat invQ) { GLfloat dudx = texW * ((s + dsdx) / (q + dqdx) - s * invQ); GLfloat dvdx = texH * ((t + dtdx) / (q + dqdx) - t * invQ); GLfloat dudy = texW * ((s + dsdy) / (q + dqdy) - s * invQ); GLfloat dvdy = texH * ((t + dtdy) / (q + dqdy) - t * invQ); GLfloat x = SQRTF(dudx * dudx + dvdx * dvdx); GLfloat y = SQRTF(dudy * dudy + dvdy * dvdy); GLfloat rho = MAX2(x, y); GLfloat lambda = LOG2(rho); return lambda; }
static pfloat calcDualResid(Data * d, Work * w, pfloat * y, pfloat tau, pfloat *nmATy) { idxint i; pfloat dres = 0, scale, *dr = w->dr, *E = w->E; *nmATy = 0; memset(dr, 0, d->n * sizeof(pfloat)); accumByAtrans(d, w->p, y, dr); /* dr = A'y */ for (i = 0; i < d->n; ++i) { scale = d->NORMALIZE ? E[i] / (w->sc_c * d->SCALE) : 1; scale = scale * scale; *nmATy += (dr[i] * dr[i]) * scale; dres += (dr[i] + d->c[i] * tau) * (dr[i] + d->c[i] * tau) * scale; } *nmATy = SQRTF(*nmATy); return SQRTF(dres); /* norm(A'y + c * tau) */ }
static void ref_norm_transform_normalize( const GLmatrix *mat, GLfloat scale, const GLvector4f *in, const GLfloat *lengths, GLvector4f *dest ) { GLuint i; const GLfloat *s = in->start; const GLfloat *m = mat->inv; GLfloat (*out)[4] = (GLfloat (*)[4]) dest->start; for ( i = 0 ; i < in->count ; i++ ) { GLfloat t[3]; TRANSFORM_NORMAL( t, s, m ); if ( !lengths ) { GLfloat len = LEN_SQUARED_3FV( t ); if ( len > 1e-20 ) { /* Hmmm, don't know how we could test the precalculated * length case... */ scale = 1.0 / SQRTF( len ); SCALE_SCALAR_3V( out[i], scale, t ); } else { out[i][0] = out[i][1] = out[i][2] = 0; } } else { scale = lengths[i];; SCALE_SCALAR_3V( out[i], scale, t ); } s = (GLfloat *)((char *)s + in->stride); } }
static void setSolution(Data * d, Work * w, Sol * sol, Info * info) { idxint l = d->n + d->m + 1; setx(d, w, sol); sety(d, w, sol); sets(d, w, sol); if (info->statusVal == 0 || info->statusVal == SOLVED) { pfloat tau = w->u[l - 1]; pfloat kap = ABS(w->v[l - 1]); if (tau > INDETERMINATE_TOL && tau > kap) { info->statusVal = solved(d, sol, info, tau); } else { if (calcNorm(w->u, l) < INDETERMINATE_TOL * SQRTF((pfloat) l)) { info->statusVal = indeterminate(d, sol, info); } else { pfloat bTy = innerProd(d->b, sol->y, d->m); pfloat cTx = innerProd(d->c, sol->x, d->n); if (bTy < cTx) { info->statusVal = infeasible(d, sol, info); } else { info->statusVal = unbounded(d, sol, info); } } } } else if (info->statusVal == INFEASIBLE) { info->statusVal = infeasible(d, sol, info); } else { info->statusVal = unbounded(d, sol, info); } }
static pfloat calcPrimalResid(Data * d, Work * w, pfloat * x, pfloat * s, pfloat tau, pfloat *nmAxs) { idxint i; pfloat pres = 0, scale, *pr = w->pr, *D = w->D; *nmAxs = 0; memset(pr, 0, d->m * sizeof(pfloat)); accumByA(d, w->p, x, pr); addScaledArray(pr, s, d->m, 1.0); /* pr = Ax + s */ for (i = 0; i < d->m; ++i) { scale = d->NORMALIZE ? D[i] / (w->sc_b * d->SCALE) : 1; scale = scale * scale; *nmAxs += (pr[i] * pr[i]) * scale; pres += (pr[i] - d->b[i] * tau) * (pr[i] - d->b[i] * tau) * scale; } *nmAxs = SQRTF(*nmAxs); return SQRTF(pres); /* norm(Ax + s - b * tau) */ }
/** * Compute point size for each vertex from the vertex eye-space Z * coordinate and the point size attenuation factors. * Only done when point size attenuation is enabled and vertex program is * disabled. */ static GLboolean run_point_stage(struct gl_context *ctx, struct tnl_pipeline_stage *stage) { if (ctx->Point._Attenuated) { struct point_stage_data *store = POINT_STAGE_DATA(stage); struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; const GLfloat *eyeCoord = (GLfloat *) VB->EyePtr->data + 2; const GLint eyeCoordStride = VB->EyePtr->stride / sizeof(GLfloat); const GLfloat p0 = ctx->Point.Params[0]; const GLfloat p1 = ctx->Point.Params[1]; const GLfloat p2 = ctx->Point.Params[2]; const GLfloat pointSize = ctx->Point.Size; GLfloat (*size)[4] = store->PointSize.data; GLuint i; for (i = 0; i < VB->Count; i++) { const GLfloat dist = FABSF(*eyeCoord); const GLfloat q = p0 + dist * (p1 + dist * p2); const GLfloat atten = (q != 0.0F) ? SQRTF(1.0F / q) : 1.0F; size[i][0] = pointSize * atten; /* clamping done in rasterization */ eyeCoord += eyeCoordStride; } VB->AttribPtr[_TNL_ATTRIB_POINTSIZE] = &store->PointSize; } return GL_TRUE; }
static pfloat fastCalcPrimalResid(Data * d, Work * w, pfloat * nmAxs) { idxint i, n = d->n, m = d->m; pfloat pres = 0, scale, *pr = w->pr, *D = w->D, tau = ABS(w->u[n + m]); *nmAxs = 0; memcpy(pr, &(w->u[n]), m * sizeof(pfloat)); /* overwrite pr */ addScaledArray(pr, &(w->u_prev[n]), m, d->ALPHA - 2); addScaledArray(pr, &(w->u_t[n]), m, 1 - d->ALPHA); addScaledArray(pr, d->b, m, w->u_t[n + m]); /* pr = Ax + s */ for (i = 0; i < m; ++i) { scale = d->NORMALIZE ? D[i] / (w->sc_b * d->SCALE) : 1; scale = scale * scale; *nmAxs += (pr[i] * pr[i]) * scale; pres += (pr[i] - d->b[i] * tau) * (pr[i] - d->b[i] * tau) * scale; } *nmAxs = SQRTF(*nmAxs); return SQRTF(pres); /* norm(Ax + s - b * tau) */ }
scs_float calcNormDiff(const scs_float *a, const scs_float *b, scs_int l) { scs_float nmDiff = 0.0, tmp; scs_int i; for (i = 0; i < l; ++i) { tmp = (a[i] - b[i]); nmDiff += tmp * tmp; } return SQRTF(nmDiff); }
// input : current spectrum in the form of power *spec and phase *phase, // the last two earlier spectrums are at position // 512 and 1024 of the corresponding Input-Arrays. // Array *vocal, which can mark an FFT_Linie as harmonic // output: current amplitude *amp and unpredictability *cw static void CalcUnpred (PsyModel* m, const int MaxLine, const float* spec, const float* phase, const int* vocal, float* amp0, float* phs0, float* cw ) { int n; float amp; float tmp; #define amp1 ((amp0) + 512) // amp[ 512...1023] contains data of frame-1 #define amp2 ((amp0) + 1024) // amp[1024...1535] contains data of frame-2 #define phs1 ((phs0) + 512) // phs[ 512...1023] contains data of frame-1 #define phs2 ((phs0) + 1024) // phs[1024...1535] contains data of frame-2 for ( n = 0; n < MaxLine; n++ ) { tmp = COSF ((phs0[n] = phase[n]) - 2*phs1[n] + phs2[n]); // copy phase to output-array, predict phase and calculate predictive error amp0[n] = SQRTF (spec[n]); // calculate and set amplitude amp = 2*amp1[n] - amp2[n]; // predict amplitude // calculate unpredictability cw[n] = SQRTF (spec[n] + amp * (amp - 2*amp0[n] * tmp)) / (amp0[n] + FABS(amp)); } // postprocessing of harmonic FFT-lines (*cw is set to CVD_UNPRED) if ( m->CVD_used && vocal != NULL ) { for ( n = 0; n < MAX_CVD_LINE; n++, cw++, vocal++ ) if ( *vocal != 0 && *cw > CVD_UNPRED * 0.01 * *vocal ) *cw = CVD_UNPRED * 0.01 * *vocal; } return; }
static int test_norm_function( normal_func func, int mtype, long *cycles ) { GLvector4f source[1], dest[1], dest2[1], ref[1], ref2[1]; GLmatrix mat[1]; GLfloat s[TEST_COUNT][5], d[TEST_COUNT][4], r[TEST_COUNT][4]; GLfloat d2[TEST_COUNT][4], r2[TEST_COUNT][4], length[TEST_COUNT]; GLfloat scale; GLfloat *m; int i, j; #ifdef RUN_DEBUG_BENCHMARK int cycle_i; /* the counter for the benchmarks we run */ #endif (void) cycles; mat->m = (GLfloat *) _mesa_align_malloc( 16 * sizeof(GLfloat), 16 ); mat->inv = m = mat->m; init_matrix( m ); scale = 1.0F + rnd () * norm_scale_types[mtype]; for ( i = 0 ; i < 4 ; i++ ) { for ( j = 0 ; j < 4 ; j++ ) { switch ( norm_templates[mtype][i * 4 + j] ) { case NIL: m[j * 4 + i] = 0.0; break; case ONE: m[j * 4 + i] = 1.0; break; case NEG: m[j * 4 + i] = -1.0; break; case VAR: break; default: exit(1); } } } for ( i = 0 ; i < TEST_COUNT ; i++ ) { ASSIGN_3V( d[i], 0.0, 0.0, 0.0 ); ASSIGN_3V( s[i], 0.0, 0.0, 0.0 ); ASSIGN_3V( d2[i], 0.0, 0.0, 0.0 ); for ( j = 0 ; j < 3 ; j++ ) s[i][j] = rnd(); length[i] = 1 / SQRTF( LEN_SQUARED_3FV( s[i] ) ); } source->data = (GLfloat(*)[4]) s; source->start = (GLfloat *) s; source->count = TEST_COUNT; source->stride = sizeof(s[0]); source->flags = 0; dest->data = d; dest->start = (GLfloat *) d; dest->count = TEST_COUNT; dest->stride = sizeof(float[4]); dest->flags = 0; dest2->data = d2; dest2->start = (GLfloat *) d2; dest2->count = TEST_COUNT; dest2->stride = sizeof(float[4]); dest2->flags = 0; ref->data = r; ref->start = (GLfloat *) r; ref->count = TEST_COUNT; ref->stride = sizeof(float[4]); ref->flags = 0; ref2->data = r2; ref2->start = (GLfloat *) r2; ref2->count = TEST_COUNT; ref2->stride = sizeof(float[4]); ref2->flags = 0; if ( norm_normalize_types[mtype] == 0 ) { ref_norm_transform_rescale( mat, scale, source, NULL, ref ); } else { ref_norm_transform_normalize( mat, scale, source, NULL, ref ); ref_norm_transform_normalize( mat, scale, source, length, ref2 ); } if ( mesa_profile ) { BEGIN_RACE( *cycles ); func( mat, scale, source, NULL, dest ); END_RACE( *cycles ); func( mat, scale, source, length, dest2 ); } else { func( mat, scale, source, NULL, dest ); func( mat, scale, source, length, dest2 ); } for ( i = 0 ; i < TEST_COUNT ; i++ ) { for ( j = 0 ; j < 3 ; j++ ) { if ( significand_match( d[i][j], r[i][j] ) < REQUIRED_PRECISION ) { printf( "-----------------------------\n" ); printf( "(i = %i, j = %i)\n", i, j ); printf( "%f \t %f \t [ratio = %e - %i bit missed]\n", d[i][0], r[i][0], r[i][0]/d[i][0], MAX_PRECISION - significand_match( d[i][0], r[i][0] ) ); printf( "%f \t %f \t [ratio = %e - %i bit missed]\n", d[i][1], r[i][1], r[i][1]/d[i][1], MAX_PRECISION - significand_match( d[i][1], r[i][1] ) ); printf( "%f \t %f \t [ratio = %e - %i bit missed]\n", d[i][2], r[i][2], r[i][2]/d[i][2], MAX_PRECISION - significand_match( d[i][2], r[i][2] ) ); return 0; } if ( norm_normalize_types[mtype] != 0 ) { if ( significand_match( d2[i][j], r2[i][j] ) < REQUIRED_PRECISION ) { printf( "------------------- precalculated length case ------\n" ); printf( "(i = %i, j = %i)\n", i, j ); printf( "%f \t %f \t [ratio = %e - %i bit missed]\n", d2[i][0], r2[i][0], r2[i][0]/d2[i][0], MAX_PRECISION - significand_match( d2[i][0], r2[i][0] ) ); printf( "%f \t %f \t [ratio = %e - %i bit missed]\n", d2[i][1], r2[i][1], r2[i][1]/d2[i][1], MAX_PRECISION - significand_match( d2[i][1], r2[i][1] ) ); printf( "%f \t %f \t [ratio = %e - %i bit missed]\n", d2[i][2], r2[i][2], r2[i][2]/d2[i][2], MAX_PRECISION - significand_match( d2[i][2], r2[i][2] ) ); return 0; } } } } _mesa_align_free( mat->m ); return 1; }
/* ||v||_2 */ scs_float calcNorm(const scs_float * v, scs_int len) { return SQRTF(calcNormSq(v, len)); }
/** * Generate a 4x4 transformation matrix from glRotate parameters, and * post-multiply the input matrix by it. * * \author * This function was contributed by Erich Boleyn ([email protected]). * Optimizations contributed by Rudolf Opalla ([email protected]). */ void _math_matrix_rotate( GLmatrix *mat, GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) { GLfloat xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c, s, c; GLfloat m[16]; GLboolean optimized; s = (GLfloat) sin( angle * DEG2RAD ); c = (GLfloat) cos( angle * DEG2RAD ); memcpy(m, Identity, sizeof(GLfloat)*16); optimized = GL_FALSE; #define M(row,col) m[col*4+row] if (x == 0.0F) { if (y == 0.0F) { if (z != 0.0F) { optimized = GL_TRUE; /* rotate only around z-axis */ M(0,0) = c; M(1,1) = c; if (z < 0.0F) { M(0,1) = s; M(1,0) = -s; } else { M(0,1) = -s; M(1,0) = s; } } } else if (z == 0.0F) { optimized = GL_TRUE; /* rotate only around y-axis */ M(0,0) = c; M(2,2) = c; if (y < 0.0F) { M(0,2) = -s; M(2,0) = s; } else { M(0,2) = s; M(2,0) = -s; } } } else if (y == 0.0F) { if (z == 0.0F) { optimized = GL_TRUE; /* rotate only around x-axis */ M(1,1) = c; M(2,2) = c; if (x < 0.0F) { M(1,2) = s; M(2,1) = -s; } else { M(1,2) = -s; M(2,1) = s; } } } if (!optimized) { const GLfloat mag = SQRTF(x * x + y * y + z * z); if (mag <= 1.0e-4) { /* no rotation, leave mat as-is */ return; } x /= mag; y /= mag; z /= mag; /* * Arbitrary axis rotation matrix. * * This is composed of 5 matrices, Rz, Ry, T, Ry', Rz', multiplied * like so: Rz * Ry * T * Ry' * Rz'. T is the final rotation * (which is about the X-axis), and the two composite transforms * Ry' * Rz' and Rz * Ry are (respectively) the rotations necessary * from the arbitrary axis to the X-axis then back. They are * all elementary rotations. * * Rz' is a rotation about the Z-axis, to bring the axis vector * into the x-z plane. Then Ry' is applied, rotating about the * Y-axis to bring the axis vector parallel with the X-axis. The * rotation about the X-axis is then performed. Ry and Rz are * simply the respective inverse transforms to bring the arbitrary * axis back to its original orientation. The first transforms * Rz' and Ry' are considered inverses, since the data from the * arbitrary axis gives you info on how to get to it, not how * to get away from it, and an inverse must be applied. * * The basic calculation used is to recognize that the arbitrary * axis vector (x, y, z), since it is of unit length, actually * represents the sines and cosines of the angles to rotate the * X-axis to the same orientation, with theta being the angle about * Z and phi the angle about Y (in the order described above) * as follows: * * cos ( theta ) = x / sqrt ( 1 - z^2 ) * sin ( theta ) = y / sqrt ( 1 - z^2 ) * * cos ( phi ) = sqrt ( 1 - z^2 ) * sin ( phi ) = z * * Note that cos ( phi ) can further be inserted to the above * formulas: * * cos ( theta ) = x / cos ( phi ) * sin ( theta ) = y / sin ( phi ) * * ...etc. Because of those relations and the standard trigonometric * relations, it is pssible to reduce the transforms down to what * is used below. It may be that any primary axis chosen will give the * same results (modulo a sign convention) using thie method. * * Particularly nice is to notice that all divisions that might * have caused trouble when parallel to certain planes or * axis go away with care paid to reducing the expressions. * After checking, it does perform correctly under all cases, since * in all the cases of division where the denominator would have * been zero, the numerator would have been zero as well, giving * the expected result. */ xx = x * x; yy = y * y; zz = z * z; xy = x * y; yz = y * z; zx = z * x; xs = x * s; ys = y * s; zs = z * s; one_c = 1.0F - c; /* We already hold the identity-matrix so we can skip some statements */ M(0,0) = (one_c * xx) + c; M(0,1) = (one_c * xy) - zs; M(0,2) = (one_c * zx) + ys; /* M(0,3) = 0.0F; */ M(1,0) = (one_c * xy) + zs; M(1,1) = (one_c * yy) + c; M(1,2) = (one_c * yz) - xs; /* M(1,3) = 0.0F; */ M(2,0) = (one_c * zx) - ys; M(2,1) = (one_c * yz) + xs; M(2,2) = (one_c * zz) + c; /* M(2,3) = 0.0F; */ /* M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = 0.0F; M(3,3) = 1.0F; */ } #undef M matrix_multf( mat, m, MAT_FLAG_ROTATION ); }