int Tuple::Compare(const Tuple &other) const { const int column_count = tuple_schema->GetColumnCount(); for (int column_itr = 0; column_itr < column_count; column_itr++) { std::unique_ptr<common::Value> lhs(GetValue(column_itr)); std::unique_ptr<common::Value> rhs(other.GetValue(column_itr)); std::unique_ptr<common::Value> res_gt(lhs->CompareGreaterThan(*rhs)); if (res_gt->IsTrue()) { return 1; } std::unique_ptr<common::Value> res_lt(lhs->CompareLessThan(*rhs)); if (res_lt->IsTrue()) { return -1; } } return 0; }
void CloningVisitor::visitOrBranch(const Or &expr) { int priority = OrPriority; expr.getLeft().visit(*this); bool lhsConstVal = _constVal; ResultSet lhsSet(_resultSet); setNodeParentheses(priority); std::unique_ptr<Node> lhs(std::move(_node)); revisit(); expr.getRight().visit(*this); _constVal &= lhsConstVal; _resultSet.calcOr(lhsSet); setNodeParentheses(priority); std::unique_ptr<Node> rhs(std::move(_node)); _priority = priority; _node.reset(new Or(std::move(lhs), std::move(rhs), "or")); };
void MatrixWrapperTest::testEqualityWrongEntry() { MatrixImpl lhs(3, 2, Matrix::INT_32); MatrixImpl rhs(3, 2, Matrix::INT_32); for (unsigned int i = 0; i < 3; ++i) { for (unsigned int j = 0; j < 2; ++j) { lhs.at<int32_t>(i, j) = i + j; rhs.at<int32_t>(i, j) = i + j; } } rhs.at<int32_t>(1, 1) = 0; CPPUNIT_ASSERT(! (lhs == rhs)); }
T mergeSort(T &tmp) { if (tmp.size() == 1) { return tmp; } typename T::iterator mediana = tmp.begin(); std::advance(mediana, tmp.size() / 2); T lhs(tmp.begin(), mediana); T rhs(mediana, tmp.end()); lhs = mergeSort(lhs); rhs = mergeSort(rhs); return merge(lhs, rhs); }
int main(int argc, char** argv) { IloEnv env; try { IloModel m(env); IloCplex cplex(env); IloObjective obj; IloNumVarArray var(env); IloRangeArray con(env); const char* datadir = (argc >= 2) ? argv[1] : "../../../examples/data"; char *fname = new char[strlen(datadir) + 1 + strlen("noswot.mps") + 1]; sprintf(fname, "%s/noswot.mps", datadir); env.out() << "reading " << fname << endl; cplex.importModel(m, fname, obj, var, con); delete[] fname; env.out() << "constructing cut callback ..." << endl; IloExprArray lhs(env); IloNumArray rhs(env); makeCuts(var, lhs, rhs); cplex.use(CtCallback(env, lhs, rhs, cplex.getParam( IloCplex::Param::Simplex::Tolerances::Feasibility))); env.out() << "extracting model ..." << endl; cplex.extract(m); cplex.setParam(IloCplex::Param::MIP::Interval, 1000); cplex.setParam(IloCplex::Param::MIP::Strategy::Search, IloCplex::Traditional); env.out() << "solving model ...\n"; cplex.solve(); env.out() << "solution status is " << cplex.getStatus() << endl; env.out() << "solution value is " << cplex.getObjValue() << endl; } catch (IloException& ex) { cerr << "Error: " << ex << endl; } env.end(); return 0; }
int main() { holder lhs( "lhs", "a", "b", "c" ) ; const holder rhs( "rhs", "dd", "eee", "ffff" ) ; std::cout << "value of members before assignment: " << lhs.one.value << ',' << lhs.two.value << ',' << lhs.three.value << "\n\n" ; // value of members before assignment: a,b,c // assign rhs to lha using the implicitly declared assignment operator lhs = rhs ; // this performs member-wise assignment // ie. assign members of rhs to the corresponding members in lhs // in the order of declaration of the members // 1. lhs.one = rhs.one // 2. lhs.two = rhs.two // 3. lhs.three = rhs.three std::cout << "\nvalue of members after assignment: " << lhs.one.value << ',' << lhs.two.value << ',' << lhs.three.value << '\n' ; // value of members after assignment: dd,eee,ffff }
int Cvode::solvex_thread_part1(double* b, NrnThread* nt){ //printf("Cvode::solvex_thread %d t=%g t_=%g\n", nt->id, nt->t, t_); //printf("Cvode::solvex_thread %d %g\n", nt->id, gam()); //printf("\tenter b\n"); //for (int i=0; i < neq_; ++i) { printf("\t\t%d %g\n", i, b[i]);} int i; CvodeThreadData& z = ctd_[nt->id]; nt->cj = 1./gam(); nt->_dt = gam(); if (z.nvsize_ == 0) { return 0; } lhs(nt); // special version for cvode. scatter_ydot(b, nt->id); nrn_mul_capacity(nt, z.cmlcap_->ml); for (i=0; i < z.no_cap_count_; ++i) { NODERHS(z.no_cap_node_[i]) = 0.; } // solve it nrn_multisplit_triang(nt); return 0; }
void CloningVisitor::visitComparison(const Compare &expr) { int priority = ComparePriority; expr.getLeft().visit(*this); bool lhsConstVal = _constVal; setValueNodeParentheses(priority); std::unique_ptr<ValueNode> lhs(std::move(_valueNode)); revisit(); expr.getRight().visit(*this); _constVal &= lhsConstVal; setValueNodeParentheses(priority); std::unique_ptr<ValueNode> rhs(std::move(_valueNode)); const Operator &op(expr.getOperator()); _priority = priority; _resultSet.fill(); // should be less if const _node.reset(new Compare(std::move(lhs), op, std::move(rhs), expr.getBucketIdFactory())); };
int Cvode::solvex_thread(double* b, double* y, NrnThread* nt){ //printf("Cvode::solvex_thread %d t=%g t_=%g\n", nt->id, nt->t, t_); //printf("Cvode::solvex_thread %d %g\n", nt->id, gam()); //printf("\tenter b\n"); //for (int i=0; i < neq_; ++i) { printf("\t\t%d %g\n", i, b[i]);} int i; CvodeThreadData& z = CTD(nt->id); nt->cj = 1./gam(); nt->_dt = gam(); if (z.nvsize_ == 0) { return 0; } lhs(nt); // special version for cvode. scatter_ydot(b, nt->id); nrn_mul_capacity(nt, z.cmlcap_->ml); for (i=0; i < z.no_cap_count_; ++i) { NODERHS(z.no_cap_node_[i]) = 0.; } // solve it #if PARANEURON if (nrn_multisplit_solve_) { (*nrn_multisplit_solve_)(); }else #endif { triang(nt); bksub(nt); } //for (i=0; i < v_node_count; ++i) { // printf("%d rhs %d %g t=%g\n", nrnmpi_myid, i, VEC_RHS(i), t); //} if (ncv_->stiff() == 2) { solvemem(nt); }else{ // bug here should multiply by gam } gather_ydot(b, nt->id); //printf("\texit b\n"); //for (i=0; i < neq_; ++i) { printf("\t\t%d %g\n", i, b[i]);} return 0; }
std::string process_impl(BinaryExpr const & e, bool use_parenthesis, rt_latex_translator<InterfaceType> const & translator) const { std::stringstream ss; viennamath::rt_expr<InterfaceType> lhs(e.lhs()->clone()); viennamath::rt_expr<InterfaceType> rhs(e.rhs()->clone()); if (dynamic_cast< const op_binary<op_div<NumericType>, InterfaceType> * >(e.op()) != NULL) //division -> \frac{}{} { if (use_parenthesis) ss << " \\left( "; ss << " \\frac{" << translator(lhs) << "}{" << translator(rhs) << "} "; if (use_parenthesis) ss << " \\right) "; } else { bool is_op_mult = false; if (dynamic_cast< const op_binary<op_mult<NumericType>, InterfaceType> * >(e.op()) != NULL) is_op_mult = true; bool is_op_minus = false; if (dynamic_cast< const op_binary<op_minus<NumericType>, InterfaceType> * >(e.op()) != NULL) is_op_minus = true; if (use_parenthesis) ss << "("; ss << translator(lhs, is_op_mult); if (is_op_mult) ss << " \\cdot "; else ss << " " << e.op()->str() << " "; ss << translator(rhs, is_op_mult || is_op_minus); if (use_parenthesis) ss << ")"; } return ss.str(); }
void EBPoissonOp:: getInvDiagRHS(LevelData<EBCellFAB>& a_lhs, const LevelData<EBCellFAB>& a_rhs) { //this function computes: a_lhs = (1/diagonal)*a_rhs // use this to initialize the preconditioner Real mult = m_alpha; for (int idir = 0; idir < SpaceDim; idir++) { mult += -2.0 * m_beta * m_invDx2[idir]; } mult = 1.0 / mult; //do all cells (assuming mult works for every cell) assign(a_lhs,a_rhs); scale(a_lhs, mult); //now do/fix the irreg cells for (DataIterator dit = m_eblg.getDBL().dataIterator(); dit.ok(); ++dit) { EBCellFAB& lhs = a_lhs[dit()]; const EBCellFAB& rhs = a_rhs[dit()]; const BaseIVFAB<Real>& curAlphaWeight = m_alphaDiagWeight[dit()]; const BaseIVFAB<Real>& curBetaWeight = m_betaDiagWeight[dit()]; VoFIterator& vofit = m_vofItIrreg[dit()]; for (vofit.reset(); vofit.ok(); ++vofit) { const VolIndex& VoF = vofit(); Real weightIrreg = m_alpha*curAlphaWeight(VoF,0) + m_beta*curBetaWeight(VoF,0); for (int comp = 0; comp < lhs.nComp(); comp++) { lhs(VoF,comp) = (1.0/weightIrreg)*rhs(VoF,comp); } } } }
Value NumericOp::evaluate() const { Value lhs(subExpr(0)->evaluate()); Value rhs(subExpr(1)->evaluate()); double leftVal = lhs.toNumber(); double rightVal = rhs.toNumber(); switch (m_opcode) { case OP_Add: return leftVal + rightVal; case OP_Sub: return leftVal - rightVal; case OP_Mul: return leftVal * rightVal; case OP_Div: return leftVal / rightVal; case OP_Mod: return fmod(leftVal, rightVal); } ASSERT_NOT_REACHED(); return 0.0; }
int Edge:: ccInd() { const Term* trm = lhs(); int tint = trm->toInt(); ECString tNm = trm->name(); bool sawComma = false; bool sawColen = false; bool sawCC = false; int numTrm = 0; Item* itm; LeftRightGotIter gi(this); int pos = 0; /*Change next line to indicate which non-terminals get specially marked to indicate that they are conjoined together */ if(tNm != "NP" && tNm != "S" && tNm != "VP") return tint; while( gi.next(itm) ) { const Term* subtrm = itm->term(); if(subtrm == Term::stopTerm) continue; if(subtrm == trm) numTrm++; const ECString& nm = subtrm->name(); //Change next two lines depending on possible conjunction parts of speech ECString CCInd[2] = {"CC", "CONJP"}; if(pos != 0 && (nm == CCInd[0] || nm == CCInd[1])) sawCC = true; if(pos != 0 && (nm == ",")) sawComma = true; if(pos != 0 && nm == ":") sawColen = true; //else if(!trm->isPunc()) return tint; pos++; } if(trm->name() == "NP" && numTrm == 2 && !sawCC) return Term::lastNTInt()+1; if((sawComma || sawColen || sawCC) && numTrm >= 2) return tint+Term::lastNTInt(); //if(trm->name() == "NP" && numTrm == 2 && !sawCC) return 78; //if((sawComma || sawColen || sawCC) && numTrm >= 2) return tint+80; return tint; }
static void exit_predictions(PRED_AT what) { int i; if (gl_nsim > 1 && gl_lhs) lhs(get_gstat_data(), get_n_vars(), get_mode() == STRATIFY); switch (what) { case AT_POINTS: write_points(NULL, NULL, NULL, NULL, 0); if (gl_nsim > 1) save_simulations_to_ascii(o_filename); break; case AT_GRIDMAP: if (gl_nsim > 1) { if (DEBUG_DUMP) printlog("\nWriting results to files..."); save_simulations_to_maps(masks[0]); if (DEBUG_DUMP) printlog("done"); } else { for (i = 0; i < get_n_outfile(); i++) { if (get_outfile_namei(i)) { map_sign(outmap[i], what_is_outfile(i)); (outmap[i])->write(outmap[i]); map_free(outmap[i]); } } } for (i = 0; i < get_n_masks(); i++) map_free(masks[i]); efree(masks); efree(outmap); break; } print_orvc(); efree(est); } /* exit_predictions() */
vanilla::object::ptr vanilla::int_object::ge(object::ptr const& other) { switch(other->type_id()) { case OBJECT_ID_INT: { int_object const* rhs = static_cast<int_object const*>(other.get()); int result = mpz_cmp(_v.mpz(), rhs->value().mpz()); return allocate_object<bool_object>(result >= 0); } case OBJECT_ID_FLOAT: { float_object::float_type lhs( (_v.mpz()) ); float_object const* rhs = static_cast<float_object const*>(other.get()); return allocate_object<bool_object>(mpf_cmp(lhs.mpf(), rhs->value().mpf()) >= 0); } default: { return object::ge(other); } } }
int main() { ////////////////////////////////////////////////////////////////////////////////////// //Test Concatenation { //---------------------------------------- //SETUP FIXTURE String lhs("abc"),rhs("def"); //TEST String result = lhs + rhs; //VERIFY assert(result == "abcdef"); } { //--------------------------------------- //SETUP FIXTURE String lhs("abcdef"),rhs("gh"); //TEST String result = lhs + rhs; //VERIFY assert(result == "abcdefgh"); } { //--------------------------------------- //SETUP FIXTURE String lhs("ab"),rhs("cdefghi"); //TEST String result = lhs + rhs; //VERIFY assert(result == "abcdefghi"); } { //--------------------------------------- //SETUP FIXTURE String lhs("abc"); //TEST String result = lhs + "defgh"; //VERIFY assert(result == "abcdefgh"); } { //--------------------------------------- //SETUP FIXTURE String rhs("def"); //TEST String result ="abc" + rhs; //VERIFY assert(result == "abcdef"); } { //--------------------------------------- //SETUP FIXTURE String lhs("abc"); //TEST String result = (lhs + 'd'); //VERIFY assert(result == "abcd"); } { //------------------------------------- //SETUP FIXTURE String rhs("bcd"); //TEST String result = 'a' + rhs; //VERIFY assert(result == "abcd"); } std::cout<<"\nDone Testing Concatenation\n"; //////////////////////////////////////////////////////////////////////////////////////// //Test Greater Operator { //----------------------------------------- //SETUP FIXTURES String lhs("bad"),rhs("abc"); //TEST //VERIFY assert(lhs>rhs); } { //---------------------------------------- //SETUP FIXTURES String lhs("z"),rhs("dfc"); //TEST //VERIFY assert(lhs>rhs); } { //---------------------------------------- //SETUP FIXTURES String lhs("abc"),rhs("abc"); //TEST //VERIFY assert(lhs>=rhs); } std::cout<<"\nDone Testing Greater than Operators.\n"; //////////////////////////////////////////////////////////////////////////////////////// //Test >> Operator std::ifstream in("test_in.txt"); if(!in) { std::cout<<"Couldn't open file. Cant test '>>' operator. Requires a file 'test_in.txt'\n" <<" Exiting"<<std::endl; return 0; } String str; while(!in.eof()) { in>>str; std::cout<<str<<std::endl; str = String(); } std::cout<<"\nDone testing '>>' operator.\n"; /////////////////////////////////////////////////////////////////////////////////////////// //Test less than Operators { //--------------------------------------------- //SETUP FIXTURE String lhs("abc"),rhs("bac"); //TEST //VERIFY assert(lhs<rhs); } { //--------------------------------------------- //SETUP FIXTURE String lhs(""),rhs("abc"); //TEST //VERIFY assert(lhs<rhs); } { //-------------------------------------------- //SETUP FIXTURE String lhs('b'),rhs("bdefcdefsdg"); //TEST //VERIFY assert(lhs<rhs); } { //------------------------------------------- //SETUP FIXTURE String lhs("acb"); //TEST //VERIFY assert("abc"<lhs); } { //------------------------------------------ //SETUP FIXTURE String lhs("acb"); //TEST //VERIFY assert('a'<lhs); } { //----------------------------------------- //SETUP FIXTURE String str("aab"); //TEST //VERIFY assert(str<'b'); } { //----------------------------------------- //SETUP FIXTURE String lhs("abc"),rhs("acb"); //TEST //VERIFY assert(lhs<=rhs); } { //---------------------------------------- //SETUP FIXTURE String lhs("abc"),rhs("abc"); //TEST //VERIFY assert(lhs<=rhs); } std::cout<<"\nDone testing Less than operators.\n"; //////////////////////////////////////////////////////////////////////////////////////////// //Test Not Equal Operator { //---------------------------------- //SETUP FIXTURE String lhs("abc"), rhs("bcd"); //Test //VERIFY assert(lhs!=rhs); } { //---------------------------------- //SETUP FIXTURE String lhs("aaab"), rhs("aaac"); //TEST //VERIFY assert(lhs!=rhs); } std::cout<<"\nDone testing '!=' Operator\n"; ///////////////////////////////////////////////////////////////////////////////////////////// }
Region& Region::operationSelf(const Region& rhs, int dx, int dy, int op) { Region lhs(*this); boolean_operation(op, *this, lhs, rhs, dx, dy); return *this; }
Region& Region::operationSelf(const Rect& r, int op) { Region lhs(*this); boolean_operation(op, *this, lhs, r); return *this; }
ModelTracker::Transform ModelTracker::softPosit(unsigned int numImagePoints,ModelTracker::ImgPoint imagePoints[],const Transform& initialTransform) { typedef Transform::Vector Vector; /* Pre-transform the image points by the image transformation: */ for(unsigned int ipi=0;ipi<numImagePoints;++ipi) imagePoints[ipi]=imgTransform.transform(imagePoints[ipi]); /* Assign initial homogeneous weights to the model points: */ for(unsigned int mpi=0;mpi<numModelPoints;++mpi) mpws[mpi]=1.0; /* Create the assignment matrix: */ Math::Matrix m(numImagePoints+1,numModelPoints+1); /* Initialize the "slack" rows and columns: */ double gamma=1.0/double(Math::max(numImagePoints,numModelPoints)+1); for(unsigned int ipi=0;ipi<numImagePoints;++ipi) m(ipi,numModelPoints)=gamma; for(unsigned int mpi=0;mpi<numModelPoints;++mpi) m(numImagePoints,mpi)=gamma; m(numImagePoints,numModelPoints)=gamma; /* Initialize the pose vectors: */ Transform::Rotation inverseOrientation=Geometry::invert(initialTransform.getRotation()); Vector r1=inverseOrientation.getDirection(0); Vector r2=inverseOrientation.getDirection(1); Vector t=initialTransform.getTranslation(); double s=-f/t[2]; /* Perform the deterministic annealing loop: */ for(double beta=0.005;beta<=0.5;beta*=1.025) { /* Create the initial assignment matrix based on squared distances between projected object points and image points: */ for(unsigned int ipi=0;ipi<numImagePoints;++ipi) for(unsigned int mpi=0;mpi<numModelPoints;++mpi) { double d2=Math::sqr((r1*modelPoints[mpi]+t[0])*s-mpws[mpi]*imagePoints[ipi][0]) +Math::sqr((r2*modelPoints[mpi]+t[1])*s-mpws[mpi]*imagePoints[ipi][1]); m(ipi,mpi)=Math::exp(-beta*(d2-maxMatchDist2)); // DEBUGGING // std::cout<<' '<<d2; } // DEBUGGING // std::cout<<std::endl; /* Normalize the assignment matrix using Sinkhorn's method: */ double rowMaxDelta,colMaxDelta; do { /* Normalize image point rows: */ rowMaxDelta=0.0; for(unsigned int ipi=0;ipi<numImagePoints;++ipi) { /* Calculate the row sum: */ double rowSum=0.0; for(unsigned int mpi=0;mpi<numModelPoints+1;++mpi) rowSum+=m(ipi,mpi); /* Normalize the row: */ for(unsigned int mpi=0;mpi<numModelPoints+1;++mpi) { double oldM=m(ipi,mpi); m(ipi,mpi)/=rowSum; rowMaxDelta=Math::max(rowMaxDelta,Math::abs(m(ipi,mpi)-oldM)); } } /* Normalize model point columns: */ colMaxDelta=0.0; for(unsigned int mpi=0;mpi<numModelPoints;++mpi) { /* Calculate the column sum: */ double colSum=0.0; for(unsigned int ipi=0;ipi<numImagePoints+1;++ipi) colSum+=m(ipi,mpi); /* Normalize the column: */ for(unsigned int ipi=0;ipi<numImagePoints+1;++ipi) { double oldM=m(ipi,mpi); m(ipi,mpi)/=colSum; colMaxDelta=Math::max(colMaxDelta,Math::abs(m(ipi,mpi)-oldM)); } } } while(rowMaxDelta+colMaxDelta>1.0e-4); /* Compute the left-hand side of the pose alignment linear system: */ Math::Matrix lhs(4,4,0.0); for(unsigned int mpi=0;mpi<numModelPoints;++mpi) { const Point& mp=modelPoints[mpi]; /* Calculate the linear equation weight for the model point: */ double mpWeight=0.0; for(unsigned int ipi=0;ipi<numImagePoints;++ipi) mpWeight+=m(ipi,mpi); /* Enter the model point into the pose alignment linear system: */ for(int i=0;i<3;++i) { for(int j=0;j<3;++j) lhs(i,j)+=mp[i]*mp[j]*mpWeight; lhs(i,3)+=mp[i]*mpWeight; } for(int j=0;j<3;++j) lhs(3,j)+=mp[j]*mpWeight; lhs(3,3)+=mpWeight; } /* Invert the left-hand side matrix: */ Math::Matrix lhsInv; try { lhsInv=lhs.inverseFullPivot(); } catch(Math::Matrix::RankDeficientError) { std::cerr<<"Left-hand side matrix is rank deficient"<<std::endl; for(int i=0;i<4;++i) { for(int j=0;j<4;++j) std::cerr<<" "<<lhs(i,j); std::cerr<<std::endl; } std::cerr<<"Assignment matrix:"<<std::endl; for(unsigned int i=0;i<=numImagePoints;++i) { for(unsigned int j=0;j<=numModelPoints;++j) std::cerr<<" "<<m(i,j); std::cerr<<std::endl; } return Transform::identity; } /* Perform a fixed number of iterations of POSIT: */ for(unsigned int iteration=0;iteration<2U;++iteration) { /* Compute the right-hand side of the pose alignment linear system: */ Math::Matrix rhs(4,2,0.0); for(unsigned int mpi=0;mpi<numModelPoints;++mpi) { const Point& mp=modelPoints[mpi]; /* Enter the model point into the pose alignment linear system: */ double sumX=0.0; double sumY=0.0; for(unsigned int ipi=0;ipi<numImagePoints;++ipi) { sumX+=m(ipi,mpi)*imagePoints[ipi][0]; sumY+=m(ipi,mpi)*imagePoints[ipi][1]; } sumX*=mpws[mpi]; sumY*=mpws[mpi]; for(int i=0;i<3;++i) { rhs(i,0)+=sumX*mp[i]; rhs(i,1)+=sumY*mp[i]; } rhs(3,0)+=sumX; rhs(3,1)+=sumY; } /* Solve the pose alignment system: */ Math::Matrix pose=lhsInv*rhs; for(int i=0;i<3;++i) { r1[i]=pose(i,0); r2[i]=pose(i,1); } /* Orthonormalize the pose vectors: */ double s1=r1.mag(); double s2=r2.mag(); Vector r3=Geometry::normalize(r1^r2); Vector mid=r1/s1+r2/s2; mid/=mid.mag()*Math::sqrt(2.0); Vector mid2=r3^mid; r1=mid-mid2; r2=mid+mid2; s=Math::sqrt(s1*s2); t[0]=pose(3,0)/s; t[1]=pose(3,1)/s; t[2]=-f/s; /* Update the object points' homogeneous weights: */ for(unsigned int mpi=0;mpi<numModelPoints;++mpi) mpws[mpi]=(r3*modelPoints[mpi])/t[2]+1.0; } // DEBUGGING // std::cout<<"Intermediate: "<<Transform(t,Geometry::invert(Transform::Rotation::fromBaseVectors(r1,r2)))<<std::endl; } // DEBUGGING std::cerr<<"Final assignment matrix:"<<std::endl; for(unsigned int i=0;i<=numImagePoints;++i) { for(unsigned int j=0;j<=numModelPoints;++j) std::cerr<<" "<<m(i,j); std::cerr<<std::endl; } /* Return the result transformation: */ return Transform(t,Geometry::invert(Transform::Rotation::fromBaseVectors(r1,r2))); }
Logical LineClass::intersects(const LineClass &other) { double Ax, Bx, Cx, Dx; double Ay, By, Cy, Dy; double distAB, theCos, theSin, newX, ABpos ; LineClass lhs(*this); LineClass rhs(other); Ax = lhs.p1.x; Bx = lhs.p2.x; Cx = rhs.p1.x; Dx = rhs.p2.x; Ay = lhs.p1.y; By = lhs.p2.y; Cy = rhs.p1.y; Dy = rhs.p2.y; // Fail if either line segment is zero-length. if (Ax == Bx && Ay == By || Cx == Dx && Cy == Dy) { return no; } // Fail if the segments share an end-point. // if (Ax == Cx && Ay == Cy || Bx == Cx && By == Cy || Ax == Dx && Ay == Dy || Bx == Dx && By == Dy) // { // return no; // } // check if the lines are colinear //vertical line if(Ax == Bx && Cx == Dx && Ax == Cx) { if(Ax >= Cx && Ax <= Dx && Bx >= Cx && Bx <= Dx) { if(Ay >= Cy && Ay <= Dy || By >= Cy && By <= Dy) { lprintf("vertical case\n"); return yes; } } } //horizontal line if(Ay == By && Cy == Dy && Ay == Cy) { if(Ay >= Cy && Ay <= Dy && By >= Cy && By <= Dy) { if(Ax >= Cx && Ax <= Dx || Bx >= Cx && Bx <= Dx) { lprintf("horizontal case\n"); return yes; } } } // (1) Translate the system so that point A is on the origin. Bx -= Ax; By -= Ay; Cx -= Ax; Cy -= Ay; Dx -=Ax; Dy -=Ay; // Discover the length of segment A-B. distAB = sqrt(Bx * Bx+ By *By); // (2) Rotate the system so that point B is on the positive X axis. theCos = Bx / distAB; theSin = By / distAB; newX = Cx * theCos + Cy * theSin; Cy = Cy * theCos - Cx * theSin; Cx = newX; newX = Dx * theCos +Dy * theSin; Dy =Dy * theCos - Dx * theSin; Dx = newX; // Fail if segment C-D doesn't cross line A-B. if (Cy < 0. && Dy < 0. || Cy >= 0. && Dy >= 0.) return no; // (3) Discover the position of the intersection point along line A-B. ABpos = Dx + (Cx - Dx) * Dy /(Dy - Cy); // Fail if segment C-D crosses line A-B outside of segment A-B. if (ABpos < 0. || ABpos > distAB) return no; // (4) Apply the discovered position to line A-B in the original coordinate system. //*X = Ax + ABpos * theCos; //*Y = Ay + ABpos * theSin; // Success. return yes; }
Cpath operator/(const Cpath& rhs) { Cpath lhs(*this); lhs /= rhs; return lhs; };
PB_DS_CLASS_T_DEC bool PB_DS_CLASS_C_DEC:: split_join_imp(pb_ds::detail::true_type) { PB_DS_TRACE("split_join"); bool done = true; PB_DS_SET_DESTRUCT_PRINT try { m_alloc.set_throw_prob(0); Cntnr lhs(*m_p_c); Cntnr rhs; native_type native_lhs(m_native_c); native_type native_rhs; const key_type k = test_traits::generate_key(m_g, m_m); m_alloc.set_throw_prob(m_tp); lhs.split(k, rhs); typename native_type::const_iterator it = native_lhs.upper_bound(test_traits::native_key(k)); while (!native_lhs.empty()&& it != native_lhs.end()) { native_rhs.insert(*it); typename native_type::const_iterator next_it = it; ++next_it; native_lhs.erase(test_traits::extract_native_key(*it)); it = next_it; } PB_DS_COND_COMPARE(lhs, native_lhs); PB_DS_COND_COMPARE(rhs, native_rhs); m_alloc.set_throw_prob(m_tp); if (m_g.get_prob() < 0.5) lhs.swap(rhs); lhs.join(rhs); PB_DS_THROW_IF_FAILED( rhs.size() == 0, static_cast<unsigned long>(rhs.size()), m_p_c, & m_native_c); PB_DS_THROW_IF_FAILED( rhs.empty(), static_cast<unsigned long>(rhs.size()), m_p_c, & m_native_c); m_p_c->swap(lhs); } catch(__gnu_cxx::forced_exception_error& ) { done = false; PB_DS_THROW_IF_FAILED( container_traits::split_join_can_throw, container_traits::split_join_can_throw, m_p_c, & m_native_c); } PB_DS_COND_COMPARE(*m_p_c, m_native_c); PB_DS_CANCEL_DESTRUCT_PRINT return (done); }
// ====================================================================== bool TestTriDiVariableBlocking(const Epetra_Comm & Comm) { // Basically each processor gets this 5x5 block lower-triangular matrix: // // [ 2 -1 0 0 0 ;... // [-1 2 0 0 0 ;... // [ 0 -1 3 -1 0 ;... // [ 0 0 -1 3 -1 ;... // [ 0 0 0 -1 2 ]; // Epetra_Map RowMap(-1,5,0,Comm); // 5 rows per proc Epetra_CrsMatrix A(Copy,RowMap,0); int num_entries; int indices[5]; double values[5]; int rb = RowMap.GID(0); /*** Fill RHS / LHS ***/ Epetra_Vector rhs(RowMap), lhs(RowMap), exact_soln(RowMap); rhs.PutScalar(2.0); lhs.PutScalar(0.0); exact_soln.PutScalar(2.0); /*** Fill Matrix ****/ // Row 0 num_entries=2; indices[0]=rb; indices[1]=rb+1; values[0] =2; values[1] =-1; A.InsertGlobalValues(rb,num_entries,&values[0],&indices[0]); // Row 1 num_entries=2; indices[0]=rb; indices[1]=rb+1; values[0] =-1; values[1] =2; A.InsertGlobalValues(rb+1,num_entries,&values[0],&indices[0]); // Row 2 num_entries=3; indices[0]=rb+1; indices[1]=rb+2; indices[2]=rb+3; values[0] =-1; values[1] = 3; values[2] =-1; A.InsertGlobalValues(rb+2,num_entries,&values[0],&indices[0]); // Row 3 num_entries=3; indices[0]=rb+2; indices[1]=rb+3; indices[2]=rb+4; values[0] =-1; values[1] = 3; values[2] =-1; A.InsertGlobalValues(rb+3,num_entries,&values[0],&indices[0]); // Row 4 num_entries=2; indices[0]=rb+3; indices[1]=rb+4; values[0] =-1; values[1] = 2; A.InsertGlobalValues(rb+4,num_entries,&values[0],&indices[0]); A.FillComplete(); /* Setup Block Relaxation */ int PartMap[5]={0,0,1,1,1}; Teuchos::ParameterList ilist; ilist.set("partitioner: type","user"); ilist.set("partitioner: map",&PartMap[0]); ilist.set("partitioner: local parts",2); ilist.set("relaxation: sweeps",1); ilist.set("relaxation: type","Gauss-Seidel"); Ifpack_BlockRelaxation<Ifpack_TriDiContainer> TDRelax(&A); TDRelax.SetParameters(ilist); TDRelax.Initialize(); TDRelax.Compute(); TDRelax.ApplyInverse(rhs,lhs); double norm; lhs.Update(1.0,exact_soln,-1.0); lhs.Norm2(&norm); if(verbose) cout<<"Variable Block Partitioning Test"<<endl; if(norm < 1e-14) { if(verbose) cout << "Test passed" << endl; return true; } else { if(verbose) cout << "Test failed" << endl; return false; } }
TEST(uri_comparison_test, less_than_test) { // lhs is lexicographically less than rhs network::uri lhs("http://www.example.com/"); network::uri rhs("http://www.example.org/"); ASSERT_LT(lhs, rhs); }
//-------------------------------------------------------------------------- //-------- execute --------------------------------------------------------- //-------------------------------------------------------------------------- void AssembleMomentumEdgeSolverAlgorithm::execute() { stk::mesh::MetaData & meta_data = realm_.meta_data(); const int nDim = meta_data.spatial_dimension(); const double small = 1.0e-16; // extract user advection options (allow to potentially change over time) const std::string dofName = "velocity"; const double alpha = realm_.get_alpha_factor(dofName); const double alphaUpw = realm_.get_alpha_upw_factor(dofName); const double hoUpwind = realm_.get_upw_factor(dofName); const bool useLimiter = realm_.primitive_uses_limiter(dofName); // one minus flavor const double om_alpha = 1.0-alpha; const double om_alphaUpw = 1.0-alphaUpw; // space for LHS/RHS; always edge connectivity const int nodesPerEdge = 2; const int lhsSize = nDim*nodesPerEdge*nDim*nodesPerEdge; const int rhsSize = nDim*nodesPerEdge; std::vector<double> lhs(lhsSize); std::vector<double> rhs(rhsSize); std::vector<stk::mesh::Entity> connected_nodes(2); // area vector; gather into std::vector<double> areaVec(nDim); // pointer for fast access double *p_lhs = &lhs[0]; double *p_rhs = &rhs[0]; double *p_areaVec = &areaVec[0]; // space for dui/dxj. This variable is the modified gradient with NOC std::vector<double> duidxj(nDim*nDim); // extrapolated value from the L/R direction std::vector<double> uIpL(nDim); std::vector<double> uIpR(nDim); // limiter values from the L/R direction, 0:1 std::vector<double> limitL(nDim,1.0); std::vector<double> limitR(nDim,1.0); // extrapolated gradient from L/R direction std::vector<double> duL(nDim); std::vector<double> duR(nDim); // pointers for fast access double *p_duidxj = &duidxj[0]; double *p_uIpL = &uIpL[0]; double *p_uIpR = &uIpR[0]; double *p_limitL = &limitL[0]; double *p_limitR = &limitR[0]; double *p_duL = &duL[0]; double *p_duR = &duR[0]; // deal with state VectorFieldType &velocityNp1 = velocity_->field_of_state(stk::mesh::StateNP1); ScalarFieldType &densityNp1 = density_->field_of_state(stk::mesh::StateNP1); // define some common selectors stk::mesh::Selector s_locally_owned_union = meta_data.locally_owned_part() & stk::mesh::selectUnion(partVec_) & !(realm_.get_inactive_selector()); stk::mesh::BucketVector const& edge_buckets = realm_.get_buckets( stk::topology::EDGE_RANK, s_locally_owned_union ); for ( stk::mesh::BucketVector::const_iterator ib = edge_buckets.begin(); ib != edge_buckets.end() ; ++ib ) { stk::mesh::Bucket & b = **ib ; const stk::mesh::Bucket::size_type length = b.size(); // pointer to edge area vector and mdot const double * av = stk::mesh::field_data(*edgeAreaVec_, b); const double * mdot = stk::mesh::field_data(*massFlowRate_, b); for ( stk::mesh::Bucket::size_type k = 0 ; k < length ; ++k ) { // zeroing of lhs/rhs for ( int i = 0; i < lhsSize; ++i ) { p_lhs[i] = 0.0; } for ( int i = 0; i < rhsSize; ++i ) { p_rhs[i] = 0.0; } stk::mesh::Entity const * edge_node_rels = b.begin_nodes(k); // pointer to edge area vector for ( int j = 0; j < nDim; ++j ) p_areaVec[j] = av[k*nDim+j]; const double tmdot = mdot[k]; // sanity check on number or nodes ThrowAssert( b.num_nodes(k) == 2 ); // left and right nodes stk::mesh::Entity nodeL = edge_node_rels[0]; stk::mesh::Entity nodeR = edge_node_rels[1]; connected_nodes[0] = nodeL; connected_nodes[1] = nodeR; // extract nodal fields const double * coordL = stk::mesh::field_data(*coordinates_, nodeL); const double * coordR = stk::mesh::field_data(*coordinates_, nodeR); const double * dudxL = stk::mesh::field_data(*dudx_, nodeL); const double * dudxR = stk::mesh::field_data(*dudx_, nodeR); const double * vrtmL = stk::mesh::field_data(*velocityRTM_, nodeL); const double * vrtmR = stk::mesh::field_data(*velocityRTM_, nodeR); const double * uNp1L = stk::mesh::field_data(velocityNp1, nodeL); const double * uNp1R = stk::mesh::field_data(velocityNp1, nodeR); const double densityL = *stk::mesh::field_data(densityNp1, nodeL); const double densityR = *stk::mesh::field_data(densityNp1, nodeR); const double viscosityL = *stk::mesh::field_data(*viscosity_, nodeL); const double viscosityR = *stk::mesh::field_data(*viscosity_, nodeR); // copy in extrapolated values for ( int i = 0; i < nDim; ++i ) { // extrapolated du p_duL[i] = 0.0; p_duR[i] = 0.0; const int offSet = nDim*i; for ( int j = 0; j < nDim; ++j ) { const double dxj = 0.5*(coordR[j] - coordL[j]); p_duL[i] += dxj*dudxL[offSet+j]; p_duR[i] += dxj*dudxR[offSet+j]; } } // compute geometry double axdx = 0.0; double asq = 0.0; double udotx = 0.0; for ( int j = 0; j < nDim; ++j ) { const double axj = p_areaVec[j]; const double dxj = coordR[j] - coordL[j]; axdx += axj*dxj; asq += axj*axj; udotx += 0.5*dxj*(vrtmL[j] + vrtmR[j]); } const double inv_axdx = 1.0/axdx; // ip props const double viscIp = 0.5*(viscosityL + viscosityR); const double diffIp = 0.5*(viscosityL/densityL + viscosityR/densityR); // Peclet factor const double pecfac = pecletFunction_->execute(std::abs(udotx)/(diffIp+small)); const double om_pecfac = 1.0-pecfac; // determine limiter if applicable if ( useLimiter ) { for ( int i = 0; i < nDim; ++i ) { const double dq = uNp1R[i] - uNp1L[i]; const double dqMl = 2.0*2.0*p_duL[i] - dq; const double dqMr = 2.0*2.0*p_duR[i] - dq; p_limitL[i] = van_leer(dqMl, dq, small); p_limitR[i] = van_leer(dqMr, dq, small); } } // final upwind extrapolation; with limiter for ( int i = 0; i < nDim; ++i ) { p_uIpL[i] = uNp1L[i] + p_duL[i]*hoUpwind*p_limitL[i]; p_uIpR[i] = uNp1R[i] - p_duR[i]*hoUpwind*p_limitR[i]; } /* form duidxj with over-relaxed procedure of Jasak: dui/dxj = GjUi +[(uiR - uiL) - GlUi*dxl]*Aj/AxDx where Gp is the interpolated pth nodal gradient for ui */ for ( int i = 0; i < nDim; ++i ) { // difference between R and L nodes for component i const double uidiff = uNp1R[i] - uNp1L[i]; // offset into all forms of dudx const int offSetI = nDim*i; // start sum for NOC contribution double GlUidxl = 0.0; for ( int l = 0; l< nDim; ++l ) { const int offSetIL = offSetI+l; const double dxl = coordR[l] - coordL[l]; const double GlUi = 0.5*(dudxL[offSetIL] + dudxR[offSetIL]); GlUidxl += GlUi*dxl; } // form full tensor dui/dxj with NOC for ( int j = 0; j < nDim; ++j ) { const int offSetIJ = offSetI+j; const double axj = p_areaVec[j]; const double GjUi = 0.5*(dudxL[offSetIJ] + dudxR[offSetIJ]); p_duidxj[offSetIJ] = GjUi + (uidiff - GlUidxl)*axj*inv_axdx; } } // lhs diffusion; only -mu*dui/dxj*Aj contribution for now const double dlhsfac = -viscIp*asq*inv_axdx; for ( int i = 0; i < nDim; ++i ) { // 2nd order central const double uiIp = 0.5*(uNp1R[i] + uNp1L[i]); // upwind const double uiUpwind = (tmdot > 0) ? alphaUpw*p_uIpL[i] + om_alphaUpw*uiIp : alphaUpw*p_uIpR[i] + om_alphaUpw*uiIp; // generalized central (2nd and 4th order) const double uiHatL = alpha*p_uIpL[i] + om_alpha*uiIp; const double uiHatR = alpha*p_uIpR[i] + om_alpha*uiIp; const double uiCds = 0.5*(uiHatL + uiHatR); // total advection; pressure contribution in time term expression const double aflux = tmdot*(pecfac*uiUpwind + om_pecfac*uiCds); // divU double divU = 0.0; for ( int j = 0; j < nDim; ++j) divU += p_duidxj[j*nDim+j]; // diffusive flux; viscous tensor doted with area vector double dflux = 2.0/3.0*viscIp*divU*p_areaVec[i]*includeDivU_; const int offSetI = nDim*i; for ( int j = 0; j < nDim; ++j ) { const int offSetTrans = nDim*j+i; const double axj = p_areaVec[j]; dflux += -viscIp*(p_duidxj[offSetI+j] + p_duidxj[offSetTrans])*axj; } // residal for total flux const double tflux = aflux + dflux; const int indexL = i; const int indexR = i + nDim; // total flux left p_rhs[indexL] -= tflux; // total flux right p_rhs[indexR] += tflux; // setup for LHS const int rowL = indexL * nodesPerEdge*nDim; const int rowR = indexR * nodesPerEdge*nDim; //============================== // advection first //============================== const int rLiL = rowL+indexL; const int rLiR = rowL+indexR; const int rRiL = rowR+indexL; const int rRiR = rowR+indexR; // upwind advection (includes 4th); left node double alhsfac = 0.5*(tmdot+std::abs(tmdot))*pecfac*alphaUpw + 0.5*alpha*om_pecfac*tmdot; p_lhs[rLiL] += alhsfac; p_lhs[rRiL] -= alhsfac; // upwind advection (incldues 4th); right node alhsfac = 0.5*(tmdot-std::abs(tmdot))*pecfac*alphaUpw + 0.5*alpha*om_pecfac*tmdot; p_lhs[rRiR] -= alhsfac; p_lhs[rLiR] += alhsfac; // central; left; collect terms on alpha and alphaUpw alhsfac = 0.5*tmdot*(pecfac*om_alphaUpw + om_pecfac*om_alpha); p_lhs[rLiL] += alhsfac; p_lhs[rLiR] += alhsfac; // central; right p_lhs[rRiL] -= alhsfac; p_lhs[rRiR] -= alhsfac; //============================== // diffusion second //============================== const double axi = p_areaVec[i]; //diffusion; row IL p_lhs[rLiL] -= dlhsfac; p_lhs[rLiR] += dlhsfac; // diffusion; row IR p_lhs[rRiL] += dlhsfac; p_lhs[rRiR] -= dlhsfac; // more diffusion; see theory manual for ( int j = 0; j < nDim; ++j ) { const double lhsfacNS = -viscIp*axi*p_areaVec[j]*inv_axdx; const int colL = j; const int colR = j + nDim; // first left; IL,IL; IL,IR p_lhs[rowL + colL] -= lhsfacNS; p_lhs[rowL + colR] += lhsfacNS; // now right, IR,IL; IR,IR p_lhs[rowR + colL] += lhsfacNS; p_lhs[rowR + colR] -= lhsfacNS; } } apply_coeff(connected_nodes, rhs, lhs, __FILE__); } } }
TEST(uri_comparison_test, equality_test_capitalized_scheme) { network::uri lhs("http://www.example.com/"); network::uri rhs("HTTP://www.example.com/"); ASSERT_NE(lhs.compare(rhs, network::uri_comparison_level::string_comparison), 0); }
void LEPlic :: doCellDLS(FloatArray &fvgrad, int ie, bool coord_upd, bool vof_temp_flag) { int i, ineighbr, nneighbr; double fvi, fvk, wk, dx, dy; bool isBoundaryCell = false; LEPlicElementInterface *interface, *ineghbrInterface; FloatMatrix lhs(2, 2); FloatArray rhs(2), xi(2), xk(2); IntArray currCell(1), neighborList; ConnectivityTable *contable = domain->giveConnectivityTable(); if ( ( interface = ( LEPlicElementInterface * ) ( domain->giveElement(ie)->giveInterface(LEPlicElementInterfaceType) ) ) ) { if ( vof_temp_flag ) { fvi = interface->giveTempVolumeFraction(); } else { fvi = interface->giveVolumeFraction(); } if ( ( fvi > 0. ) && ( fvi <= 1.0 ) ) { // potentially boundary cell if ( ( fvi > 0. ) && ( fvi < 1.0 ) ) { isBoundaryCell = true; } /* DLS (Differential least square reconstruction) * * In the DLS method, volume fraction Taylor series expansion of vf (volume fraction) * is formed from each reference cell volume fraction vf at element center x(i) to each * cell neighbor at point x(k). The sum (vf(i)-vf(k))^2 over all immediate neighbors * is then minimized inthe least square sense. */ // get list of neighbours to current cell including current cell currCell.at(1) = ie; contable->giveElementNeighbourList(neighborList, currCell); // loop over neighbors to assemble normal equations nneighbr = neighborList.giveSize(); interface->giveElementCenter(this, xi, coord_upd); lhs.zero(); rhs.zero(); for ( i = 1; i <= nneighbr; i++ ) { ineighbr = neighborList.at(i); if ( ineighbr == ie ) { continue; // skip itself } if ( ( ineghbrInterface = ( LEPlicElementInterface * ) ( domain->giveElement(ineighbr)->giveInterface(LEPlicElementInterfaceType) ) ) ) { if ( vof_temp_flag ) { fvk = ineghbrInterface->giveTempVolumeFraction(); } else { fvk = ineghbrInterface->giveVolumeFraction(); } if ( fvk < 1.0 ) { isBoundaryCell = true; } ineghbrInterface->giveElementCenter(this, xk, coord_upd); wk = xk.distance(xi); dx = ( xk.at(1) - xi.at(1) ) / wk; dy = ( xk.at(2) - xi.at(2) ) / wk; lhs.at(1, 1) += dx * dx; lhs.at(1, 2) += dx * dy; lhs.at(2, 2) += dy * dy; rhs.at(1) += ( fvi - fvk ) * dx / wk; rhs.at(2) += ( fvi - fvk ) * dy / wk; } } if ( isBoundaryCell ) { // symmetry lhs.at(2, 1) = lhs.at(1, 2); // solve normal equation for volume fraction gradient lhs.solveForRhs(rhs, fvgrad); // compute unit normal fvgrad.normalize(); fvgrad.negated(); #ifdef __OOFEG /* * EASValsSetLayer(OOFEG_DEBUG_LAYER); * WCRec p[2]; * double tx = -fvgrad.at(2), ty=fvgrad.at(1); * p[0].x=xi.at(1)-tx*0.1; * p[0].y=xi.at(2)-ty*0.1; * p[1].x=xi.at(1)+tx*0.1; * p[1].y=xi.at(2)+ty*0.1; * p[0].z = p[1].z = 0.0; * GraphicObj *go = CreateLine3D(p); * EGWithMaskChangeAttributes(LAYER_MASK, go); * EMAddGraphicsToModel(ESIModel(), go); * ESIEventLoop (YES, "Cell DLS finished; Press Ctrl-p to continue"); */ #endif } else { fvgrad.zero(); } } } }
TEST(uri_comparison_test, equality_test_capitalized_scheme_with_case_normalization) { network::uri lhs("http://www.example.com/"); network::uri rhs("HTTP://www.example.com/"); ASSERT_EQ(lhs.compare(rhs, network::uri_comparison_level::case_normalization), 0); }
//========================================================================= // test matrix operator= (copy & view) int matrixAssignment(bool verbose, bool debug) { int ierr = 0; int returnierr = 0; if(verbose) printHeading("Testing matrix operator="); // each section is in its own block so we can reuse variable names // lhs = left hand side, rhs = right hand side { // copy->copy (more space needed) // orig and dup should have same signature // modifying orig or dup should have no effect on the other if(verbose) cout << "Checking copy->copy (new alloc)" << endl; Epetra_SerialDenseMatrix lhs(2,2); double* rand1 = getRandArray(25); Epetra_SerialDenseMatrix rhs(Copy, rand1, 5, 5, 5); if(debug) { cout << "before assignment:" << endl; printMat("rhs",rhs); printMat("lhs",lhs); } lhs = rhs; if(debug) { cout << "after assignment:" << endl; printMat("rhs",rhs); printMat("lhs",lhs); } EPETRA_TEST_ERR(!identicalSignatures(rhs,lhs), ierr); EPETRA_TEST_ERR(!seperateData(rhs,lhs), ierr); delete[] rand1; } returnierr += ierr; if(ierr == 0) if(verbose) cout << "Checked OK." << endl; ierr = 0; { // copy->copy (have enough space) // orig and dup should have same signature // modifying orig or dup should have no effect on the other if(verbose) cout << "\nChecking copy->copy (no alloc)" << endl; double* rand1 = getRandArray(25); double* rand2 = getRandArray(20); Epetra_SerialDenseMatrix lhs(Copy, rand1, 5, 5, 5); Epetra_SerialDenseMatrix rhs(Copy, rand2, 4, 4, 5); double* origA = lhs.A(); int origLDA = lhs.LDA(); if(debug) { cout << "before assignment:" << endl; printMat("rhs",rhs); printMat("lhs",lhs); } lhs = rhs; if(debug) { cout << "after assignment:" << endl; printMat("rhs",rhs); printMat("lhs",lhs); } // in this case, instead of doing a "normal" LDA test in identSig, // we do our own. Since we had enough space already, A and LDA should // not have been changed by the assignment. (The extra parameter to // identicalSignatures tells it not to test LDA). EPETRA_TEST_ERR((lhs.A() != origA) || (lhs.LDA() != origLDA), ierr); EPETRA_TEST_ERR(!identicalSignatures(rhs,lhs,false), ierr); EPETRA_TEST_ERR(!seperateData(rhs,lhs), ierr); } returnierr += ierr; if(ierr == 0) if(verbose) cout << "Checked OK." << endl; ierr = 0; { // view->copy // orig and dup should have same signature // modifying orig or dup should have no effect on the other if(verbose) cout << "\nChecking view->copy" << endl; double* rand1 = getRandArray(25); double* rand2 = getRandArray(64); Epetra_SerialDenseMatrix lhs(View, rand1, 5, 5, 5); Epetra_SerialDenseMatrix rhs(Copy, rand2, 8, 8, 8); if(debug) { cout << "before assignment:" << endl; printMat("rhs",rhs); printMat("lhs",lhs); } lhs = rhs; if(debug) { cout << "after assignment:" << endl; printMat("rhs",rhs); printMat("lhs",lhs); } EPETRA_TEST_ERR(!identicalSignatures(rhs,lhs), ierr); EPETRA_TEST_ERR(!seperateData(rhs,lhs), ierr); delete[] rand1; delete[] rand2; } returnierr += ierr; if(ierr == 0) if(verbose) cout << "Checked OK." << endl; ierr = 0; { // copy->view // orig and dup should have same signature // modifying orig or dup should change the other if(verbose) cout << "\nChecking copy->view" << endl; double* rand1 = getRandArray(10); Epetra_SerialDenseMatrix lhs(4,4); Epetra_SerialDenseMatrix rhs(View, rand1, 2, 2, 5); if(debug) { cout << "before assignment:" << endl; printMat("rhs",rhs); printMat("lhs",lhs); } lhs = rhs; if(debug) { cout << "after assignment:" << endl; printMat("rhs",rhs); printMat("lhs",lhs); } EPETRA_TEST_ERR(!identicalSignatures(rhs,lhs), ierr); EPETRA_TEST_ERR(seperateData(rhs,lhs), ierr); delete[] rand1; } returnierr += ierr; if(ierr == 0) if(verbose) cout << "Checked OK." << endl; ierr = 0; { // view->view // orig and dup should have same signature // modifying orig or dup should change the other if(verbose) cout << "\nChecking view->view" << endl; double* rand1 = getRandArray(9); double* rand2 = getRandArray(18); Epetra_SerialDenseMatrix lhs(View, rand1, 3, 3, 3); Epetra_SerialDenseMatrix rhs(View, rand2, 3, 3, 6); if(debug) { cout << "before assignment:" << endl; printMat("rhs",rhs); printMat("lhs",lhs); } lhs = rhs; if(debug) { cout << "after assignment:" << endl; printMat("rhs",rhs); printMat("lhs",lhs); } EPETRA_TEST_ERR(!identicalSignatures(rhs,lhs), ierr); EPETRA_TEST_ERR(seperateData(rhs,lhs), ierr); delete[] rand1; delete[] rand2; } returnierr += ierr; if(ierr == 0) if(verbose) cout << "Checked OK." << endl; ierr = 0; return(returnierr); }
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) { // a bunch of typedefs which will be handy later on typedef boost::dynamic_bitset<Block> bitset_type; typedef bitset_test<bitset_type> Tests; // typedef typename bitset_type::size_type size_type; // unusable with Borland 5.5.1 std::string long_string = get_long_string(); std::size_t ul_width = std::numeric_limits<unsigned long>::digits; //===================================================================== // Test b.empty() { bitset_type b; Tests::empty(b); } { bitset_type b(1, 1ul); Tests::empty(b); } { bitset_type b(bitset_type::bits_per_block + bitset_type::bits_per_block/2, 15ul); Tests::empty(b); } //===================================================================== // Test b.to_long() { boost::dynamic_bitset<Block> b; Tests::to_ulong(b); } { boost::dynamic_bitset<Block> b(std::string("1")); Tests::to_ulong(b); } { boost::dynamic_bitset<Block> b(bitset_type::bits_per_block, static_cast<unsigned long>(-1)); Tests::to_ulong(b); } { std::string str(ul_width - 1, '1'); boost::dynamic_bitset<Block> b(str); Tests::to_ulong(b); } { std::string ul_str(ul_width, '1'); boost::dynamic_bitset<Block> b(ul_str); Tests::to_ulong(b); } { // case overflow boost::dynamic_bitset<Block> b(long_string); Tests::to_ulong(b); } //===================================================================== // Test to_string(b, str) { boost::dynamic_bitset<Block> b; Tests::to_string(b); } { boost::dynamic_bitset<Block> b(std::string("0")); Tests::to_string(b); } { boost::dynamic_bitset<Block> b(long_string); Tests::to_string(b); } //===================================================================== // Test b.count() { boost::dynamic_bitset<Block> b; Tests::count(b); } { boost::dynamic_bitset<Block> b(std::string("0")); Tests::count(b); } { boost::dynamic_bitset<Block> b(std::string("1")); Tests::count(b); } { boost::dynamic_bitset<Block> b(8, 255ul); Tests::count(b); } { boost::dynamic_bitset<Block> b(long_string); Tests::count(b); } //===================================================================== // Test b.size() { boost::dynamic_bitset<Block> b; Tests::size(b); } { boost::dynamic_bitset<Block> b(std::string("0")); Tests::size(b); } { boost::dynamic_bitset<Block> b(long_string); Tests::size(b); } //===================================================================== // Test b.any() { boost::dynamic_bitset<Block> b; Tests::any(b); } { boost::dynamic_bitset<Block> b(std::string("0")); Tests::any(b); } { boost::dynamic_bitset<Block> b(long_string); Tests::any(b); } //===================================================================== // Test b.none() { boost::dynamic_bitset<Block> b; Tests::none(b); } { boost::dynamic_bitset<Block> b(std::string("0")); Tests::none(b); } { boost::dynamic_bitset<Block> b(long_string); Tests::none(b); } //===================================================================== // Test a.is_subset_of(b) { boost::dynamic_bitset<Block> a, b; Tests::subset(a, b); } { boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0")); Tests::subset(a, b); } { boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1")); Tests::subset(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); Tests::subset(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); a[long_string.size()/2].flip(); Tests::subset(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); b[long_string.size()/2].flip(); Tests::subset(a, b); } //===================================================================== // Test a.is_proper_subset_of(b) { boost::dynamic_bitset<Block> a, b; Tests::proper_subset(a, b); } { boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0")); Tests::proper_subset(a, b); } { boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1")); Tests::proper_subset(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); Tests::proper_subset(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); a[long_string.size()/2].flip(); Tests::proper_subset(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); b[long_string.size()/2].flip(); Tests::proper_subset(a, b); } //===================================================================== // Test intersects { bitset_type a; // empty bitset_type b; Tests::intersects(a, b); } { bitset_type a; bitset_type b(5, 8ul); Tests::intersects(a, b); } { bitset_type a(8, 0ul); bitset_type b(15, 0ul); b[9] = 1; Tests::intersects(a, b); } { bitset_type a(15, 0ul); bitset_type b(22, 0ul); a[14] = b[14] = 1; Tests::intersects(a, b); } //===================================================================== // Test find_first { // empty bitset bitset_type b; Tests::find_first(b); } { // bitset of size 1 bitset_type b(1, 1ul); Tests::find_first(b); } { // all-0s bitset bitset_type b(4 * bitset_type::bits_per_block, 0ul); Tests::find_first(b); } { // first bit on bitset_type b(1, 1ul); Tests::find_first(b); } { // last bit on bitset_type b(4 * bitset_type::bits_per_block - 1, 0ul); b.set(b.size() - 1); Tests::find_first(b); } //===================================================================== // Test find_next { // empty bitset bitset_type b; // check Tests::find_next(b, 0); Tests::find_next(b, 1); Tests::find_next(b, 200); Tests::find_next(b, b.npos); } { // bitset of size 1 (find_next can never find) bitset_type b(1, 1ul); // check Tests::find_next(b, 0); Tests::find_next(b, 1); Tests::find_next(b, 200); Tests::find_next(b, b.npos); } { // all-1s bitset bitset_type b(16 * bitset_type::bits_per_block); b.set(); // check const typename bitset_type::size_type larger_than_size = 5 + b.size(); for(typename bitset_type::size_type i = 0; i <= larger_than_size; ++i) { Tests::find_next(b, i); } Tests::find_next(b, b.npos); } { // a bitset with 1s at block boundary only const int num_blocks = 32; const int block_width = bitset_type::bits_per_block; bitset_type b(num_blocks * block_width); typename bitset_type::size_type i = block_width - 1; for ( ; i < b.size(); i += block_width) { b.set(i); typename bitset_type::size_type first_in_block = i - (block_width - 1); b.set(first_in_block); } // check const typename bitset_type::size_type larger_than_size = 5 + b.size(); for (i = 0; i <= larger_than_size; ++i) { Tests::find_next(b, i); } Tests::find_next(b, b.npos); } { // bitset with alternate 1s and 0s const typename bitset_type::size_type sz = 1000; bitset_type b(sz); typename bitset_type::size_type i = 0; for ( ; i < sz; ++i) { b[i] = (i%2 == 0); } // check const typename bitset_type::size_type larger_than_size = 5 + b.size(); for (i = 0; i <= larger_than_size; ++i) { Tests::find_next(b, i); } Tests::find_next(b, b.npos); } //===================================================================== // Test operator== { boost::dynamic_bitset<Block> a, b; Tests::operator_equal(a, b); } { boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0")); Tests::operator_equal(a, b); } { boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1")); Tests::operator_equal(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); Tests::operator_equal(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); a[long_string.size()/2].flip(); Tests::operator_equal(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); b[long_string.size()/2].flip(); Tests::operator_equal(a, b); } //===================================================================== // Test operator!= { boost::dynamic_bitset<Block> a, b; Tests::operator_not_equal(a, b); } { boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0")); Tests::operator_not_equal(a, b); } { boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1")); Tests::operator_not_equal(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); Tests::operator_not_equal(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); a[long_string.size()/2].flip(); Tests::operator_not_equal(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); b[long_string.size()/2].flip(); Tests::operator_not_equal(a, b); } //===================================================================== // Test operator< { boost::dynamic_bitset<Block> a, b; Tests::operator_less_than(a, b); } { boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0")); Tests::operator_less_than(a, b); } { boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1")); Tests::operator_less_than(a, b); } { boost::dynamic_bitset<Block> a(std::string("10")), b(std::string("11")); Tests::operator_less_than(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); Tests::operator_less_than(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); a[long_string.size()/2].flip(); Tests::operator_less_than(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); b[long_string.size()/2].flip(); Tests::operator_less_than(a, b); } // check for consistency with ulong behaviour { boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul); assert(a < b); } { boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul); assert(!(a < b)); } { boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul); assert(!(a < b)); } //===================================================================== // Test operator<= { boost::dynamic_bitset<Block> a, b; Tests::operator_less_than_eq(a, b); } { boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0")); Tests::operator_less_than_eq(a, b); } { boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1")); Tests::operator_less_than_eq(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); Tests::operator_less_than_eq(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); a[long_string.size()/2].flip(); Tests::operator_less_than_eq(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); b[long_string.size()/2].flip(); Tests::operator_less_than_eq(a, b); } // check for consistency with ulong behaviour { boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul); assert(a <= b); } { boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul); assert(a <= b); } { boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul); assert(!(a <= b)); } //===================================================================== // Test operator> { boost::dynamic_bitset<Block> a, b; Tests::operator_greater_than(a, b); } { boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0")); Tests::operator_greater_than(a, b); } { boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1")); Tests::operator_greater_than(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); Tests::operator_greater_than(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); a[long_string.size()/2].flip(); Tests::operator_greater_than(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); b[long_string.size()/2].flip(); Tests::operator_greater_than(a, b); } // check for consistency with ulong behaviour { boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul); assert(!(a > b)); } { boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul); assert(!(a > b)); } { boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul); assert(a > b); } //===================================================================== // Test operator<= { boost::dynamic_bitset<Block> a, b; Tests::operator_greater_than_eq(a, b); } { boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0")); Tests::operator_greater_than_eq(a, b); } { boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1")); Tests::operator_greater_than_eq(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); Tests::operator_greater_than_eq(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); a[long_string.size()/2].flip(); Tests::operator_greater_than_eq(a, b); } { boost::dynamic_bitset<Block> a(long_string), b(long_string); b[long_string.size()/2].flip(); Tests::operator_greater_than_eq(a, b); } // check for consistency with ulong behaviour { boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul); assert(!(a >= b)); } { boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul); assert(a >= b); } { boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul); assert(a >= b); } //===================================================================== // Test b.test(pos) { // case pos >= b.size() boost::dynamic_bitset<Block> b; Tests::test_bit(b, 0); } { // case pos < b.size() boost::dynamic_bitset<Block> b(std::string("0")); Tests::test_bit(b, 0); } { // case pos == b.size() / 2 boost::dynamic_bitset<Block> b(long_string); Tests::test_bit(b, long_string.size()/2); } //===================================================================== // Test b << pos { // case pos == 0 std::size_t pos = 0; boost::dynamic_bitset<Block> b(std::string("1010")); Tests::operator_shift_left(b, pos); } { // case pos == size()/2 std::size_t pos = long_string.size() / 2; boost::dynamic_bitset<Block> b(long_string); Tests::operator_shift_left(b, pos); } { // case pos >= n std::size_t pos = long_string.size(); boost::dynamic_bitset<Block> b(long_string); Tests::operator_shift_left(b, pos); } //===================================================================== // Test b >> pos { // case pos == 0 std::size_t pos = 0; boost::dynamic_bitset<Block> b(std::string("1010")); Tests::operator_shift_right(b, pos); } { // case pos == size()/2 std::size_t pos = long_string.size() / 2; boost::dynamic_bitset<Block> b(long_string); Tests::operator_shift_right(b, pos); } { // case pos >= n std::size_t pos = long_string.size(); boost::dynamic_bitset<Block> b(long_string); Tests::operator_shift_right(b, pos); } //===================================================================== // Test a & b { boost::dynamic_bitset<Block> lhs, rhs; Tests::operator_and(lhs, rhs); } { boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0")); Tests::operator_and(lhs, rhs); } { boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string); Tests::operator_and(lhs, rhs); } { boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string); Tests::operator_and(lhs, rhs); } //===================================================================== // Test a | b { boost::dynamic_bitset<Block> lhs, rhs; Tests::operator_or(lhs, rhs); } { boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0")); Tests::operator_or(lhs, rhs); } { boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string); Tests::operator_or(lhs, rhs); } { boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string); Tests::operator_or(lhs, rhs); } //===================================================================== // Test a^b { boost::dynamic_bitset<Block> lhs, rhs; Tests::operator_xor(lhs, rhs); } { boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0")); Tests::operator_xor(lhs, rhs); } { boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string); Tests::operator_xor(lhs, rhs); } { boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string); Tests::operator_xor(lhs, rhs); } //===================================================================== // Test a-b { boost::dynamic_bitset<Block> lhs, rhs; Tests::operator_sub(lhs, rhs); } { boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0")); Tests::operator_sub(lhs, rhs); } { boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string); Tests::operator_sub(lhs, rhs); } { boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string); Tests::operator_sub(lhs, rhs); } }