bool FragCatalogEntry::match(const FragCatalogEntry *other, double tol) const { PRECONDITION(other, "bad fragment to compare"); // std::cerr << " MATCH: "<<d_order<<" " << other->getOrder()<<std::endl; if (d_order != other->getOrder()) { return false; } // now check if both the entries have the same number of functional groups const INT_INT_VECT_MAP &oFgpMap = other->getFuncGroupMap(); // std::cerr << " "<<oFgpMap.size() <<" " <<d_aToFmap.size()<<std::endl; if (oFgpMap.size() != d_aToFmap.size()) { return false; } // now check if the IDs are the same INT_INT_VECT_MAP_CI tfi, ofi; for (tfi = d_aToFmap.begin(); tfi != d_aToFmap.end(); tfi++) { bool found = false; // std::cerr << " "<< (tfi->second[0]) << ":"; for (ofi = oFgpMap.begin(); ofi != oFgpMap.end(); ofi++) { // std::cerr << " "<< (ofi->second[0]); if (tfi->second == ofi->second) { found = true; break; } } // std::cerr<<std::endl; if (!found) { return false; } } // FIX: if might be better if we just do the balaban first and then // move onto eigen values Subgraphs::DiscrimTuple tdiscs, odiscs; odiscs = other->getDiscrims(); // double x1 = boost::tuples::get<0>(odiscs); // std::cout << x1 << "\n"; tdiscs = this->getDiscrims(); #if 0 std::cout << "DISCRIMS: " << d_descrip << " "; std::cout << tdiscs.get<0>() << " " << tdiscs.get<1>() << " " << tdiscs.get<2>(); std::cout << " -- "<<odiscs.get<0>() << " " << odiscs.get<1>() << " " << odiscs.get<2>(); std::cout << std::endl; #endif // REVIEW: need an overload of feq that handles tuples in MolOps, or wherever // DiscrimTuple is defined if (!(feq(boost::tuples::get<0>(tdiscs), boost::tuples::get<0>(odiscs), tol)) || !(feq(boost::tuples::get<1>(tdiscs), boost::tuples::get<1>(odiscs), tol)) || !(feq(boost::tuples::get<2>(tdiscs), boost::tuples::get<2>(odiscs), tol))) { return false; } // FIX: this may not be enough // we may have to do teh actual isomorphism mapping return true; }
int main(){ std::vector<double> const array1{ 1.2, 2.0, 2.5, 4.0, 3.0, 6.0, 5.5, 6.3, 7.1, 5.4 }; std::vector<double> const array2{ 3.4, 3.3, 3.0, 5.5, 1.2, 2.4, 3.2, 3.1, 2.9, 3.2 }; { double const covarianceValue = covariance<double>( array1, array2 ); assert(feq(covarianceValue, -0.108889)); } { double const covarianceValue = gsl_stats_covariance( &array1.front(), 1, &array2.front(), 1, array2.size() ); assert(feq(covarianceValue, -0.108889)); } }
int main(int argc, char **argv) { char *buf, *eq, *p; if ( argc < 2 ) { fprintf(stderr,"Need string argument\n"); exit(1); } buf = strdup(argv[1]); printf("%s\n",buf); for ( p = buf; (eq=feq(p)); ) { while ( p != eq ) { printf("."); p++; } printf("^"); p++; } printf("\n"); for (p=buf; p=fnam(p); p++ ) { printf("Found %s\n",p); if ( ! (p = feq(p)) ) break; } cmdlinePairExtract(buf,ptenv,1); printf("Line now '%s'\n", buf); }
//vec.h void test_vec(void) { SECTION_BEGIN("Vector Math"); //htof TEST_BEGIN("Half-To-Float"); assert(feq(htof(32767), 1.0f)); assert(feq(htof(-32768), -1.0f)); assert(feq(htof(0), 0.0f)); TEST_END("Half-To-Float"); //uhtof TEST_BEGIN("Unsigned-Half-To-Float"); assert(feq(uhtof(0), 0.0f)); assert(feq(uhtof(65535), 1.0f)); TEST_END("Unsigned-Half-To-Float"); //vector average TEST_BEGIN("Averaging"); vec3 a = {1,2,3}; vec3 b = {2,3,4}; vec3 c = {1.4f, 1.4f, 1.4f}; vec3 d = {0,0,0}; vec3 res; vec3 tot = {1.1f, 1.6f, 2.1f}; vec3_avg(res, 4, a, b, c, d); assert(vec3_eq(res, tot)); TEST_END("Averaging"); SECTION_END("Vector Math\n"); }
double RD28Builder::integral(const Boundary& boundary) { CHECK( feq(boundary.l(0), 2.0) && feq(boundary.u(0), 1.0) && boundary.l(1) == -inf && feq(boundary.u(1), -1.0), "Unsupported boundary."); return -1.0; }
void initializeFluid(int Lz, int Ly, int Lx, double ****R, double ****B){ int x, y, z, k; double ux,uy,uz; for(z = 0; z < Lz; z++) { for(y = 0; y < Ly; y++) { for(x = 0; x < Lx; x++) { Solid[z][y][x] = 1; if(y < Ly - 1 && y > 0 && z < Lz - 1 && z > 0) { Solid[z][y][x] = 0; } } } } // According to bubble in the middle of a tube for(z = 0; z < Lz; z++) { for(y = 0; y < Ly; y++) { for(x = 0; x < Lx; x++) { if(Solid[z][y][x] != b) { if(x < Lx/4 || x > 3*Lx/4) { ux=0.0; uy=0.0; uz=0.0; for(k = 0; k < b; k++) { B[z][y][x][k] = feq(RHO,z,y,x,k,ux,uy,uz); R[z][y][x][k] = 0.0; } } else{ ux=0.0; uy=0.0; uz=0.0; for(k = 0; k < b; k++) { R[z][y][x][k]= feq(RHO,z,y,x,k,ux,uy,uz); B[z][y][x][k] = 0.0; } } } } } } }//end initializeFluid()_________________________________________________
double G6Builder::integral(const Boundary& boundary) { CHECK( feq0(boundary.l(0)) && feq(boundary.u(0), 1.0) && feq0(boundary.l(1)) && feq(boundary.u(1), 1.0), InvalidValueError("Only unit square solution available.")); return ( exp(dC[0] * dx0[0]) - 1 ) / dC[0] * ( exp(dC[1] * dx0[1]) - 1 ) / dC[1]; }
uint8_t positioning_from_angles( float alpha, float beta, float gamma, const reference_triangle_t * t, position_t * output) { // output is not valid if input is not valid if (output == NULL || t == NULL || !feq(alpha + beta + gamma, 2 * M_PI)) { return 0; } uint8_t is_valid = 1; // test for possible division by zero (or very small number) // and mark result as invalid (but compute it anyway!) float cot_alpha = cot(alpha); float cot_beta = cot(beta); float cot_gamma = cot(gamma); if ( feq(cot_alpha, t->cotangent_at_a) || feq(cot_beta, t->cotangent_at_b) || feq(cot_gamma, t->cotangent_at_c)) { is_valid = 0; } // compute barycentric coordinates from angles float barycentric_a = 1.0f / (t->cotangent_at_a - cot_alpha); float barycentric_b = 1.0f / (t->cotangent_at_b - cot_beta); float barycentric_c = 1.0f / (t->cotangent_at_c - cot_gamma); // normalize barycentric coordinates float magnitude = barycentric_a + barycentric_b + barycentric_c; barycentric_a /= magnitude; barycentric_b /= magnitude; barycentric_c /= magnitude; // convert to cartesian coordinates float x = barycentric_a * t->point_a->x + barycentric_b * t->point_b->x + barycentric_c * t->point_c->x; float y = barycentric_a * t->point_a->y + barycentric_b * t->point_b->y + barycentric_c * t->point_c->y; position_t pos = {x, y}; // copy result to output memcpy(output, &pos, sizeof(position_t)); return is_valid; }
/* returns 1 for concordance, -1 for discordance, and 0 for equality */ int concordant_pair(double x1, double x2, double y1, double y2) { /* check for equality */ if (feq(x1, x2) || feq(y1, y2)) { return 0; } if ((x1 > x2 && y1 > y2) || (x1 < x2 && y1 < y2)) { return 1; } /* if not equal and not concordant, must be discordant */ return -1; }
void CPlayer::GroundClampTerrain() { DASSERT(m_pTerrain); WorldPosition pos = m_transform.GetTranslation(); pos.y = 0.0f; if(feq(pos.x, m_vecLastPos.x) && feq(pos.z, m_vecLastPos.z)) return; CTerrainPatch *patch = m_pTerrain->GetTerrainByLocation(pos); if(patch) pos.y = patch->GetTerrainHeightAtXZ(pos.x, pos.z); m_transform.SetTranslation(pos); }
// Indices of the vertices returned by the above function int OBB::GetSupportIndices(vec2 n, std::array<int, 2>& sV) const { // Find the furthest vertex float dMin = -FLT_MAX; for (int i = 0; i < 4; i++) { vec2 v = GetVert(i); float d = glm::dot(n, v); if (d > dMin) { dMin = d; sV[0] = i; } } int num(1); // If there's a different vertex for (int i = 0; i < 4; i++) { if (i == sV[0]) continue; vec2 v = GetVert(i); float d = glm::dot(n, v); // That's pretty close... if (feq(d, dMin, 100.f * kEPS)) { // Take it too dMin = d; sV[num++] = i; } } return num; }
void test (void) { int i, j, *res = correct_results; for (i = 0; i < 8; i++) { float arg0 = args[i]; for (j = 0; j < 8; j++) { float arg1 = args[j]; if (feq (arg0, arg1) != *res++) abort (); if (fne (arg0, arg1) != *res++) abort (); if (flt (arg0, arg1) != *res++) abort (); if (fge (arg0, arg1) != *res++) abort (); if (fgt (arg0, arg1) != *res++) abort (); if (fle (arg0, arg1) != *res++) abort (); } } }
/* implement the 'c' category average command */ void do_catavg(csv_t *D, int cat, int col) { double category_values [MAXCATS], sum; int i, j, n_cats, n_values; /* fix column numbers to match array indexing */ int array_col = col-1; int array_cat = cat-1; /* copy values of category column into category array */ for (i=0; i<D->nrows; i++) { category_values[i] = D->vals[i][array_cat]; } /* sort category array into ascending distinct values */ n_cats = sort_distinct_values(category_values, D->nrows); /* search through value by value in val array */ printf("%8s average %s\n", D->labs[array_cat], D->labs[array_col]); for(i=0; i<n_cats; i++) { sum = 0; n_values = 0; for (j=0; j<D->nrows; j++) { if(feq(D->vals[j][array_cat], category_values[i])) { /* for each category match, add to sum */ sum += D->vals[j][array_col]; n_values ++; } } /* for each category, print average and increase to next cat */ printf("%8.2f %8.2f (over %d values)\n", category_values[i], (sum/n_values), n_values); } return; }
void gen_test (void) { union uint32_f a, b; bool c; for (int i = 0; i < 2000000 ; i++) { char aa[33],bb[33],cc[2]; a.i = rand () | rand () << 16; b.i = rand () | rand () << 16; if (fpclassify (a.f) != FP_NORMAL || fpclassify (b.f) != FP_NORMAL) continue; c = feq (a.i,b.i); for (int t = 0; t < 32;++t) { aa[31 - t] = a.i & (1 << t) ? '1' : '0'; bb[31 - t] = b.i & (1 << t) ? '1' : '0'; } aa[32] = '\0'; bb[32] = '\0'; cc[0] = c ? '1' : '0'; cc[1] = '\0'; // 非正規化数とかはやらない if (isnormal (a.f) && isnormal((b.f))) { printf ("%s\t%s\t%s\n",aa,bb,cc); } } }
uint8_t positioning_reference_triangle_from_points( const position_t * a, const position_t * b, const position_t * c, reference_triangle_t * output) { // verify input if (output == NULL || a == NULL || b == NULL || c == NULL) { return 0; } // test if a,b,c are not positively oriented or colinear float orient = orientation(a, b, c); if (orient < 0.0f || feq(orient, 0.0f)) { return 0; } // compute cotangents of angle inside triangle at every point float cot_at_a = cotangent_from_points(b, a, c); float cot_at_b = cotangent_from_points(a, b, c); float cot_at_c = cotangent_from_points(b, c, a); reference_triangle_t t = {a, b, c, cot_at_a, cot_at_b, cot_at_c}; // copy result to output memcpy(output, &t, sizeof(reference_triangle_t)); // success return 1; }
// Pick the best feature pair (penetrating or separating); A is the "face" object, B is the "vertex" object // Penetrating is a bit of a grey area atm static void featurePairJudgement(FeaturePair& mS, FeaturePair& mP, OBB * A, OBB * B, FeaturePair::Type type) { // For all A's normals for (int fIdx = 0; fIdx < 4; fIdx++) { vec2 n = A->GetNormal(fIdx); vec2 p1 = A->GetVert(fIdx); vec2 p2 = A->GetVert((fIdx + 1) % 4); // For B's support verts relative to the normal std::array<int, 2> supportVerts = { { -1, -1 } }; int nVerts = B->GetSupportIndices(-n, supportVerts); for (int s = 0; s < nVerts; s++) { int sIdx = supportVerts[s]; vec2 sV = B->GetVert(sIdx); // minkowski face points vec2 mfp0 = sV - p1; vec2 mfp1 = sV - p2; // Find point on minkowski face vec2 p = projectOnEdge(vec2(), mfp0, mfp1); // are objects penetrating? // i.e is first mf point behind face normal // penetration implies support vert behind normal float dist = glm::dot(mfp0, n); float c_dist = glm::length(sV - A->C); bool isPenetrating = dist < 0.f; // fp points to the correct feature pair FeaturePair * fp(nullptr); if (isPenetrating) fp = &mP; else { fp = &mS; // Separation dist is the length from p to the origin dist = glm::length(p); } // See whether or not this new feature pair is a good candidate // For penetration, we want the largest negative value bool accept = false; if (isPenetrating ? (dist > fp->dist) : (dist < fp->dist)) accept = true; else if (feq(dist, fp->dist)) { // If it's just about as close as the current best feature pair, // pick the one whose distance is closest to the center of the face object if (c_dist < fp->c_dist) accept = true; } // Reassign *fp as needed if (accept) *fp = FeaturePair(dist, c_dist, fIdx, sIdx, type); } } }
void TransformSequence::optimize() { if (m_size > 1) { for (size_t i = 0; i < m_size; ++i) { const bool same_left = i == 0 || feq(m_keys[i - 1].m_transform, m_keys[i].m_transform); const bool same_right = i == m_size - 1 || feq(m_keys[i + 1].m_transform, m_keys[i].m_transform); if (same_left && same_right) { memmove(&m_keys[i], &m_keys[i + 1], (m_size - 1 - i) * sizeof(TransformKey)); --m_size; } } } }
bool math_vector::operator==(const math_vector & rhs) const { if( this->num_elements() != rhs.num_elements()) return false; bool areEqual = true; for( int i = 0; i < m_values.size(); i++) { if (!feq(this->getValue(i), rhs.getValue(i)) ) { areEqual = false; break; } } return areEqual; }
enum overlap overlap (ftype_t r1a, ftype_t r1b, ftype_t r2a, ftype_t r2b) { if (r1a > r1b) swap (r1a, r1b); if (r2a > r2b) swap (r2a, r2b); if (r2a < r1a) { swap (r1a, r2a); swap (r1b, r2b); } if (feq (r1b, r2a)) return OVERLAP_POINT; if (r1b < r2a) return OVERLAP_NONE; return OVERLAP_MANY; }
void bot_quat_to_angle_axis (const double q[4], double *theta, double axis[3]) { double halftheta = acos (q[0]); *theta = halftheta * 2; double sinhalftheta = sin (halftheta); if (feq (halftheta, 0)) { axis[0] = 0; axis[1] = 0; axis[2] = 1; *theta = 0; } else { axis[0] = q[1] / sinhalftheta; axis[1] = q[2] / sinhalftheta; axis[2] = q[3] / sinhalftheta; } }
/* * Load internal state from archive. */ void Distribution::loadParameters(Serializable::IArchive &ar) { loadParameter<double>(ar, "min", min_); loadParameter<double>(ar, "max", max_); loadParameter<int>(ar, "nBin", nBin_); ar & nSample_; ar & nReject_; ar & binWidth_; ar & histogram_; // Validate if (histogram_.capacity() != nBin_) { UTIL_THROW("Inconsistent histogram capacity"); } if (!feq(binWidth_, (max_ - min_)/double(nBin_))) { UTIL_THROW("Inconsistent binWidth_"); } }
bool are_images_feq( const Image& image1, const Image& image2, const float eps) { const CanvasProperties& image1_props = image1.properties(); const size_t width = image1_props.m_canvas_width; const size_t height = image1_props.m_canvas_height; const size_t channel_count = image1_props.m_channel_count; if (image2.properties().m_canvas_width != width || image2.properties().m_canvas_height != height || image2.properties().m_channel_count != channel_count) return false; assert(channel_count <= 4); size_t differing_pixels = 0; for (size_t y = 0; y < height; ++y) { for (size_t x = 0; x < width; ++x) { float color1[4]; image1.get_pixel(x, y, color1); float color2[4]; image2.get_pixel(x, y, color2); for (size_t c = 0; c < channel_count; ++c) { if (!feq(color1[c], color2[c], eps)) { ++differing_pixels; break; } } } } return differing_pixels == 0; }
/* * Lbm implementation methods */ void collide(FlowState * f_state, LbmState * lbm_state) { unsigned int i, k; unsigned int nodes = lbm_state->lx * lbm_state->ly; double omega = 1.0 / f_state->tau, gx0, gy0, ux0, uy0, rho0; #pragma omp for private(i, k, gx0, gy0, ux0, uy0, rho0) for(i = 0; i < nodes; ++i) { gx0 = f_state->force[0][i]; gy0 = f_state->force[1][i]; rho0 = f_state->rho[i]; ux0 = f_state->u[0][i]; uy0 = f_state->u[1][i]; for(k = 0; k < Q; ++k) lbm_state->f[k][i] = lbm_state->f[k][i] - omega * (lbm_state->f[k][i] - feq(k, rho0, ux0, uy0)) + 3.0 * weight[k] * (cx[k]*gx0 + cy[k]*gy0); } }
smp_t pul(smp_t w, smp_t shape) { //remove all multiples of 2PI: int m = (int)(floor(w/M_2PI)); smp_t arg = w - M_2PI*m; if(arg<0)arg = M_2PI+arg; DASSERT(arg>=0 && arg<=M_2PI); smp_t sp = shape*M_2PI; if(feq(arg,sp, (smp_t)0.00001) || arg < sp) { return 1.0; } else { return 0; } }
void lbm_init_state(FlowState * f_state, LbmState * lbm_state) { unsigned int i, j, k, idx; double ux0, uy0, rho0; /* Initialize the distributions */ for(i = 0; i < f_state->lx; ++i) { for(j = 0; j < f_state->ly; ++j) { idx = i*f_state->ly + j; ux0 = f_state->u[0][idx]; uy0 = f_state->u[1][idx]; rho0 = f_state->rho[idx]; for(k = 0; k < Q; ++k) { lbm_state->f[k][idx] = feq(k, rho0, ux0, uy0); lbm_state->f_next[k][idx] = lbm_state->f[k][idx]; } } } }
void IIRFilter::setCoeff(smp_t* XC, smp_t* YC) { //pre divide by YC[0] so that output can be written as the sum 2) DASSERT( !feq(YC[0], (smp_t)0.0) ); for(int i=0;i<num_x;i++) { Xcoeff[i]=XC[i]/YC[0]; DASSERT(!isnan(Xcoeff[i])); //cout << "x" << i << " " << Xcoeff[i] << endl; } for(int i=0;i<num_y;i++) { Ycoeff[i]=YC[i]/YC[0]; DASSERT(!isnan(Ycoeff[i])); //cout << "y" << i << " " << Ycoeff[i] << endl; } }
void bot_quat_to_rodrigues(const double q[4], double r[3]) { double halftheta = acos (q[0]); double theta = halftheta * 2; double sinhalftheta = sin (halftheta); if (feq (halftheta, 0)) { r[0] = 0; r[1] = 0; r[2] = 0; } else { r[0] = q[1] / sinhalftheta; r[1] = q[2] / sinhalftheta; r[2] = q[3] / sinhalftheta; //normalize and scale by theta double rmag = sqrt(r[0]*r[0] + r[1]*r[1] + r[2]*r[2]); r[0] *=theta/rmag; r[1] *=theta/rmag; r[2] *=theta/rmag; } }
static uint8_t m_inv(const matrix2d_t * m1, matrix2d_t * dest) { float det = m1->_a * m1->_d - m1->_b * m1->_c; if(feq(det, 0.0f)) { return 0; } det = 1 / det; float n_a = det * m1->_d; float n_b = det * m1->_b; float n_c = det * m1->_c; float n_d = det * m1->_a; dest->_a = n_a; dest->_b = - n_b; dest->_c = - n_c; dest->_d = n_d; return 1; }
static char *fnam(char *str) { char *eq, *e, *b; if ( !(eq=feq(str)) ) return 0; /* skip white space */ e = eq; do { if ( --e <= str ) return 0; } while ( ' '==*e ); /* e points to last char of name */ for ( b = e; ' '!= *b && '\'' !=*b && b>=str; b-- ) ; if ( ++b > e ) return 0; /* eliminate white space */ if ( eq > e+1 ) memmove(e+1, eq, strlen(eq)+1); return b; }
/* * Check consistency of data. */ bool OrthorhombicBoundary::isValid() { double dot; double twoPi = 2.0*Constants::Pi; int i, j; OrthoRegion::isValid(); for (i = 0; i < Dimension; ++i) { if (!feq(minima_[i], 0.0)) { UTIL_THROW("minima_[i] != 0"); } if (!feq(lengths_[i]*invLengths_[i], 1.0)) { UTIL_THROW("invLengths_[i]*lengths_[i] != 1.0"); } if (!feq(lengths_[i], bravaisBasisVectors_[i][i])) { UTIL_THROW("bravaisBasisVectors_[i][i] != lengths_[i]"); } for (j = 0; j < Dimension; ++j) { dot = bravaisBasisVectors_[i].dot(reciprocalBasisVectors_[j]); if (i == j) { if (!feq(dot, twoPi)) { UTIL_THROW("a[i].b[i] != twoPi"); } } else { if (!feq(dot, 0.0)) { UTIL_THROW("a[i].b[j] != 0 for i != j"); } if (!feq(bravaisBasisVectors_[i][j], 0.0)) { UTIL_THROW("Nonzero off-diagonal element of bravaisBasisVectors_"); } if (!feq(reciprocalBasisVectors_[i][j], 0.0)) { UTIL_THROW("Nonzero off-diagonal element of reciprocalBasisVectors_"); } } } } return true; }