void Bras::in_state_func() { switch (state) { case RANGE_DEPART : scr(); a0(); spb(); pf(); break; case INT_RANGE : //va bumper scn(); a0(); spb(); pf(); break; case INT2_RANGE : set_time_out(400, trigger_to_be); scn(); a0(); spb(); pf(); break; case GO_ATTENTE : scn(); a1(); spb(); pf(); break; case ATTENTE_ACTIF : scn(); a1(); spb(); pf(); break; case DESCENTE_LAT : scn(); a4(); spb(); pf(); break; case DESCENTE_POMPE_LAT : scn(); a4(); spb(); po(); break; case PRISE_LAT : scn(); a4(); spb(); po(); break; case MONTE_VERT : set_time_out(500, TIME_OUT); scn(); a0(); spv(); po(); break; case MONTE : scn(); a0(); spb(); po(); break; case RANGE_PRISE : set_time_out(2000, TIME_OUT); scl(); a0(); spb(); po(); break; case LACHE : set_time_out(300, TIME_OUT); scl(); a0(); spb(); pf(); break; case MONTE_ECH : scn(); a3(); spb(); po(); break; case MONTE_ECH_VERT : sce(); a3(); spr(); po(); break; case RETOURNE_ECH : call_for_help(); sce(); a3(); spr(); po(); break; case REPLACE_APRES_ECH : set_time_out(300, TIME_OUT); scn(); a3(); spb(); pf(); break; case SEND_MINE : scv(); a4(); spv(); pf(); break; case SENDMASTER_PRET : scv(); a4(); spv(); po(); break; case PRISE_VERT : scv(); a4(); spv(); po(); break; case PRISE_COPAIN : a2(); sce(); spb(); po(); break; } }
void simpleMatrixTest::testElementAssignment() { matrix<int> a = matrix<int>(2,3); a(0,0) = 5; Assert(a(0,0) == 5, "Element Assignment Test 1 failed"); a(0,1) = a(0,0); Assert(a(0,1) == 5, "Element Assignment Test 2 failed"); a(0,0) = a(0,1) = a(1,0) = a(1,2) = 7; Assert(a(0,0) == 7 && a(1,2) == 7, "Element Assignment Test 3 failed"); matrix<int> a2 = matrix<int>(2,3,true); a2(0,0) = 5; Assert(a2(0,0) == 5, "Element Assignment Test 1 failed"); a2(0,1) = a2(0,0); Assert(a2(0,1) == 5, "Element Assignment Test 2 failed"); a2(0,0) = a2(0,1) = a2(1,0) = a2(1,2) = 7; Assert(a2(0,0) == 7 && a2(1,2) == 7, "Element Assignment Test 3 failed"); }
int a3(int n) { return n * a2(n-1); }
void testTDM(void) { std::default_random_engine generator; std::uniform_real_distribution<double> distribution(-1000., 1000.); auto rnd = std::bind(distribution, generator); std::size_t N = 10; vec a(N, 0.); vec a2(N, 0.); vec b(N, 0.); vec b2(N, 0.); vec c(N-1, 0); vec c2(N-1, 0); b[0] = rnd(); c[0] = rnd(); for (std::size_t i=1; i<N-1; i++) { a[i] = rnd(); a2[i] = rnd(); b[i] = rnd(); b2[i] = rnd(); c[i] = rnd(); c2[i] = rnd(); } a[N-1] = rnd(); b[N-1] = rnd(); TDM tdm(a, b, c); const TDM tdm2(a2, b2, c2); tdm.add(tdm2); vtype s = rnd(); tdm.scale(s); auto a3 = tdm.get(TDM::Diagonal::A); auto a4 = tdm.get(TDM::Diagonal::A, true); auto b3 = tdm.get(TDM::Diagonal::B); auto b4 = tdm.get(TDM::Diagonal::B, true); auto c3 = tdm.get(TDM::Diagonal::C); auto c4 = tdm.get(TDM::Diagonal::C, true); a4.insert(a4.begin(), 0.); assert(a3.size() == a4.size()); assert(a4.size() == b3.size()); assert(b3.size() == b4.size()); assert(b4.size() == c3.size()+1); assert(c3.size() == c4.size()); assert(c4.size()+1 == N); for (size_t i=0; i<N; i++) { assert(std::abs(a3[i] - a4[i]) < 1e-10); assert(std::abs(b3[i] - b4[i]) < 1e-10); assert(std::abs(c3[i] - c4[i]) < 1e-10); assert(std::abs(a3[i] - s*(a[i]+a2[i])) < 1e-10); assert(std::abs(b3[i] - s*(b[i]+b2[i])) < 1e-10); assert(std::abs(c3[i] - s*(c[i]+c2[i])) < 1e-10); } vec x(N, 0.); for (size_t i=0; i<N; i++) { x[i] = rnd(); } const TDM tdm3(tdm); auto inverted = tdm3.invert(x); auto y = tdm.transform(inverted); for (size_t i=0; i<N; i++) { assert(std::abs(x[i] - y[i]) < 1e-10); } }
void test2 () { b = a2 (b, b); }
bool testinvldlt(bool silent) { bool result; ap::real_2d_array a; ap::real_2d_array a2; ap::real_2d_array a3; ap::integer_1d_array p; int n; int pass; int mtask; int i; int j; int k; int minij; bool upperin; bool cr; double v; double err; bool waserrors; int passcount; int maxn; int htask; double threshold; err = 0; passcount = 10; maxn = 20; threshold = 100000*ap::machineepsilon; waserrors = false; // // Test // for(n = 1; n <= maxn; n++) { a.setbounds(0, n-1, 0, n-1); a2.setbounds(0, n-1, 0, n-1); a3.setbounds(0, n-1, 0, n-1); for(mtask = 2; mtask <= 2; mtask++) { for(htask = 0; htask <= 1; htask++) { for(pass = 1; pass <= passcount; pass++) { upperin = htask==0; // // Prepare task: // * A contains symmetric matrix // * A2, A3 contains its upper (or lower) half // generatematrix(a, n, mtask); for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a2(i,j) = a(i,j); a3(i,j) = a(i,j); } } for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { if( upperin ) { if( j<i ) { a2(i,j) = 0; a3(i,j) = 0; } } else { if( i<j ) { a2(i,j) = 0; a3(i,j) = 0; } } } } // // Test 1: inv(A2) // smatrixinverse(a2, n, upperin); restorematrix(a2, n, upperin); for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { v = ap::vdotproduct(a.getrow(i, 0, n-1), a2.getcolumn(j, 0, n-1)); if( i==j ) { v = v-1; } err = ap::maxreal(err, fabs(v)); } } // // Test 2: inv(LDLt(A3)) // smatrixldlt(a3, n, upperin, p); smatrixldltinverse(a3, p, n, upperin); restorematrix(a3, n, upperin); for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { v = ap::vdotproduct(a.getrow(i, 0, n-1), a3.getcolumn(j, 0, n-1)); if( i==j ) { v = v-1; } err = ap::maxreal(err, fabs(v)); } } } } } } // // report // waserrors = err>threshold; if( !silent ) { printf("TESTING LDLT INVERSE\n"); printf("ERROR: %5.3le\n", double(err)); if( waserrors ) { printf("TEST FAILED\n"); } else { printf("TEST PASSED\n"); } printf("\n\n"); } result = !waserrors; return result; }
int main () try { auto usb = usb_open(); std::shared_ptr<libusb_device_handle> dh = usb_device_get (usb.get(), 0x1130, 0x660c); usb_attach_interface a1 (dh, 0); usb_attach_interface a2 (dh, 1); usb_error::check (libusb_set_configuration (dh.get (), 1)); usb_claim_interface i1 (dh, 0); usb_claim_interface i2 (dh, 1); // init { struct dev_info { uint16_t dev_type; uint8_t cal[2][2]; // OpenBSD repeatedly issues the devtype command until this != 0x53 // Maybe this is necessary if the device has just been plugged in // and has not settled yet? uint8_t footer; } dinfo; msg256 dinfo_raw = read_data (dh, cmd_devtype); std::copy (std::begin(dinfo_raw), std::end(dinfo_raw), reinterpret_cast<unsigned char*> (&dinfo)); //int val; switch (dinfo.dev_type) { case dev_type_temper1: send_cmd (dh, cmd_reset0); /*val = (dinfo.cal[0][0] - 0x14) * 100; val += dinfo.cal[0][1] * 10; std::cerr << "calibration: " << val << std::endl;*/ break; default: throw std::runtime_error ("unknwon device type"); } } // read { msg256 d = read_data (dh, cmd_getdata_inner); // raw values /* std::ostringstream h; h << std::hex << "0x" << int (d[0]) << " 0x" << int (d[1]); std::cout << h.str () << std::endl; std::cout << ((d[0] << 8) + (d[1] & 0xff)) << std::endl; */ // from OpenBSD //std::cout << d[0] * 100 + (d[1] >> 4) * 25 / 4 << std::endl; // easy way std::cout << float (d[0]) + float (d[1])/256 << '\n'; } return EXIT_SUCCESS; } catch (std::exception& e) { std::cerr << "exception: " << e.what () << std::endl; return EXIT_FAILURE; }
int main(int argc, char *argv[]) { // Initialize POOMA and output stream, using Tester class Pooma::initialize(argc, argv); Pooma::Tester tester(argc, argv); tester.out() << argv[0] << ": MP DynamicArray w/ shared layouts." << std::endl; tester.out() << "-------------------------------------------" << std::endl; // Create some Interval objects to create and index into Array's with tester.out() << "Creating Interval<1> objects ..." << std::endl; Interval<1> D1(3); tester.out() << "D1 = " << D1 << std::endl; // Create MultiPatch dynamic arrays that share a layout. tester.out() << "Creating MP DynamicArray using domain D1 ... " << std::endl; Loc<1> blocks(3); GridPartition<1> gpar(blocks); LocalMapper<1> cmap(gpar); DynamicLayout dynlayout(D1,gpar,cmap); DynamicArray< int, MultiPatch<DynamicTag,Dynamic> > a2(dynlayout); tester.check("a2 size", a2.domain().size() == D1.size()); tester.check("a2 patches", a2.layout().sizeLocal() == 3); tester.out() << "Creating MP DynamicArray w/ same layout ..." << std::endl; DynamicArray< int, MultiPatch<DynamicTag,Dynamic> > b2(a2.layout()); tester.check("b2 size", b2.domain().size() == D1.size()); tester.check("b2 patches", b2.layout().sizeLocal() == 3); // Test looping over layout nodes tester.out() << "DynamicArray< MultiPatch<DynamicTag,Dynamic> > layout:\n"; tester.out() << a2.layout() << std::endl; // Initialize dynamic arrays with scalars. a2 = 30; b2 = 40; Pooma::blockAndEvaluate(); tester.out() << "Initialized MP DynamicArray's to 30, 40:" << std::endl; tester.out() << "a2 = " << a2 << std::endl; tester.out() << "b2 = " << b2 << std::endl; tester.check("a2 initial sum", sum(a2) == (a2.domain().size() * 30)); tester.check("b2 initial sum", sum(b2) == (b2.domain().size() * 40)); // Create elements in the shared-layout MPE arrays tester.out() << "Creating 2 elements at end of a2 and b2 ..." << std::endl; a2.create(2); a2.sync(); a2(3)=a2(4)=-50; b2(3)=b2(4)=-60; a2(a2.engine().domain().last()-1)=0; a2(a2.engine().domain().last())=0; tester.out() << "a2 = " << a2 << std::endl; tester.out() << "b2 = " << b2 << std::endl; tester.check("a2 size after create", a2.domain().size() == (D1.size() + 2)); tester.check("b2 size after create", b2.domain().size() == (D1.size() + 2)); // Delete an element in the shared-layout MPE arrays tester.out() << "Deleting 2nd element of a2 & b2 w/backfill ..."<<std::endl; b2.destroy(Interval<1>(1,1), BackFill()); b2.sync(); tester.out() << "a2 = " << a2 << std::endl; tester.out() << "b2 = " << b2 << std::endl; tester.check("a2 size after BackFill",a2.domain().size() == (D1.size() + 1)); tester.check("b2 size after BackFill",b2.domain().size() == (D1.size() + 1)); // Copy values from the beginning of a2 and b2 to their end tester.out() << "Copying first three elements of a2 and b2 ..." << std::endl; a2.copy(Interval<1>(3)); a2.sync(); tester.out() << "a2 = " << a2 << std::endl; tester.out() << "b2 = " << b2 << std::endl; tester.check("a2 size after copy", a2.domain().size() == (D1.size() + 4)); tester.check("b2 size after copy", b2.domain().size() == (D1.size() + 4)); // Return resulting error code and exit; Tester will shut down POOMA. tester.out() << "-------------------------------------------" << std::endl; int retval = tester.results("MP DynamicArray w/ shared layouts"); Pooma::finalize(); return retval; }
void fitKmm_loQ(Int_t bin) { gSystem->Load("libRooFit"); gROOT->SetStyle("Plain"); gStyle->SetOptStat(1111); TFile * file = TFile::Open("/Disk/ecdf-nfs-ppe/lhcb/gcowan/B2Kll/data/fromAlex/BuKmm.root"); TTree * DecayTree = dynamic_cast<TTree*>(file->Get("DecayTree")); TString binStr; binStr+=bin; Double_t minQ(0.), maxQ(0.); switch(bin) { case 0: minQ = TMath::Sqrt(1.1e6); maxQ = TMath::Sqrt(2.e6); break; case 1: minQ = TMath::Sqrt(2.e6); maxQ = TMath::Sqrt(3.e6); break; case 2: minQ = TMath::Sqrt(3.e6); maxQ = TMath::Sqrt(4.e6); break; case 3: minQ = TMath::Sqrt(4.e6); maxQ = TMath::Sqrt(5.e6); break; case 4: minQ = TMath::Sqrt(5.e6); maxQ = TMath::Sqrt(6.e6); break; default: return; } TString cutStr("Psi_M> "); cutStr += minQ; cutStr += " && Psi_M< "; cutStr += maxQ; //B_M RooRealVar B_M("B_M","; m(Kmumu) (MeV/c^{2}); Candidates / 12 MeV/c^{2}",5150,6000); RooRealVar Psi_M("Psi_M","; m(mumu) (MeV/c^{2}); Candidates / 45 MeV/c^{2}",500,5000); RooDataSet * data = new RooDataSet("data", "dataset with B_REFITTED_M", DecayTree, RooArgSet(B_M,Psi_M)); RooDataSet * data1 = dynamic_cast<RooDataSet*>(data->reduce(cutStr)); // from J/Psi region // 1 #sigma_{Lo} 1.59171e+01 9.61516e-02 1.80663e-03 6.11760e-02 // 2 M_{B} 5.28397e+03 3.00802e-02 1.66677e-03 3.66768e-01 // 3 a1 1.57752e+00 1.64484e-02 2.65338e-03 -7.53912e-01 // 4 a2 -2.64268e+00 2.11254e-02 2.51938e-03 4.90950e-01 // 5 frac 6.78672e-01 1.29969e-02 7.03329e-03 3.65422e-01 // 6 n1 4.79832e+00 2.84430e-01 2.61785e-02 -4.03463e-02 // 7 n2 1.08224e+00 2.68180e-02 5.47500e-03 -9.00362e-01 // 8 nbkg 5.56890e+03 1.31433e+02 7.62084e-03 -8.36640e-01 // 9 nsig 6.56230e+05 8.17224e+02 4.15943e-03 6.95832e-01 // 10 p0 -6.44379e-02 2.13769e-03 2.57927e-02 4.41139e-01 // 11 ratio 1.60407e+00 9.46569e-03 3.93086e-03 -7.72555e-01 // B DCB // start, range to from. plus names and titles. RooRealVar sigmean("M_{B}","B mass",5281.0,5250.0,5300.0,"MeV/c^{2}"); RooRealVar sigsigma("#sigma_{Lo}","B sigma",15.9,0.0,30.0,"MeV/c^{2}"); RooRealVar a1("a1","a1", 1.57752e+00); RooRealVar n1("n1","n1", 4.79832e+00); RooRealVar a2("a2","a2",-2.64268e+00); RooRealVar n2("n2","n2", 1.08224e+00); RooRealVar ratio("ratio","Ratio of widths",1.60407e+00); RooProduct sigsigma2("#sigma_{B}2","B sigma2",RooArgSet(sigsigma,ratio)); RooRealVar frac("frac","fraction of events in each gaussian",6.78672e-01); RooCBShape BSig_RF( "Bsig_RF", "Signal CB B RF Mass", B_M, sigmean, sigsigma, a1, n1 ); RooCBShape BSig_RF2( "Bsig_RF2", "Signal CB B RF Mass", B_M, sigmean, sigsigma2, a2, n2 ); RooAddPdf B0Sig("B0signal","signal pdf",RooArgList(BSig_RF,BSig_RF2),RooArgList(frac)); RooRealVar p0("p0","",-6.44379e-02,-0.1,0.1); RooExponential comb_bkg("comb_bkg","",B_M,p0); // Number of signal & background events RooRealVar nsig("nsig","#signal events",150,-1000,50000,"Events"); RooRealVar nbkg("nbkg","#signal events",150,-1000,50000,"Events"); RooAddPdf full_RF_PDF("full_RF_PDF","RF PDF of everything",RooArgList(B0Sig,comb_bkg), RooArgList(nsig,nbkg)); //# Do the fit on REFITTED Mass full_RF_PDF.fitTo(*data1,RooFit::Extended()); TCanvas * can = new TCanvas("can","Mass fits Data",800,600); B_M_RF_Plot = B_M.frame(100); B_M_RF_Plot->SetTitle(""); B_M_RF_Plot->GetYaxis()->SetTitle("Candidates / 8.5 MeV/c^{2}"); B_M_RF_Plot->GetXaxis()->SetTitle("m(K#mu#mu) (MeV/c^{2})"); data1->plotOn(B_M_RF_Plot); full_RF_PDF.plotOn(B_M_RF_Plot); full_RF_PDF.plotOn(B_M_RF_Plot, RooFit::Components("comb_bkg"), RooFit::LineStyle(kDashed),RooFit::LineColor(kMagenta)); full_RF_PDF.plotOn(B_M_RF_Plot, RooFit::Components("B0signal"), RooFit::LineStyle(kDashed)); B_M_RF_Plot->Draw(); can->SaveAs("plots/Kmm_loQ_"+binStr+".pdf"); can->SetLogy(); B_M_RF_Plot->SetMinimum(1.e-1); B_M_RF_Plot->SetMaximum(5.e+2); B_M_RF_Plot->Draw(); can->SaveAs("plots/Kmm_loQ_"+binStr+"_log.pdf"); //// Try splot stuff //// First set all parameters to constant except for yields sigmean.setConstant(); sigsigma.setConstant(); p0.setConstant(); RooStats::SPlot * sData = new RooStats::SPlot("sData","An SPlot",*data1, &full_RF_PDF, RooArgList(nsig,nbkg)); sData->GetSDataSet()->write("/Home/dcraik/Kll/tuples/Kmm_loQ_"+binStr+"_sWeights.txt"); }
TEST(BaseLib, Functional) { auto num_const = InstanceCounter<A>::getNumberOfConstructions(); auto num_move = InstanceCounter<A>::getNumberOfMoves(); auto num_copy = InstanceCounter<A>::getNumberOfCopies(); auto num_inst = InstanceCounter<A>::getNumberOfInstances(); // Base line: measure how many copies and moves // std::function<>(std::bind(...)) needs. A a_base(0.0); // move the object to std::bind() InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); std::function<void(A)> fct_mult( std::bind(&A::multiply, std::move(a_base), std::placeholders::_1)); auto const num_copy_base_move = InstanceCounter<A>::getNumberOfCopies() - num_copy; auto const num_move_base_move = InstanceCounter<A>::getNumberOfMoves() - num_move; // call std::function using pass-by-value A a_base2(0.0); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); fct_mult(a_base2); auto const num_copy_base_pass = InstanceCounter<A>::getNumberOfCopies() - num_copy; auto const num_move_base_pass = InstanceCounter<A>::getNumberOfMoves() - num_move; // end base line // self test InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); A a1(3.0); A a2(a1); EXPECT_INSTANCES(A, num_const+1, num_move, num_copy+1, num_inst+2); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); auto f1_get = BaseLib::easyBind(&A::getValue, a1); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(3.0, f1_get()); // check that really a reference is returned { auto f2_getRef = BaseLib::easyBind(&A::getValueRef, a2); auto& value_ref = f2_getRef(); EXPECT_EQ(3.0, value_ref); value_ref = 4.0; EXPECT_EQ(4.0, a2.getValue()); } EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); // test binding to pointers { A* ap = &a1; auto fp_get = BaseLib::easyBind(&A::getValue, ap); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(3.0, fp_get()); A const* apc = &a1; auto fpc_get = BaseLib::easyBind(&A::getValue, apc); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(3.0, fpc_get()); } EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); // check that referenced objects are not copied { A& a3 = a2; auto f3_get = BaseLib::easyBind(&A::getValue, a3); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(4.0, f3_get()); } { A const& a3 = a2; auto f3_get = BaseLib::easyBind(&A::getValue, a3); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(4.0, f3_get()); } EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); // temporaries must be moved { auto ftemp_get = BaseLib::easyBind(&A::getValue, A(5.0)); EXPECT_INSTANCES(A, num_const + 1, num_move + num_move_base_move, num_copy + num_copy_base_move, num_inst + 1); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); EXPECT_EQ(5.0, ftemp_get()); } // ftemp_get destroyed EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst-1); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); // testing explicit move { A a_move(5.0); EXPECT_INSTANCES(A, num_const+1, num_move, num_copy, num_inst+1); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); auto ftemp_get = BaseLib::easyBind(&A::getValue, std::move(a_move)); EXPECT_INSTANCES(A, num_const, num_move + num_move_base_move, num_copy + num_copy_base_move, num_inst+1); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); EXPECT_EQ(5.0, ftemp_get()); } // ftemp_get destroyed and a_move EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst-2); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); // test binding a callable object { auto f1_op = BaseLib::easyBind(a1); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(21.0, f1_op(7.0)); } EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); // test binding a lambda { double value = 2.0; auto f_op = BaseLib::easyBind([&value](const double x) { value *= x; return value; }); EXPECT_EQ(6.0, f_op(3.0)); EXPECT_EQ(6.0, value); } // check that parameters passed by reference are not copied { auto f1_add = BaseLib::easyBind(&A::add, a1); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); f1_add(a2); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); EXPECT_EQ(7.0, f1_get()); } // check that parameters passed by value are copied { auto f1_mult = BaseLib::easyBind(&A::multiply, a1); EXPECT_INSTANCES(A, num_const, num_move, num_copy, num_inst); f1_mult(a2); EXPECT_INSTANCES(A, num_const, num_move + num_move_base_pass, num_copy + num_copy_base_pass, num_inst); InstanceCounter<A>::update(num_const, num_move, num_copy, num_inst); EXPECT_EQ(28.0, f1_get()); EXPECT_EQ(4.0, a2.getValue()); } }
void unordered_test(X&, Key& k, T& t, Hash& hf, Pred& eq) { typedef BOOST_DEDUCED_TYPENAME X::key_type key_type; typedef BOOST_DEDUCED_TYPENAME X::hasher hasher; typedef BOOST_DEDUCED_TYPENAME X::key_equal key_equal; typedef BOOST_DEDUCED_TYPENAME X::size_type size_type; typedef BOOST_DEDUCED_TYPENAME X::iterator iterator; typedef BOOST_DEDUCED_TYPENAME X::const_iterator const_iterator; typedef BOOST_DEDUCED_TYPENAME X::local_iterator local_iterator; typedef BOOST_DEDUCED_TYPENAME X::const_local_iterator const_local_iterator; typedef BOOST_DEDUCED_TYPENAME boost::BOOST_ITERATOR_CATEGORY<iterator>::type iterator_category; typedef BOOST_DEDUCED_TYPENAME boost::iterator_difference<iterator>::type iterator_difference; typedef BOOST_DEDUCED_TYPENAME boost::iterator_pointer<iterator>::type iterator_pointer; typedef BOOST_DEDUCED_TYPENAME boost::iterator_reference<iterator>::type iterator_reference; typedef BOOST_DEDUCED_TYPENAME boost::BOOST_ITERATOR_CATEGORY<local_iterator>::type local_iterator_category; typedef BOOST_DEDUCED_TYPENAME boost::iterator_difference<local_iterator>::type local_iterator_difference; typedef BOOST_DEDUCED_TYPENAME boost::iterator_pointer<local_iterator>::type local_iterator_pointer; typedef BOOST_DEDUCED_TYPENAME boost::iterator_reference<local_iterator>::type local_iterator_reference; typedef BOOST_DEDUCED_TYPENAME boost::BOOST_ITERATOR_CATEGORY<const_iterator>::type const_iterator_category; typedef BOOST_DEDUCED_TYPENAME boost::iterator_difference<const_iterator>::type const_iterator_difference; typedef BOOST_DEDUCED_TYPENAME boost::iterator_pointer<const_iterator>::type const_iterator_pointer; typedef BOOST_DEDUCED_TYPENAME boost::iterator_reference<const_iterator>::type const_iterator_reference; typedef BOOST_DEDUCED_TYPENAME boost::BOOST_ITERATOR_CATEGORY<const_local_iterator>::type const_local_iterator_category; typedef BOOST_DEDUCED_TYPENAME boost::iterator_difference<const_local_iterator>::type const_local_iterator_difference; typedef BOOST_DEDUCED_TYPENAME boost::iterator_pointer<const_local_iterator>::type const_local_iterator_pointer; typedef BOOST_DEDUCED_TYPENAME boost::iterator_reference<const_local_iterator>::type const_local_iterator_reference; BOOST_MPL_ASSERT((boost::is_same<Key, key_type>)); boost::function_requires<boost::CopyConstructibleConcept<key_type> >(); boost::function_requires<boost::AssignableConcept<key_type> >(); BOOST_MPL_ASSERT((boost::is_same<Hash, hasher>)); test::check_return_type<std::size_t>::equals(hf(k)); BOOST_MPL_ASSERT((boost::is_same<Pred, key_equal>)); test::check_return_type<bool>::convertible(eq(k, k)); boost::function_requires<boost::InputIteratorConcept<local_iterator> >(); BOOST_MPL_ASSERT((boost::is_same<local_iterator_category, iterator_category>)); BOOST_MPL_ASSERT((boost::is_same<local_iterator_difference, iterator_difference>)); BOOST_MPL_ASSERT((boost::is_same<local_iterator_pointer, iterator_pointer>)); BOOST_MPL_ASSERT((boost::is_same<local_iterator_reference, iterator_reference>)); boost::function_requires<boost::InputIteratorConcept<const_local_iterator> >(); BOOST_MPL_ASSERT((boost::is_same<const_local_iterator_category, const_iterator_category>)); BOOST_MPL_ASSERT((boost::is_same<const_local_iterator_difference, const_iterator_difference>)); BOOST_MPL_ASSERT((boost::is_same<const_local_iterator_pointer, const_iterator_pointer>)); BOOST_MPL_ASSERT((boost::is_same<const_local_iterator_reference, const_iterator_reference>)); X(10, hf, eq); X a(10, hf, eq); X(10, hf); X a2(10, hf); X(10); X a3(10); X(); X a4; BOOST_DEDUCED_TYPENAME X::value_type* i = 0; BOOST_DEDUCED_TYPENAME X::value_type* j = 0; X(i, j, 10, hf, eq); X a5(i, j, 10, hf, eq); X(i, j, 10, hf); X a6(i, j, 10, hf); X(i, j, 10); X a7(i, j, 10); X(i, j); X a8(i, j); X const b; sink(X(b)); X a9(b); a = b; test::check_return_type<hasher>::equals(b.hash_function()); test::check_return_type<key_equal>::equals(b.key_eq()); const_iterator q = a.cbegin(); test::check_return_type<iterator>::equals(a.insert(q, t)); test::check_return_type<iterator>::equals(a.emplace_hint(q, t)); a.insert(i, j); test::check_return_type<size_type>::equals(a.erase(k)); BOOST_TEST(a.empty()); if(a.empty()) { a.insert(t); q = a.cbegin(); test::check_return_type<iterator>::equals(a.erase(q)); } const_iterator q1 = a.cbegin(), q2 = a.cend(); test::check_return_type<iterator>::equals(a.erase(q1, q2)); a.clear(); test::check_return_type<iterator>::equals(a.find(k)); test::check_return_type<const_iterator>::equals(b.find(k)); test::check_return_type<size_type>::equals(b.count(k)); test::check_return_type<std::pair<iterator, iterator> >::equals( a.equal_range(k)); test::check_return_type<std::pair<const_iterator, const_iterator> >::equals( b.equal_range(k)); test::check_return_type<size_type>::equals(b.bucket_count()); test::check_return_type<size_type>::equals(b.max_bucket_count()); test::check_return_type<size_type>::equals(b.bucket(k)); test::check_return_type<size_type>::equals(b.bucket_size(0)); test::check_return_type<local_iterator>::equals(a.begin(0)); test::check_return_type<const_local_iterator>::equals(b.begin(0)); test::check_return_type<local_iterator>::equals(a.end(0)); test::check_return_type<const_local_iterator>::equals(b.end(0)); test::check_return_type<const_local_iterator>::equals(a.cbegin(0)); test::check_return_type<const_local_iterator>::equals(b.cbegin(0)); test::check_return_type<const_local_iterator>::equals(a.cend(0)); test::check_return_type<const_local_iterator>::equals(b.cend(0)); test::check_return_type<float>::equals(b.load_factor()); test::check_return_type<float>::equals(b.max_load_factor()); a.max_load_factor((float) 2.0); a.rehash(100); }
void test_constructor() { boost::alignment::aligned_allocator<char, Alignment> a1; boost::alignment::aligned_allocator<int, Alignment> a2(a1); BOOST_TEST(a2 == a1); }
void main() { //Create our audio channels AudioChannel a1(0); AudioChannel a2(1); AudioChannel a3(2); AudioChannel a4(3); AudioChannel a5(4); AudioChannel a6(5); channels[0] = &a1; channels[1] = &a2; channels[2] = &a3; channels[3] = &a4; channels[4] = &a5; channels[5] = &a6; r.seed(); channels[BALL_ROLL_CHANNEL]->play(sRollLoop, REPEAT); //Start playing rolling marble noise channels[BALL_ROLL_CHANNEL]->setVolume(0); for(int i = 0; i < NUM_CUBES; i++) g_starsCollected[i] = 0; for(int i = 0; i < NUM_COLORS; i++) g_bColorsUsed[i] = false; g_iBoardReset = -1; g_iScore = -1; TimeStep ts; float fTapPromptDelay = 0.0; int iBoardDied; //Initialize our boards for(int i = 0; i < NUM_CUBES; i++) boards[i].init(i); Events::neighborAdd.set(onNeighborAdd); //Function for when two cubes touch each other Events::cubeTouch.set(onTouch); //Function for when a cube is tapped //Add the marble to one of them Float2 fVel; fVel.set(0,0); Float2 fPos = LCD_center; fPos.x += TILE_WIDTH/2.0; fPos.y += TILE_HEIGHT/2.0; boards[0].addMarble(fPos, fVel); TextDraw td; bool bFirstSound = true; //Main loop while (1) { ts.next(); for(int i = 0; i < NUM_CUBES; i++) { int iMode; switch(g_iCurMode) { case BOARD_NOTHING: iMode = boards[i].update(float(ts.delta())); //Update our rolling sound to the right volume if(boards[i].hasMarble()) { float fVol = boards[i].getMarbleVelocity() * 0.9; if(fVol > MAX_VOLUME) fVol = MAX_VOLUME; channels[BALL_ROLL_CHANNEL]->setVolume(fVol); } if(iMode & BOARD_GOTPOINT) { iMode ^= BOARD_GOTPOINT; g_iScore++; if(++g_starsCollected[i] == NUM_STARS_CUBE) g_iBoardReset = i; //Play sound for getting a star, but not right on reset if(bFirstSound) bFirstSound = false; else channels[BALL_SFX_CHANNEL]->play(sGetStar); } if(iMode & BOARD_DIED) { //Show game over screen iMode ^= BOARD_DIED; iMode |= MODE_GAMEOVER; td.draw(boards[i].getVid(), "Game over", 6); String<64> s; s << "Score: " << g_iScore; td.draw(boards[i].getVid(), s.c_str(), 8); fTapPromptDelay = 0.0; iBoardDied = i; bFirstSound = true; channels[BALL_ROLL_CHANNEL]->setVolume(0); channels[BALL_SFX_CHANNEL]->play(sDie); } if(iMode & BOARD_LEFT) { iMode ^= BOARD_LEFT; if(g_iBoardReset == i) { boards[i].reset(g_bColorsUsed); g_starsCollected[i] = 0; g_iBoardReset = -1; g_iScore += 3; //Three points for clearing board //Play sound effect for clearing board channels[BOARD_SFX_CHANNEL]->play(sBoardClear); } //Play pass-through-portal sound else if(!channels[PORTAL_CHANNEL]->isPlaying()) channels[PORTAL_CHANNEL]->play(sThroughPortal); } if(iMode & BOARD_WAITPORTAL) { //Play sound effect for entering a portal channels[PORTAL_CHANNEL]->play(sPortalEnter); channels[BALL_ROLL_CHANNEL]->setVolume(0); } g_iCurMode = iMode; break; case BOARD_WAITPORTAL: boards[i].waitPortal(float(ts.delta())); channels[BALL_ROLL_CHANNEL]->setVolume(0); break; case MODE_GAMEOVER: fTapPromptDelay += float(ts.delta()) / 3.0; if(fTapPromptDelay >= TAP_PROMPT_DELAY && fTapPromptDelay < 100.0) { fTapPromptDelay = 100; td.draw(boards[iBoardDied].getVid(), "Tap to restart", 14); } channels[BALL_ROLL_CHANNEL]->setVolume(0); } } System::paint(); } }
TGraphErrors* newCorrCoefGraph(const T* const dat1, const U* const dat2, const Int_t nd, const Int_t minbin=-1, // -1 => 0 const Int_t maxbin=-1 // -1 => nd-1 ) { const Int_t minb = (minbin<0) ? 0 : minbin; const Int_t maxb = (maxbin<0) ? nd-1 : maxbin; if ( (maxb<=minb) || (maxb>=nd) ) { Fatal("newCorrCoefGraph", "Invalid maxb=%d. (minb=%d, nd=%d)", maxb, minb, nd); } // find correlation coef for different shifts //const Int_t ndh = nd/2; const T* c1 = dat1+minb; const U* c2 = dat2+minb; const Int_t ndh = (maxb-minb+1)/2; Int_t pos, j(0); TGraphErrors* gc = new TGraphErrors; for (Int_t sh=1-ndh; sh<ndh; ++sh) { Double_t a1(0), a2(0), r1(0), r2(0); Double_t cor(0), ncr(0); c1 = dat1+minb; c2 = dat2+minb-sh; for (Int_t i=minb; i<=maxb; ++i, ++c1, ++c2) { pos = c2 - dat2; #ifdef SHIFT_INTO_WINDOW if (pos<nd) { // CHECK: can c1 go above nd? if (pos>=0) { #else if (pos<=maxb) { if (pos>=minb) { #endif a1 += *c1; a2 += *c2; r1 += (*c1)*(*c1); r2 += (*c2)*(*c2); cor += (*c1)*(*c2); ncr += 1.0; } } else { break; } } // sample if (ncr>1) { // rms r1 -= (a1*a1)/ncr; r2 -= (a2*a2)/ncr; r1 /= ncr-1.0; r2 /= ncr-1.0; r1 = TMath::Sqrt(r1); r2 = TMath::Sqrt(r2); // ave a1 /= ncr; a2 /= ncr; // cor cor -= ncr*a1*a2; cor /= (ncr-1.0)*r1*r2; gc->SetPoint(j, static_cast<Double_t>(sh), cor); gc->SetPointError(j, 0, (1.0-(cor*cor))/TMath::Sqrt(ncr-1.0)); ++j; } } // shift return gc; }
//Rasterize 4 pixels at once void DepthBuffer::rasterizeTile2x2(int32 x,int32 y,uint32 pass) { auto tileIndex = x + y*tileCount_.x; auto count = tileTriangleCount_[tileIndex]; tileTriangleCount_[tileIndex] = 0; auto faces = triangleBins_ + x*kMaxTrianglesPerTile + y*tileCount_.x*kMaxTrianglesPerTile; vec2i tilePos(x*tileSize_.x,y*tileSize_.y); vec2i tileEnd(tilePos + tileSize_); #ifdef ARPHEG_ARCH_X86 enum { kNumLanes = 4 }; //Flush denormals to zero _mm_setcsr( _mm_getcsr() | 0x8040 ); VecS32 colOffset(0, 1, 0, 1); VecS32 rowOffset(0, 0, 1, 1); //Process the 4 binned triangles at a time VecS32 vertexX[3]; VecS32 vertexY[3]; VecF32 vertexZ[4]; VecS32 tileMinXSimd(tilePos.x); VecS32 tileMaxXSimd(tilePos.x+tileSize_.x-2); VecS32 tileMinYSimd(tilePos.y); VecS32 tileMaxYSimd(tilePos.y+tileSize_.y-2); for(uint32 i = 0;i<count;i += kNumLanes){ uint32 numSimdTris = std::min(uint32(kNumLanes),count-i); auto f = faces+i; for(uint32 ii = 0;ii< numSimdTris;++ii){ vertexX[0].lane[ii] = f[ii].v[0].x; vertexY[0].lane[ii] = f[ii].v[0].y; vertexX[1].lane[ii] = f[ii].v[1].x; vertexY[1].lane[ii] = f[ii].v[1].y; vertexX[2].lane[ii] = f[ii].v[2].x; vertexY[2].lane[ii] = f[ii].v[2].y; vertexZ[ii] = VecF32(f[ii].z[0],f[ii].z[1],f[ii].z[2],0.0f); } // Fab(x, y) = Ax + By + C = 0 // Fab(x, y) = (ya - yb)x + (xb - xa)y + (xa * yb - xb * ya) = 0 // Compute A = (ya - yb) for the 3 line segments that make up each triangle VecS32 A0 = vertexY[1] - vertexY[2]; VecS32 A1 = vertexY[2] - vertexY[0]; VecS32 A2 = vertexY[0] - vertexY[1]; // Compute B = (xb - xa) for the 3 line segments that make up each triangle VecS32 B0 = vertexX[2] - vertexX[1]; VecS32 B1 = vertexX[0] - vertexX[2]; VecS32 B2 = vertexX[1] - vertexX[0]; // Compute C = (xa * yb - xb * ya) for the 3 line segments that make up each triangle VecS32 C0 = vertexX[1] * vertexY[2] - vertexX[2] * vertexY[1]; VecS32 C1 = vertexX[2] * vertexY[0] - vertexX[0] * vertexY[2]; VecS32 C2 = vertexX[0] * vertexY[1] - vertexX[1] * vertexY[0]; // Use bounding box traversal strategy to determine which pixels to rasterize VecS32 minX = vmax(vmin(vmin(vertexX[0], vertexX[1]), vertexX[2]), tileMinXSimd) & VecS32(~1); VecS32 maxX = vmin(vmax(vmax(vertexX[0], vertexX[1]), vertexX[2]), tileMaxXSimd); VecS32 minY = vmax(vmin(vmin(vertexY[0], vertexY[1]), vertexY[2]), tileMinYSimd) & VecS32(~1); VecS32 maxY = vmin(vmax(vmax(vertexY[0], vertexY[1]), vertexY[2]), tileMaxYSimd); //Rasterize each triangle individually for(uint32 lane = 0;lane < numSimdTris;++lane){ //Rasterize in 2x2 quads. VecF32 zz[3]; zz[0] = VecF32(vertexZ[lane].lane[0]); zz[1] = VecF32(vertexZ[lane].lane[1]); zz[2] = VecF32(vertexZ[lane].lane[2]); VecS32 a0(A0.lane[lane]); VecS32 a1(A1.lane[lane]); VecS32 a2(A2.lane[lane]); VecS32 b0(B0.lane[lane]); VecS32 b1(B1.lane[lane]); VecS32 b2(B2.lane[lane]); int32 minx = minX.lane[lane]; int32 maxx = maxX.lane[lane]; int32 miny = minY.lane[lane]; int32 maxy = maxY.lane[lane]; VecS32 col = VecS32(minx) + colOffset; VecS32 row = VecS32(miny) + rowOffset; auto rowIdx = miny*size_.x + 2 * minx; VecS32 w0_row = a0 * col + b0 * row + VecS32(C0.lane[lane]); VecS32 w1_row = a1 * col + b1 * row + VecS32(C1.lane[lane]); VecS32 w2_row = a2 * col + b2 * row + VecS32(C2.lane[lane]); //Multiply each weight by two(rasterize 2x2 quad at once). a0 = shiftl<1>(a0); a1 = shiftl<1>(a1); a2 = shiftl<1>(a2); b0 = shiftl<1>(b0); b1 = shiftl<1>(b1); b2 = shiftl<1>(b2); VecF32 zInc = itof(a1)*zz[1] + itof(a2)*zz[2]; for(int32 y = miny;y<=maxy;y+=2,rowIdx += 2 * size_.x){ auto w0 = w0_row; auto w1 = w1_row; auto w2 = w2_row; VecF32 depth = zz[0] + itof(w1)*zz[1] + itof(w2)*zz[2]; auto idx = rowIdx; for(int32 x = minx;x<=maxx;x+=2,idx+=4){ auto mask = w0|w1|w2; VecF32 previousDepth = VecF32::load(data_+idx); VecF32 mergedDepth = vmin(depth,previousDepth); previousDepth = select(mergedDepth,previousDepth,mask); previousDepth.store(data_+idx); w0+=a0; w1+=a1; w2+=a2; depth+=zInc; } w0_row += b0; w1_row += b1; w2_row += b2; } } } #endif }
void C3DPlotCanvas::SelectByRect() { int hl_size = highlight_state->GetHighlightSize(); std::vector<bool>& hs = highlight_state->GetHighlight(); std::vector<int>& nh = highlight_state->GetNewlyHighlighted(); std::vector<int>& nuh = highlight_state->GetNewlyUnhighlighted(); int total_newly_selected = 0; int total_newly_unselected = 0; double world11[3], world12[3], world22[3], world21[3]; double world113[3], world123[3], world223[3], world213[3]; int pixel11[2], pixel12[2], pixel22[2], pixel21[2]; int small_x = (select_start.x < select_end.x)? select_start.x:select_end.x; int large_x = (select_start.x > select_end.x)? select_start.x:select_end.x; int small_y = (select_start.y < select_end.y)? select_start.y:select_end.y; int large_y = (select_start.y > select_end.y)? select_start.y:select_end.y; pixel11[0] = small_x; pixel12[0] = small_x; pixel21[0] = large_x; pixel22[0] = large_x; pixel11[1] = small_y; pixel21[1] = small_y; pixel12[1] = large_y; pixel22[1] = large_y; ball->apply_transform(); unproject_pixel(pixel11, world11, 0.0); unproject_pixel(pixel12, world12, 0.0); unproject_pixel(pixel22, world22, 0.0); unproject_pixel(pixel21, world21, 0.0); unproject_pixel(pixel11, world113, 1.0); unproject_pixel(pixel12, world123, 1.0); unproject_pixel(pixel22, world223, 1.0); unproject_pixel(pixel21, world213, 1.0); ball->unapply_transform(); SPlane* plane; int i; bool *inside = new bool[num_obs*4]; for(i=0; i<num_obs*4; i++) inside[i] = false; double *world1, *world2, *world3, *world4; for (int k=0; k<4; k++) { switch(k) { case 0: world1 = world11; world2 = world12; world3 = world113; world4 = world123; break; case 1: world1 = world12; world2 = world22; world3 = world123; world4 = world223; break; case 2: world1 = world22; world2 = world21; world3 = world223; world4 = world213; break; case 3: world1 = world21; world2 = world11; world3 = world213; world4 = world113; break; default: break; } plane = new SPlane(world1, world2, world3); Vec3f a1(world1[0], world1[1], world1[2]); Vec3f a2(world2[0], world2[1], world2[2]); Vec3f a3(world3[0], world3[1], world3[2]); Vec3f a4(world4[0], world4[1], world4[2]); Vec3f l1 = a3 - a1; Vec3f l2 = a4 - a2; int xt = var_info[0].time; int yt = var_info[1].time; int zt = var_info[2].time; for (i=0; i<num_obs; i++) { Vec3f cor(scaled_d[0][xt][i], scaled_d[1][yt][i], scaled_d[2][zt][i]); if (plane->isPositive(cor)) inside[k*num_obs+i] = true; } delete plane; } delete [] inside; for (i=0; i<num_obs; i++) { bool contains = (inside[i] && inside[num_obs+i] && inside[2*num_obs+i] && inside[3*num_obs+i]); if (contains) { if (!hs[i]) nh[total_newly_selected++] = i; } else { if (hs[i]) nuh[total_newly_unselected++] = i; } } if (total_newly_selected == 0 && total_newly_unselected == 0) return; if (total_newly_selected == 0 && total_newly_unselected == highlight_state->GetTotalHighlighted()) { highlight_state->SetEventType(HighlightState::unhighlight_all); highlight_state->notifyObservers(); } else { highlight_state->SetEventType(HighlightState::delta); highlight_state->SetTotalNewlyHighlighted(total_newly_selected); highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); highlight_state->notifyObservers(); } }
//Returns true if the triangle is visible bool DepthBuffer::testTriangle2x2(const vec4f& v0,const vec4f& v1,const vec4f& v2){ VecS32 colOffset(0, 1, 0, 1); VecS32 rowOffset(0, 0, 1, 1); vec2i vertex[3]; vertex[0] = vec2i(int32(v0.x),int32(v0.y)); vertex[1] = vec2i(int32(v1.x),int32(v1.y)); vertex[2] = vec2i(int32(v2.x),int32(v2.y)); // Reject the triangle if any of its verts is behind the nearclip plane if(v0.w == 0.0f || v1.w == 0.0f || v2.w == 0.0f) return true; float minZ = std::min(v0.z,std::min(v1.z,v2.z)); VecF32 fixedDepth(minZ); // Fab(x, y) = Ax + By + C = 0 // Fab(x, y) = (ya - yb)x + (xb - xa)y + (xa * yb - xb * ya) = 0 // Compute A = (ya - yb) for the 3 line segments that make up each triangle auto A0 = vertex[1].y - vertex[2].y; auto A1 = vertex[2].y - vertex[0].y; auto A2 = vertex[0].y - vertex[1].y; // Compute B = (xb - xa) for the 3 line segments that make up each triangle auto B0 = vertex[2].x - vertex[1].x; auto B1 = vertex[0].x - vertex[2].x; auto B2 = vertex[1].x - vertex[0].x; // Compute C = (xa * yb - xb * ya) for the 3 line segments that make up each triangle auto C0 = vertex[1].x * vertex[2].y - vertex[2].x * vertex[1].y; auto C1 = vertex[2].x * vertex[0].y - vertex[0].x * vertex[2].y; auto C2 = vertex[0].x * vertex[1].y - vertex[1].x * vertex[0].y; // Use bounding box traversal strategy to determine which pixels to rasterize auto minx = std::max(std::min(std::min(vertex[0].x,vertex[1].x),vertex[2].x),0) & (~1); auto maxx = std::min(std::max(std::max(vertex[0].x,vertex[1].x),vertex[2].x),size_.x-2); auto miny = std::max(std::min(std::min(vertex[0].y,vertex[1].y),vertex[2].y),0) & (~1); auto maxy = std::min(std::max(std::max(vertex[0].y,vertex[1].y),vertex[2].y),size_.y-2); VecS32 a0(A0); VecS32 a1(A1); VecS32 a2(A2); VecS32 b0(B0); VecS32 b1(B1); VecS32 b2(B2); VecS32 col = VecS32(minx) + colOffset; VecS32 row = VecS32(miny) + rowOffset; auto rowIdx = miny*size_.x + 2 * minx; VecS32 w0_row = a0 * col + b0 * row + VecS32(C0); VecS32 w1_row = a1 * col + b1 * row + VecS32(C1); VecS32 w2_row = a2 * col + b2 * row + VecS32(C2); //Multiply each weight by two(rasterize 2x2 quad at once). a0 = shiftl<1>(a0); a1 = shiftl<1>(a1); a2 = shiftl<1>(a2); b0 = shiftl<1>(b0); b1 = shiftl<1>(b1); b2 = shiftl<1>(b2); for(int32 y = miny;y<=maxy;y+=2,rowIdx += 2 * size_.x){ auto w0 = w0_row; auto w1 = w1_row; auto w2 = w2_row; auto idx = rowIdx; for(int32 x = minx;x<=maxx;x+=2,idx+=4){ auto mask = w0|w1|w2; auto masks = _mm_movemask_ps(bits2float(mask).simd); if(masks != 0xF){ VecF32 previousDepth = VecF32::load(data_+idx); auto cmpMask = ((~masks)&0xF)& _mm_movemask_ps(cmple(fixedDepth,previousDepth).simd); if(cmpMask){ return true; } } w0+=a0; w1+=a1; w2+=a2; } w0_row += b0; w1_row += b1; w2_row += b2; } return false; }
int main (int, char *[]) { ACE_START_TEST ("Addr_Test"); /* ================================================================== */ ACE_DEBUG((LM_INFO, "------test virtual destructor------\n")); testSap *n1 = new testSap(); ACE_CLASSIX_SAP *n2 = n1; delete n2; /* ================================================================== */ ACE_DEBUG((LM_INFO, "--------ACE_CLASSIX_Addr----------\n")); ACE_DEBUG((LM_DEBUG, "\n--------------------------------\n")); ACE_CLASSIX_Port_Core *k2 = new ACE_CLASSIX_Port_Core(); int p2 = k2->get_handle(); ACE_CLASSIX_Port a2(*k2); ACE_DEBUG((LM_INFO, "Addr a2(ipc port id = %d)\n", p2)); a2.dump(); ACE_CLASSIX_Port *a1 = ACE_CLASSIX_DEFAULT_PORT::instance(); ACE_DEBUG((LM_INFO, "Default port:")); a1->dump(); a1->set_addr(a2.get_addr(), a2.get_size()); if (*a1 != *ACE_CLASSIX_DEFAULT_PORT::instance()) ACE_DEBUG((LM_ERROR, "???? Default port cannot be changed-2 !!!")); ACE_DEBUG((LM_DEBUG, "\n--------------------------------\n")); ACE_CLASSIX_Port_Core k3; ACE_CLASSIX_Port a3(k3); ACE_DEBUG((LM_INFO, "Addr a3(ipc port id = %d)\n", k3.get_handle)); a3.dump(); ACE_DEBUG((LM_DEBUG, "\n--------------------------------\n")); ACE_CLASSIX_Port a4(a1->get_addr(), a1->get_size()); a4.dump(); if (a4 == *a1) ACE_DEBUG((LM_INFO, "OK: Addr a4 == a1\n")); else ACE_ERROR((LM_ERROR, "Error: Addr a4 != a1\n")); if (a4 != a2) ACE_DEBUG((LM_INFO, "OK: Addr a4 != a2\n")); else ACE_ERROR((LM_ERROR, "Error: Addr a4 == a2\n")); /* ================================================================== */ ACE_DEBUG((LM_INFO, "\n--------ACE_CLASSIX_Sap----------\n")); testSap sap1; sap1.set_addr(*a1); ACE_CLASSIX_Port b1; if (sap1.get_addr(b1) < 0) ACE_ERROR((LM_ERROR, "failed to get sap1 address")); if (b1 != *a1) ACE_ERROR((LM_ERROR, "Error: sap1 address")); sap1.dump(); ACE_DEBUG((LM_DEBUG, "\n--------------------------------\n")); testSap sap2(a2); ACE_CLASSIX_Port b2; if (sap2.get_addr(b2) < 0) ACE_ERROR((LM_ERROR, "failed to get sap1 address")); if (b2 != a2) ACE_ERROR((LM_ERROR, "Error: sap2 address")); b2.dump(); sap2.dump(); /* ================================================================== */ int result = 0; int p = k2->get_handle(); delete k2; if ((result = portDelete(K_MYACTOR, p)) == 0) ACE_ERROR((LM_ERROR, "????Error: delete already deleted port")); ACE_END_TEST; return 0; }
float TouchTracker::Calibrator::differenceFromTemplateTouchWithMask(const MLSignal& in, Vec2 pos, const MLSignal& mask) { static float maskThresh = 0.001f; static MLSignal a2(kTemplateSize, kTemplateSize); static MLSignal b(kTemplateSize, kTemplateSize); static MLSignal b2(kTemplateSize, kTemplateSize); float r = 0.f; int height = in.getHeight(); int width = in.getWidth(); MLRect boundsRect(0, 0, width, height); // use linear interpolated z value from input float linearZ = in.getInterpolatedLinear(pos)*getZAdjust(pos); linearZ = clamp(linearZ, 0.00001f, 1.f); float z1 = 1./linearZ; const MLSignal& a = getTemplate(pos); // get normalized input values surrounding touch int tr = kTemplateRadius; b.clear(); for(int j=0; j < kTemplateSize; ++j) { for(int i=0; i < kTemplateSize; ++i) { Vec2 vInPos = pos + Vec2((float)i - tr,(float)j - tr); if (boundsRect.contains(vInPos) && (mask.getInterpolatedLinear(vInPos) < maskThresh)) { float inVal = in.getInterpolatedLinear(vInPos); inVal *= z1; b(i, j) = inVal; } } } int tests = 0; float sum = 0.; // add differences in z from template a2.copy(a); b2.copy(b); a2.partialDiffX(); b2.partialDiffX(); for(int j=0; j < kTemplateSize; ++j) { for(int i=0; i < kTemplateSize; ++i) { if(b(i, j) > 0.) { float d = a2(i, j) - b2(i, j); sum += d*d; tests++; } } } // get RMS difference if(tests > 0) { r = sqrtf(sum / tests); } return r; }
void f() const { String a2(*this); }
void test() { // This function tests C++0x 5.16 // p1 (contextually convert to bool) int i1 = ToBool() ? 0 : 1; // p2 (one or both void, and throwing) i1 ? throw 0 : throw 1; i1 ? test() : throw 1; i1 ? throw 0 : test(); i1 ? test() : test(); i1 = i1 ? throw 0 : 0; i1 = i1 ? 0 : throw 0; i1 = i1 ? (throw 0) : 0; i1 = i1 ? 0 : (throw 0); i1 ? 0 : test(); // expected-error {{right operand to ? is void, but left operand is of type 'int'}} i1 ? test() : 0; // expected-error {{left operand to ? is void, but right operand is of type 'int'}} (i1 ? throw 0 : i1) = 0; // expected-error {{expression is not assignable}} (i1 ? i1 : throw 0) = 0; // expected-error {{expression is not assignable}} // p3 (one or both class type, convert to each other) // b1 (lvalues) Base base; Derived derived; Convertible conv; Base &bar1 = i1 ? base : derived; Base &bar2 = i1 ? derived : base; Base &bar3 = i1 ? base : conv; Base &bar4 = i1 ? conv : base; // these are ambiguous BadBase bb; BadDerived bd; (void)(i1 ? bb : bd); // expected-error {{conditional expression is ambiguous; 'BadBase' can be converted to 'BadDerived' and vice versa}} (void)(i1 ? bd : bb); // expected-error {{conditional expression is ambiguous}} // curiously enough (and a defect?), these are not // for rvalues, hierarchy takes precedence over other conversions (void)(i1 ? BadBase() : BadDerived()); (void)(i1 ? BadDerived() : BadBase()); // b2.1 (hierarchy stuff) extern const Base constret(); extern const Derived constder(); // should use const overload A a1((i1 ? constret() : Base()).trick()); A a2((i1 ? Base() : constret()).trick()); A a3((i1 ? constret() : Derived()).trick()); A a4((i1 ? Derived() : constret()).trick()); // should use non-const overload i1 = (i1 ? Base() : Base()).trick(); i1 = (i1 ? Base() : Base()).trick(); i1 = (i1 ? Base() : Derived()).trick(); i1 = (i1 ? Derived() : Base()).trick(); // should fail: const lost (void)(i1 ? Base() : constder()); // expected-error {{incompatible operand types ('Base' and 'const Derived')}} (void)(i1 ? constder() : Base()); // expected-error {{incompatible operand types ('const Derived' and 'Base')}} Priv priv; Fin fin; (void)(i1 ? Base() : Priv()); // expected-error{{private base class}} (void)(i1 ? Priv() : Base()); // expected-error{{private base class}} (void)(i1 ? Base() : Fin()); // expected-error{{ambiguous conversion from derived class 'Fin' to base class 'Base':}} (void)(i1 ? Fin() : Base()); // expected-error{{ambiguous conversion from derived class 'Fin' to base class 'Base':}} (void)(i1 ? base : priv); // expected-error {{private base class}} (void)(i1 ? priv : base); // expected-error {{private base class}} (void)(i1 ? base : fin); // expected-error {{ambiguous conversion from derived class 'Fin' to base class 'Base':}} (void)(i1 ? fin : base); // expected-error {{ambiguous conversion from derived class 'Fin' to base class 'Base':}} // b2.2 (non-hierarchy) i1 = i1 ? I() : i1; i1 = i1 ? i1 : I(); I i2(i1 ? I() : J()); I i3(i1 ? J() : I()); // "the type [it] woud have if E2 were converted to an rvalue" vfn pfn = i1 ? F() : test; pfn = i1 ? test : F(); (void)(i1 ? A() : B()); // expected-error {{conversion from 'B' to 'A' is ambiguous}} (void)(i1 ? B() : A()); // expected-error {{conversion from 'B' to 'A' is ambiguous}} (void)(i1 ? 1 : Ambig()); // expected-error {{conversion from 'Ambig' to 'int' is ambiguous}} (void)(i1 ? Ambig() : 1); // expected-error {{conversion from 'Ambig' to 'int' is ambiguous}} // By the way, this isn't an lvalue: &(i1 ? i1 : i2); // expected-error {{cannot take the address of an rvalue}} // p4 (lvalue, same type) Fields flds; int &ir1 = i1 ? flds.i1 : flds.i2; (i1 ? flds.b1 : flds.i2) = 0; (i1 ? flds.i1 : flds.b2) = 0; (i1 ? flds.b1 : flds.b2) = 0; // p5 (conversion to built-in types) // GCC 4.3 fails these double d1 = i1 ? I() : K(); pfn = i1 ? F() : G(); DFnPtr pfm; pfm = i1 ? DFnPtr() : &Base::fn1; pfm = i1 ? &Base::fn1 : DFnPtr(); // p6 (final conversions) i1 = i1 ? i1 : ir1; int *pi1 = i1 ? &i1 : 0; pi1 = i1 ? 0 : &i1; i1 = i1 ? i1 : EVal; i1 = i1 ? EVal : i1; d1 = i1 ? 'c' : 4.0; d1 = i1 ? 4.0 : 'c'; Base *pb = i1 ? (Base*)0 : (Derived*)0; pb = i1 ? (Derived*)0 : (Base*)0; pfm = i1 ? &Base::fn1 : &Derived::fn2; pfm = i1 ? &Derived::fn2 : &Base::fn1; pfm = i1 ? &Derived::fn2 : 0; pfm = i1 ? 0 : &Derived::fn2; const int (MixedFieldsDerived::*mp1) = i1 ? &MixedFields::ci : &MixedFieldsDerived::i; const volatile int (MixedFields::*mp2) = i1 ? &MixedFields::ci : &MixedFields::cvi; (void)(i1 ? &MixedFields::ci : &MixedFields::vi); // Conversion of primitives does not result in an lvalue. &(i1 ? i1 : d1); // expected-error {{cannot take the address of an rvalue}} (void)&(i1 ? flds.b1 : flds.i1); // expected-error {{address of bit-field requested}} (void)&(i1 ? flds.i1 : flds.b1); // expected-error {{address of bit-field requested}} unsigned long test0 = 5; test0 = test0 ? (long) test0 : test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}} test0 = test0 ? (int) test0 : test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? (short) test0 : test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}} test0 = test0 ? test0 : (long) test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}} test0 = test0 ? test0 : (int) test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? test0 : (short) test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}} test0 = test0 ? test0 : (long) 10; test0 = test0 ? test0 : (int) 10; test0 = test0 ? test0 : (short) 10; test0 = test0 ? (long) 10 : test0; test0 = test0 ? (int) 10 : test0; test0 = test0 ? (short) 10 : test0; int test1; test0 = test0 ? EVal : test0; test1 = test0 ? EVal : (int) test0; test0 = test0 ? EVal : test1; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? test1 : EVal; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test1 = test0 ? EVal : (int) test0; test1 = test0 ? (int) test0 : EVal; // Note the thing that this does not test: since DR446, various situations // *must* create a separate temporary copy of class objects. This can only // be properly tested at runtime, though. const Abstract &a = true ? static_cast<const Abstract&>(Derived1()) : Derived2(); // expected-error {{allocating an object of abstract class type 'const Abstract'}} true ? static_cast<const Abstract&>(Derived1()) : throw 3; // expected-error {{allocating an object of abstract class type 'const Abstract'}} }
void TessellateTri( std::vector< bspVertex_t >& outVerts, std::vector< triangle_t >& outIndices, float amount, float normalOffsetScale, const bspVertex_t& a, const bspVertex_t& b, const bspVertex_t& c ) { auto LPassedC = [ &c ]( const glm::vec3& point, const glm::vec3& sig ) -> bool { return ( glm::sign( c.position - point ) != sig ); }; float step = 1.0f / amount; // Use these as a basis for when either the a or b traversal vectors // have passed vertex c glm::vec3 aSig = glm::sign( c.position - a.position ); glm::vec3 bSig = glm::sign( c.position - b.position ); std::unique_ptr< baryCoordSystem_t > triCoordSys( new baryCoordSystem_t( a.position, b.position, c.position ) ); bspVertex_t bToC( ( c - b ) * step ); bspVertex_t aToC( ( c - a ) * step ); bspVertex_t aToBStep( ( b - a ) * step ); std::vector< triangle_t > curStrip; // Points which walk along the edges bspVertex_t a2( a ); bspVertex_t b2( b ); while ( true ) { if ( glm::any( glm::isnan( a2.position ) ) || glm::any( glm::isnan( b2.position ) ) ) break; // If either of these are set to true, then we'll have // triangles which exist outside of the parent tri. if ( LPassedC( a2.position, aSig ) || LPassedC( b2.position, bSig ) ) break; if ( a2.position == c.position || b2.position == c.position ) break; // Path trace the edges of our triangle defined by vertices a2 and b2 bspVertex_t aToB( b2 - a2 ); float walk = 0.0f; float walkLength = 0.0f; float walkStep = glm::length( aToBStep.position ) / glm::length( aToB.position ); float endLength = glm::length( aToB.position ); while ( walkLength < endLength ) { bspVertex_t gv1( a2 + aToB * walk ); bspVertex_t gv2( gv1 + aToBStep ); bspVertex_t gv3( gv1 + aToC ); bspVertex_t gv4( gv3 + aToBStep ); gv1.position += gv1.normal * normalOffsetScale; gv2.position += gv2.normal * normalOffsetScale; gv3.position += gv3.normal * normalOffsetScale; gv4.position += gv4.normal * normalOffsetScale; size_t numVertices; triangle_t t1; // There should be a reasonable workaround for this; maybe scale // the vertices or something like that. if ( !triCoordSys->IsInTri( gv3.position ) || !triCoordSys->IsInTri( gv2.position ) ) goto end_iteration; numVertices = outVerts.size(); gv1.color = glm::u8vec4( 255 ); gv2.color = glm::u8vec4( 255 ); gv3.color = glm::u8vec4( 255 ); { auto v1Iter = std::find( outVerts.begin(), outVerts.end(), gv1 ); if ( v1Iter == outVerts.end() ) { outVerts.push_back( gv1 ); t1.indices[ 0 ] = numVertices++; } else { t1.indices[ 0 ] = v1Iter - outVerts.begin(); } auto v2Iter = std::find( outVerts.begin(), outVerts.end(), gv2 ); if ( v2Iter == outVerts.end() ) { outVerts.push_back( gv2 ); t1.indices[ 1 ] = numVertices++; } else { t1.indices[ 1 ] = v2Iter - outVerts.begin(); } auto v3Iter = std::find( outVerts.begin(), outVerts.end(), gv3 ); if ( v3Iter == outVerts.end() ) { outVerts.push_back( gv3 ); t1.indices[ 2 ] = numVertices++; } else { t1.indices[ 2 ] = v3Iter - outVerts.begin(); } } curStrip.push_back( t1 ); // Attempt a second triangle, providing v4 // is within the bounds if ( !triCoordSys->IsInTri( gv4.position ) ) goto end_iteration; { auto v4Iter = std::find( outVerts.begin(), outVerts.end(), gv4 ); triangle_t t2 = { { t1.indices[ 2 ], t1.indices[ 1 ], 0 } }; if ( v4Iter == outVerts.end() ) { outVerts.push_back( gv4 ); t2.indices[ 2 ] = numVertices; } else { t2.indices[ 2 ] = v4Iter - outVerts.begin(); } curStrip.push_back( t2 ); } end_iteration: walk += walkStep; walkLength = glm::length( aToB.position * walk ); } outIndices.insert( outIndices.end(), curStrip.begin(), curStrip.end() ); curStrip.clear(); a2 += aToC; b2 += bToC; } }
void TubeGenerator::generateCarbonTube(int n1, int n2, int k, float transition, float bondLength, std::vector<Molecule::Atom>& atoms, std::vector<Molecule::Link>& links) { if (n1 < n2) std::swap(n1, n2); atoms.clear(); links.clear(); gameplay::Vector2 a1(1.7320508f, 0.0f); gameplay::Vector2 a2(-0.8660254f, 1.5f); gameplay::Vector2 R = (a1 * static_cast<float>(n1) + a2 * static_cast<float>(n2))* bondLength; gameplay::Vector2 L(-R.y, R.x); L.normalize(); L.scale(k * bondLength); int ymin = -1; int ymax = static_cast<int>(ceilf(std::max(L.y, R.y) / bondLength)) + 1; int xmin = static_cast<int>(floorf(L.x / bondLength / a1.x)) - 1; int xmax = static_cast<int>(ceilf(R.x / bondLength / a1.x - a2.x * ymax)) + 1; std::map<std::tuple<int, int, int>, int> clippedAtoms; float Rlen = R.length(); float Llen = L.length(); float eps = 0.0001f; for (int y = ymin; y <= ymax; y++) for (int x = xmin; x <= xmax; x++) { // process hexagon atoms gameplay::Vector2 hexagonCenter(x * bondLength * a1.x + a2.x * y * bondLength, y * bondLength * a2.y); // process only two hexagon's atoms // these are unique to hexagon // the rest will be processed by other hexagons // each atom then can be uniquely defined by hexagon coordinates (x, y) and one index (0-1) for (int i = 0; i < 2; i++) { float phi = MATH_PI / 6.0f + MATH_PI / 3.0f * i; gameplay::Vector2 atomPosition(cosf(phi), sinf(phi)); atomPosition = hexagonCenter + atomPosition * bondLength; // clip atoms by square defined by R and L vectors float u = gameplay::Vector2::dot(atomPosition, R) / Rlen; float v = gameplay::Vector2::dot(atomPosition, L) / Llen; if (u >= -eps && v >= -eps && u < Rlen - eps && v < Llen - eps) { clippedAtoms.insert(std::make_pair(std::make_tuple(x, y, i), static_cast<int>(atoms.size()))); atoms.push_back({ 1, 0.0f, gameplay::Vector3(u, v, 0.0f) }); //atoms.push_back({ 1, 0.0f, gameplay::Vector3(atomPosition.x, atomPosition.y, 0.0f) }); } } } std::vector<std::tuple<int, int, int>> unboundAtoms; // check links for (auto it = clippedAtoms.begin(), end_it = clippedAtoms.end(); it != end_it; it++) { int x = std::get<0>((*it).first); int y = std::get<1>((*it).first); if (std::get<2>((*it).first) == 0) { auto next = clippedAtoms.find(std::make_tuple(x, y, 1)); if (next != clippedAtoms.end()) links.push_back({ (*it).second, (*next).second, 1 }); else unboundAtoms.push_back((*it).first); next = clippedAtoms.find(std::make_tuple(x, y - 1, 1)); if (next != clippedAtoms.end()) links.push_back({ (*it).second, (*next).second, 1 }); else unboundAtoms.push_back((*it).first); next = clippedAtoms.find(std::make_tuple(x + 1, y, 1)); if (next != clippedAtoms.end()) links.push_back({ (*it).second, (*next).second, 1 }); else unboundAtoms.push_back((*it).first); } } // bend graphene if (transition > 0.0f) { for (auto it = atoms.begin(), end_it = atoms.end(); it != end_it; it++) { float radius = R.length() / MATH_PIX2 / transition; float phi = (*it).pos.x / radius; (*it).pos.x = radius * sinf(phi); (*it).pos.z = radius * cosf(phi); } } // add new links //for (auto it = unboundAtoms.begin(), end_it = unboundAtoms.end(); it != end_it; it++) //{ // auto first = clippedAtoms.find(std::make_tuple(x, y, 0)); // if (first != clippedAtoms.end()) // { // auto next = clippedAtoms.find(std::make_tuple(x, y, 1)); // if (next == clippedAtoms.end()) // { // for (int x1 = xmax; x1 > x; x1--) // { // auto last = clippedAtoms.find(std::make_tuple(x1, y, 1)); // if (last != clippedAtoms.end()) // { // links.push_back({ (*first).second, (*last).second, 1 }); // break; // } // } // } // next = clippedAtoms.find(std::make_tuple(x, y - 1, 1)); // if (next == clippedAtoms.end()) // { // for (int x1 = xmin; x1 < x; x1++ ) // { // auto last = clippedAtoms.find(std::make_tuple(x1, y - 1, 1)); // if (last != clippedAtoms.end()) // { // links.push_back({ (*first).second, (*last).second, 1 }); // break; // } // } // } // next = clippedAtoms.find(std::make_tuple(x + 1, y, 1)); // if (next == clippedAtoms.end()) // { // for (int x1 = xmin; x1 < x; x1++) // { // auto last = clippedAtoms.find(std::make_tuple(x1, y, 1)); // if (last != clippedAtoms.end()) // { // links.push_back({ (*first).second, (*last).second, 1 }); // break; // } // } // } // } //} }
int main(){ int testcount = 1; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " --- default constructor : \n"; std::cout << "AMP a1;\n"; AMP a1; std::cout << a1.GetStats("a1"); mpfr_t m1; mpfr_init2(m1, 200); std::string sm1 = ".4289752083091740193840376037104709136407130583909742058139425891364961384691827392735927503872508358392040183748013740812740827410871"; mpfr_set_str(m1, sm1.c_str(), 10, MPFR_RNDN); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " --- AMP(mpfr_t m1) Constructor : \n"; std::cout << "AMP a2(m1);\n"; AMP a2(m1); std::cout << a2.GetStats("a2"); std::string sm2 = ".5829639709248056731870470984209830741072392174087420580329850983409137083472102754084092850236497126478518735401842097649285703124830186489724091709248102948618305714701836593872048267529637108243258794872015627398140932976481648923740381740"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " --- AMP(std::string s, int base, int prec) Constructor : \n"; std::cout << "AMP a3(sm2, 10, 320);\n"; AMP a3(sm2, 10, 1024); std::cout << a3.GetStats("a3"); AMP a4(.1750284075032985); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " --- AMP(double d) Constructor : \n"; std::cout << "AMP a4(.1750284075032985);\n"; std::cout << a4.GetStats("a4"); std::cout << "\n*******************\n\n"; std::cout << "Constructors are all successful.\n"; std::cout << "\n\nTesting Inspectors / Getters.\n\n"; std::cout << "Testing a3.GetD() : " << *a3.GetD() << "\n\n" << "Testing a3.GetMP() : \n" << *a3.GetMP() << "\n\n" << "Testing a3.GetPrecisionB() : " << a3.GetPrecisionB() << "\n\n" << "Testing a3.GetPrecision() : " << a3.GetPrecision() << "\n\n"; std::cout << "Testing Inspectors are all succesful.\n"; std::cout << "\n\nTesting Modifiers / Setters.\n\n"; AMP a100(a3); std::cout << "Testing a100.SetPrecision(int) : a100.SetPrecision(400);\n"; std::cout << a100.GetStats("a100") << "\n\n"; a100.SetPrecision(400); std::cout << a100.GetStats("a100") << "\n\n"; std::cout << "Testing a100.SetPrecision(mp_prec_t) : a100.SetPrecision(mpfr_get_prec(a3));\n"; a100.SetPrecision(mpfr_get_prec(*a3.GetMP())); std::cout << a100.GetStats("a100") << "\n\n"; std::cout << "Testing a100.SetPrecision(int) -- move to hardware precision : a100.SetPrecision(HARDWARE_PRECISION);\n"; a100.SetPrecision(HARDWARE_PRECISION); std::cout << a100.GetStats("a100") << "\n\n"; std::cout << "***********************\n\n"; std::cout << "Testing a1.Set(double) : a1.Set(.1894724908572);\n\n"; a1.Set(.1894724908572); std::cout << a1.GetStats("a1"); std::cout << "Testing a1.Set(mpfr_t) : a1.Set(m1);\n\n"; a1.Set(m1); std::cout << a1.GetStats("a1") << "\n"; std::cout << "Testing a1.Set(std::string str, int base, int prec) : a1.Set(sm3, 10, 1024); \n"; std::string sm3 = ".689639782987492570298395720689350927503297598163249817649217407035927059732057320562308945732057209347309587092375095327509372438193469185703298515896139058029467903570329582305790"; a1.Set(sm3, 10, 1024); std::cout << a1.GetStats("a1") << "\n"; std::cout << "Testing = assignment operator : a5 = a1; \n"; AMP a5; a5 = a1; std::cout << a5.GetStats("a5"); std::cout << "Assignment = operator successful.\n\n"; std::cout << "Testing << insertion operator. \n\n"; std::cout << "a1 = " << a1 << "\n\n" << "a2 = " << a2 << "\n\n" << "a3 = " << a3 << "\n\n" << "a4 = " << a4 << "\n\n" << "a5 = " << a5 << "\n\n"; std::cout << " << insertion operator successful.\n\n" << "********************\n\n"; std::cout << "Testing arithmetic operations. \n\n"; std::cout << "********************\n\n"; std::cout << "Testing Addition.\n\n"; std::cout << "********************\n\n"; std::cout << "Testing AMP + AMP (double + double) : AMP a6 = a4 + a4; \n\n"; AMP a6 = a4 + a4; std::cout << a4.GetStats("a4") << "\n\n"; std::cout << a6.GetStats("a6") << "\n\n"; std::cout << "Testing AMP + double (double + double) : AMP a7 = a4 + 3.2; \n\n"; AMP a7 = a4 + 3.2; std::cout << a4.GetStats("a4") << "\n\n" << a7.GetStats("a7") << "\n\n"; std::cout << "Testing double + AMP (double + double) : AMP a8 = 2.5 + a4; \n\n"; AMP a8 = 2.5 + a4; std::cout << a4.GetStats("a4") << "\n\n" << a8.GetStats("a8") << "\n\n"; std::cout << "Testing AMP + AMP (double + MP) : AMP a9 = a8 + a5;\n\n"; AMP a9 = a8 + a5; std::cout << a8.GetStats("a8") << "\n\n" << a5.GetStats("a5") << "\n\n" << a9.GetStats("a9") << "\n\n"; std::cout << "Testing AMP + AMP (MP + double) : AMP a10 = a3 + a7;\n\n"; AMP a10 = a3 + a7; std::cout << a3.GetStats("a3") << "\n\n" << a7.GetStats("a7") << "\n\n" << a10.GetStats("a10") << "\n\n"; std::cout << "Testing AMP + AMP (MP + MP) : AMP a11 = a2 + a3; \n\n"; AMP a11 = a2 + a3; std::cout << a2.GetStats("a2") << "\n\n" << a3.GetStats("a3") << "\n\n" << a11.GetStats("a11") << "\n\n"; std::cout << "Testing AMP + double (MP + double) : AMP a12 = a2 + 4.2\n\n"; AMP a12 = a2 + 4.2; std::cout << a2.GetStats("a2") << "\n\n" << a12.GetStats("a12") << "\n\n"; std::cout << "Testing double + AMP (double + MP) : AMP a13 = 1.4 + a2;\n\n"; AMP a13 = 1.4 + a2; std::cout << a2.GetStats("a2") << "\n\n"; std::cout << a13.GetStats("a13") << "\n\n"; std::cout << "********************\n\n"; std::cout << "Testing Subtraction.\n\n"; std::cout << "********************\n\n"; std::cout << "Testing AMP - AMP (double - double) : AMP a14 = a8 - a4; \n\n"; AMP a14 = a8 - a4; std::cout << a8.GetStats("a8") << "\n\n"; std::cout << a4.GetStats("a4") << "\n\n"; std::cout << a14.GetStats("a14") << "\n\n"; std::cout << "Testing AMP - double (double - double) : AMP a15 = a4 - 3.2; \n\n"; AMP a15 = a4 - 3.2; std::cout << a4.GetStats("a4") << "\n\n" << a15.GetStats("a15") << "\n\n"; std::cout << "Testing double - AMP (double - double) : AMP a16 = 2.5 - a4; \n\n"; AMP a16 = 2.5 - a4; std::cout << a4.GetStats("a4") << "\n\n" << a16.GetStats("a16") << "\n\n"; std::cout << "Testing AMP - AMP (double - MP) : AMP a17 = a8 - a5;\n\n"; AMP a17 = a8 - a5; std::cout << a8.GetStats("a8") << "\n\n" << a5.GetStats("a5") << "\n\n" << a17.GetStats("a17") << "\n\n"; std::cout << "Testing AMP - AMP (MP - double) : AMP a18 = a3 - a7;\n\n"; AMP a18 = a3 - a7; std::cout << a3.GetStats("a3") << "\n\n" << a7.GetStats("a7") << "\n\n" << a18.GetStats("a18") << "\n\n"; std::cout << "Testing AMP - AMP (MP - MP) : AMP a19 = a2 - a3; \n\n"; AMP a19 = a2 - a3; std::cout << a2.GetStats("a2") << "\n\n" << a3.GetStats("a3") << "\n\n" << a19.GetStats("a19") << "\n\n"; std::cout << "Testing AMP - double (MP - double) : AMP a20 = a2 - 4.2\n\n"; AMP a20 = a2 - 4.2; std::cout << a2.GetStats("a2") << "\n\n" << a20.GetStats("a20") << "\n\n"; std::cout << "Testing double - AMP (double - MP) : AMP a21 = 1.4 - a2;\n\n"; AMP a21 = 1.4 - a2; std::cout << a2.GetStats("a2") << "\n\n"; std::cout << a21.GetStats("a21") << "\n\n"; std::cout << "********************\n\n"; std::cout << "Testing Multiplication.\n\n"; std::cout << "********************\n\n"; std::cout << "Testing AMP * AMP (double * double) : AMP a22 = a8 * a4; \n\n"; AMP a22 = a8 * a4; std::cout << a8.GetStats("a8") << "\n\n"; std::cout << a4.GetStats("a4") << "\n\n"; std::cout << a22.GetStats("a22") << "\n\n"; std::cout << "Testing AMP * double (double * double) : AMP a23 = a4 * 3.2; \n\n"; AMP a23 = a4 * 3.2; std::cout << a4.GetStats("a4") << "\n\n" << a23.GetStats("a23") << "\n\n"; std::cout << "Testing double * AMP (double * double) : AMP a24 = 2.5 * a4; \n\n"; AMP a24 = 2.5 * a4; std::cout << a4.GetStats("a4") << "\n\n" << a24.GetStats("a24") << "\n\n"; std::cout << "Testing AMP * AMP (double * MP) : AMP a25 = a8 * a5;\n\n"; AMP a25 = a8 * a5; std::cout << a8.GetStats("a8") << "\n\n" << a5.GetStats("a5") << "\n\n" << a25.GetStats("a25") << "\n\n"; std::cout << "Testing AMP * AMP (MP * double) : AMP a26 = a3 * a7;\n\n"; AMP a26 = a3 * a7; std::cout << a3.GetStats("a3") << "\n\n" << a7.GetStats("a7") << "\n\n" << a26.GetStats("a26") << "\n\n"; std::cout << "Testing AMP * AMP (MP * MP) : AMP a27 = a2 * a3; \n\n"; AMP a27 = a2 * a3; std::cout << a2.GetStats("a2") << "\n\n" << a3.GetStats("a3") << "\n\n" << a27.GetStats("a27") << "\n\n"; std::cout << "Testing AMP * double (MP * double) : AMP a28 = a2 * 4.2\n\n"; AMP a28 = a2 * 4.2; std::cout << a2.GetStats("a2") << "\n\n" << a28.GetStats("a28") << "\n\n"; std::cout << "Testing double * AMP (double * MP) : AMP a29 = 1.4 * a2;\n\n"; AMP a29 = 1.4 * a2; std::cout << a2.GetStats("a2") << "\n\n"; std::cout << a29.GetStats("a29") << "\n\n"; std::cout << "********************\n\n"; std::cout << "Testing Division.\n\n"; std::cout << "********************\n\n"; std::cout << "Testing AMP / AMP (double / double) : AMP a30 = a8 / a4; \n\n"; AMP a30 = a8 / a4; std::cout << a8.GetStats("a8") << "\n\n"; std::cout << a4.GetStats("a4") << "\n\n"; std::cout << a22.GetStats("a22") << "\n\n"; std::cout << "Testing AMP / double (double / double) : AMP a31 = a4 / 3.2; \n\n"; AMP a31 = a4 / 3.2; std::cout << a4.GetStats("a4") << "\n\n" << a31.GetStats("a31") << "\n\n"; std::cout << "Testing double / AMP (double / double) : AMP a32 = 2.5 / a4; \n\n"; AMP a32 = 2.5 / a4; std::cout << a4.GetStats("a4") << "\n\n" << a32.GetStats("a32") << "\n\n"; std::cout << "Testing AMP / AMP (double / MP) : AMP a33 = a8 / a5;\n\n"; AMP a33 = a8 / a5; std::cout << a8.GetStats("a8") << "\n\n" << a5.GetStats("a5") << "\n\n" << a33.GetStats("a33") << "\n\n"; std::cout << "Testing AMP / AMP (MP / double) : AMP a34 = a3 / a7;\n\n"; AMP a34 = a3 / a7; std::cout << a3.GetStats("a3") << "\n\n" << a7.GetStats("a7") << "\n\n" << a34.GetStats("a34") << "\n\n"; std::cout << "Testing AMP / AMP (MP / MP) : AMP a35 = a2 / a3; \n\n"; AMP a35 = a2 / a3; std::cout << a2.GetStats("a2") << "\n\n" << a3.GetStats("a3") << "\n\n" << a35.GetStats("a35") << "\n\n"; std::cout << "Testing AMP / double (MP / double) : AMP a36 = a2 / 4.2\n\n"; AMP a36 = a2 / 4.2; std::cout << a2.GetStats("a2") << "\n\n" << a36.GetStats("a36") << "\n\n"; std::cout << "Testing double / AMP (double / MP) : AMP a37 = 1.4 / a2;\n\n"; AMP a37 = 1.4 / a2; std::cout << a2.GetStats("a2") << "\n\n"; std::cout << a37.GetStats("a37") << "\n\n"; std::ofstream fout("results_amp"); fout << a1 << "\n" << a2 << "\n" << a3 << "\n" << a4 << "\n" << a5 << "\n" << a6 << "\n" << a7 << "\n" << a8 << "\n" << a9 << "\n" << a10 << "\n" << a11 << "\n" << a12 << "\n" << a13 << "\n" << a14 << "\n" << a15 << "\n" << a16 << "\n" << a17 << "\n" << a18 << "\n" << a19 << "\n" << a20 << "\n" << a21 << "\n" << a22 << "\n" << a23 << "\n" << a24 << "\n" << a25 << "\n" << a26 << "\n" << a27 << "\n" << a28 << "\n" << a29 << "\n" << a30 << "\n" << a31 << "\n" << a32 << "\n" << a33 << "\n" << a34 << "\n" << a35 << "\n" << a36 << "\n" << a37 << "\n"; /* std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- default constructor \n\n"; AMP a1; std::cout << "Successful default constructor for a1 'AMP A1;'.\n\n"; std::cout << "a1 = " << a1 << "\n"; std::cout << "a1.GetPrecision() = " << a1.GetPrecision() << "\n\n"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- double constructor \n\n"; AMP a2(2480.7931); std::cout << "Successful double constructor. 'AMP a2(2480.7931);'\n\n"; std::cout << "a2 = " << a2 << "\n"; std::cout << "a2.GetPrecision() = " << a2.GetPrecision() << "\n\n"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- mp(string, int,int) constructor \n\n"; AMP a3(".1390840284091369752084027084016871936786481647908452428080313686", 10, 200); std::cout << "Successful mp (string, int, int) constructor. 'AMP a3(\".1390840284091369752084027084016871936786481647908452428080313686\", 10, 200);' \n\n"; std::cout << a3 << "\n\n"; std::cout << "a3.GetPrecision() = " << a3.GetPrecision() << "\n\n"; mpfr_t tmp; mpfr_init2(tmp, 100); mpfr_set_str(tmp, ".42975902804123819697520840729410370173905782749129317491707408952080428768462189421798301804261", 10, MPFR_RNDN); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- AMP(mpfr_t m) constructor \n\n"; AMP a4(tmp); std::cout << "Successful AMP (mpfr_t m) constructor. \n"; std::cout << "' mpfr_t tmp;\nmpfr_init2(tmp, 100);\nmpfr_set_str(tmp, \".42975902804123819697520840729410370173905782749129317491707408952080428768462189421798301804261\", 10, MPFR_RNDN);" << "\nAMP a4(tmp)\n\n"; std::cout << "a4 = " << a4 << "\n"; std::cout << "a4.GetPrecision() = " << a4.GetPrecision() << "\n"; mpfr_clear(tmp); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- Set(double d) \n\n"; a1.Set(.973100428183079789); std::cout << "successful a1.Set(double d): 'a1.Set(.973100428183079789)'\n"; std::cout << "a1 = " << a1 << "\n" << "a1.GetPrecision() = " << a1.GetPrecision() << "\n"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- Set(mpfr_t m) \n\n"; AMP a45; mpfr_t m; mpfr_init2(m, 180); mpfr_set_str(m, ".920476107502730816407810360957203649318725896391601836480123806013847981365897102476031847028658021740164087421047036850174230271047919024707310957093754276593164", 10, MPFR_RNDN); a45.Set(m); std::cout << "successful a45.Set(mpfr_t m): 'a45.Set(m)'\n"; std::cout << "a45 = " << a45 << "\n" << "a45.GetPrecision() = " << a45.GetPrecision() << "\n"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- move to higher precision from hardware -- \n\n"; // test moving up in precision a1.SetPrecision(96); std::cout << "successful SetPrecision(int prec) from hardware precision to multiprecision: ' a1.SetPrecision(96);'\n'" << "a1 = " << a1 << "\na1.GetPrecision() = " << a1.GetPrecision() << "\n"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- assignment = operator \n\n"; AMP a0 = a3; std::cout << "a0 = " << a0 << "\na0.GetPrecision() = " << a0.GetPrecision() << "\n" << "a0.GetPrecisionB() = " << a0.GetPrecisionB() << "\n" << "a3 = " << a3 << "\na3.GetPrecision() = " << a3.GetPrecision() << "\n" << "a3.GetPrecisionB() = " << a3.GetPrecisionB() << "\n"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- move to lower precision from multiprecision \n\n"; a3.SetPrecision(64); std::cout << "successful SetPrecision(int prec) from multiprecision to hardware precision: ' a3.SetPrecision(64);'\n" << "a3 = " << a3 << "\n" << "a3.GetPrecision() = " << a3.GetPrecision() << "\n" << "\na0 should not have changed.\n\n" << "a0 = " << a0 << "\na0.GetPrecision() = " << a0.GetPrecision() << "\n" << "a0.GetPrecisionB() = " << a0.GetPrecisionB() << "\n"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- hardware precision to hardware precision \n\n"; a2.SetPrecision(3); std::cout << "successful SetPrecision(int) : 'a2.SetPrecision(3)'\n"; std::cout << "a2 = " << a2 << "\n" << "a2.GetPrecision() = " << a2.GetPrecision() << "\n"; std::cout << "\n*******************\n\n"; std::cout << "\n\naddition tests \n\n"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- assignment = operator and + operator (hardware precision) \n\n"; AMP a5 = a2 + a3; std::cout << "successful assignment = operator and + operator (hardware_precision): 'AMP a5 = a2 + a3;'\n"; std::cout << "a5 = " << a5 << "\n" << "a5.GetPrecision() = " << a5.GetPrecision() << "\n"; std::cout //<< "a2.GetPrecisionB() = " << a2.GetPrecisionB() //<< ", a3.GetPrecisionB() = " << a3.GetPrecisionB() << ((a2.GetPrecisionB() || a3.GetPrecisionB()) == 0 ? " -- both are hardware\n" : " -- one or both is mp\n"); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- + operator (mp + hardware) \n\n"; AMP a6 = a1 + a5; std::cout << "successful + operator : left operand is mp, right operand is hardware: 'AMP a6 = a1 + a5;'\n" << "a6 = " << a6 << "\n" << "a6.GetPrecision() = " << a6.GetPrecision() << "\n" << (a1.GetPrecisionB() == 0 ? "left operand is hardware. " : "left operand is mp. ") << (a5.GetPrecisionB() == 0 ? "right operand is hardware. " : "right operand is mp. ") << ((a1.GetPrecisionB() || a5.GetPrecisionB()) == 0 ? "hardware addition performed.\n" : "mp addition performed.\n"); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- + operator (hardware + mp) \n\n"; AMP a7 = a5 + a1; std::cout << "successful + operator : left operand is hardware, right operand is mp: 'AMP a6 = a1 + a5;'\n" << "a7 = " << a7 << "\n" << "a7.GetPrecision() = " << a7.GetPrecision() << "\n" << (a5.GetPrecisionB() == 0 ? "left operand is hardware. " : "left operand is mp. ") << (a1.GetPrecisionB() == 0 ? "right operand is hardware. " : "right operand is mp. ") << ((a5.GetPrecisionB() || a1.GetPrecisionB()) == 0 ? "hardware addition performed.\n" : "mp addition performed.\n"); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- + operator (mp + mp) \n\n"; AMP a8 = a1 + a0; std::cout << "successful + operator : left operand is mp, right operand is mp: 'AMP a8 = a1 + a0;'\n" << "a8 = " << a8 << "\na8.GetPrecision() = " << a8.GetPrecision() << "\n" << (a1.GetPrecisionB() == 0 ? "left operand is hardware. " : "left operand is mp. ") << (a0.GetPrecisionB() == 0 ? "right operand is hardware. " : "right operand is mp. ") << ((a1.GetPrecisionB() || a0.GetPrecisionB()) == 0 ? "hardware addition performed.\n" : "mp addition performed.\n"); std::cout << "\n\nsubtraction tests \n\n"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- - operator (hardware precision) \n\n"; AMP a9 = a2 - a3; std::cout << "successful - operator (hardware_precision): 'AMP a9 = a2 + a3;'\n"; std::cout << "a9 = " << a9 << "\n" << "a9.GetPrecision() = " << a9.GetPrecision() << "\n"; std::cout //<< "a2.GetPrecisionB() = " << a2.GetPrecisionB() //<< ", a3.GetPrecisionB() = " << a3.GetPrecisionB() << ((a2.GetPrecisionB() || a3.GetPrecisionB()) == 0 ? " -- both are hardware\n" : " -- one or both is mp\n"); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- - operator (mp - hardware) \n\n"; AMP a10 = a1 - a5; std::cout << "successful - operator : left operand is mp, right operand is hardware: 'AMP a10 = a1 - a5;'\n" << "a10 = " << a10 << "\n" << "a10.GetPrecision() = " << a10.GetPrecision() << "\n" << (a1.GetPrecisionB() == 0 ? "left operand is hardware. " : "left operand is mp. ") << (a5.GetPrecisionB() == 0 ? "right operand is hardware. " : "right operand is mp. ") << ((a1.GetPrecisionB() || a5.GetPrecisionB()) == 0 ? "hardware subtraction performed.\n" : "mp subtraction performed.\n"); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- - operator (hardware + mp) \n\n"; AMP a11 = a5 - a1; std::cout << "successful - operator : left operand is hardware, right operand is mp: 'AMP a11 = a5 - a1;'\n" << "a11 = " << a11 << "\n" << "a11.GetPrecision() = " << a11.GetPrecision() << "\n" << (a5.GetPrecisionB() == 0 ? "left operand is hardware. " : "left operand is mp. ") << (a1.GetPrecisionB() == 0 ? "right operand is hardware. " : "right operand is mp. ") << ((a5.GetPrecisionB() || a1.GetPrecisionB()) == 0 ? "hardware subtraction performed.\n" : "mp subtraction performed.\n"); std::cout << "Here\n"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- - operator (mp - mp) \n\n"; AMP a12 = a1 - a0; std::cout << "successful - operator : left operand is mp, right operand is mp: 'AMP a12 = a1 - a0;'\n" << "a12 = " << a12 << "\na12.GetPrecision() = " << a12.GetPrecision() << "\n" << (a1.GetPrecisionB() == 0 ? "left operand is hardware. " : "left operand is mp. ") << (a0.GetPrecisionB() == 0 ? "right operand is hardware. " : "right operand is mp. ") << ((a1.GetPrecisionB() || a0.GetPrecisionB()) == 0 ? "hardware subtraction performed.\n" : "mp subtraction performed.\n"); std::cout << "\n\nmultiplication tests\n\n"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- * operator (hardware precision) \n\n"; AMP a13 = a2 * a3; std::cout << "successful * operator (hardware_precision): 'AMP a13 = a2 * a3;'\n"; std::cout << "a13 = " << a13 << "\n" << "a13.GetPrecision() = " << a13.GetPrecision() << "\n"; std::cout //<< "a2.GetPrecisionB() = " << a2.GetPrecisionB() //<< ", a3.GetPrecisionB() = " << a3.GetPrecisionB() << ((a2.GetPrecisionB() || a3.GetPrecisionB()) == 0 ? " -- both are hardware\n" : " -- one or both is mp\n"); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- * operator (mp * hardware) \n\n"; AMP a14 = a1 * a5; std::cout << "successful * operator : left operand is mp, right operand is hardware: 'AMP a14 = a1 * a5;'\n"; std::cout << "HERE\n\n"; std::cout << "a14 = " << a14 << "\n" << "a14.GetPrecision() = " << a14.GetPrecision() << "\n"; std::cout << "\n\nHERE\n\n"; std::cout << (a1.GetPrecisionB() == 0 ? "left operand is hardware. " : "left operand is mp. "); std::cout << (a5.GetPrecisionB() == 0 ? "right operand is hardware. " : "right operand is mp. "); std::cout << ((a1.GetPrecisionB() || a5.GetPrecisionB()) == 0 ? "hardware multiplication performed.\n" : "mp multiplication performed.\n"); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- * operator (hardware * mp) \n\n"; AMP a15 = a5 * a1; std::cout << "successful * operator : left operand is hardware, right operand is mp: 'AMP a15 = a5 * a1;'\n" << "a15 = " << a15 << "\n" << "a15.GetPrecision() = " << a15.GetPrecision() << "\n" << (a5.GetPrecisionB() == 0 ? "left operand is hardware. " : "left operand is mp. ") << (a1.GetPrecisionB() == 0 ? "right operand is hardware. " : "right operand is mp. ") << ((a5.GetPrecisionB() || a1.GetPrecisionB()) == 0 ? "hardware multiplication performed.\n" : "mp multiplication performed.\n"); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- * operator (mp * mp) \n\n"; AMP a16 = a1 * a0; std::cout << "successful * operator : left operand is mp, right operand is mp: 'AMP a16 = a1 * a0;'\n" << "a16 = " << a16 << "\na16.GetPrecision() = " << a8.GetPrecision() << "\n" << (a1.GetPrecisionB() == 0 ? "left operand is hardware. " : "left operand is mp. ") << (a0.GetPrecisionB() == 0 ? "right operand is hardware. " : "right operand is mp. ") << ((a1.GetPrecisionB() || a0.GetPrecisionB()) == 0 ? "hardware multiplication performed.\n" : "mp multiplication performed.\n"); std::cout << "\n\ndivision tests\n\n"; std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- / operator (hardware precision) \n\n"; AMP a17 = a2 / a3; std::cout << "successful / operator (hardware_precision): 'AMP a17 = a2 / a3;'\n"; std::cout << "a17 = " << a17 << "\n" << "a17.GetPrecision() = " << a17.GetPrecision() << "\n"; std::cout //<< "a2.GetPrecisionB() = " << a2.GetPrecisionB() //<< ", a3.GetPrecisionB() = " << a3.GetPrecisionB() << ((a2.GetPrecisionB() || a3.GetPrecisionB()) == 0 ? " -- both are hardware\n" : " -- one or both is mp\n"); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- / operator (mp / hardware) \n\n"; AMP a18 = a1 / a5; std::cout << "successful / operator : left operand is mp, right operand is hardware: 'AMP a18 = a1 / a5;'\n" << "a18 = " << a18 << "\n" << "a18.GetPrecision() = " << a18.GetPrecision() << "\n" << (a1.GetPrecisionB() == 0 ? "left operand is hardware. " : "left operand is mp. ") << (a5.GetPrecisionB() == 0 ? "right operand is hardware. " : "right operand is mp. ") << ((a1.GetPrecisionB() || a5.GetPrecisionB()) == 0 ? "hardware division performed.\n" : "mp division performed.\n"); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- / operator (hardware / mp) \n\n"; AMP a19 = a5 / a1; std::cout << "successful / operator : left operand is hardware, right operand is mp: 'AMP a19 = a5 / a1;'\n" << "a19 = " << a19 << "\n" << "a19.GetPrecision() = " << a19.GetPrecision() << "\n" << (a5.GetPrecisionB() == 0 ? "left operand is hardware. " : "left operand is mp. ") << (a1.GetPrecisionB() == 0 ? "right operand is hardware. " : "right operand is mp. ") << ((a5.GetPrecisionB() || a1.GetPrecisionB()) == 0 ? "hardware division performed.\n" : "mp division performed.\n"); std::cout << "\n*******************\n\n"; std::cout << "Test " << testcount++ << " -- / operator (mp mp) \n\n"; AMP a20 = a1 / a0; std::cout << "successful / operator : left operand is mp, right operand is mp: 'AMP a20 = a1 / a0;'\n" << "a20 = " << a20 << "\na20.GetPrecision() = " << a20.GetPrecision() << "\n" << (a1.GetPrecisionB() == 0 ? "left operand is hardware. " : "left operand is mp. ") << (a0.GetPrecisionB() == 0 ? "right operand is hardware. " : "right operand is mp. ") << ((a1.GetPrecisionB() || a0.GetPrecisionB()) == 0 ? "hardware division performed.\n" : "mp division performed.\n"); */ return 0; }
int main() { cout << "以下实验是规定了Document的值,测试时可以自行改变其值与测试内容" << endl; char b1[5] = { 'i', '9', '5', ',', 's' }; Line a1 (b1, b1 + 5); char b2[7] = { ' ', 'c', 'r', 'l', ' ','c','o' }; Line a2(b2,b2+7); char b3[6] = { '8','w', ' ', 'l', '*', 'l'}; Line a3(b3, b3 + 6); list<Line>answer; answer.push_back(a1); answer.push_back(a2); answer.push_back(a3); Document my_doc(answer); Document tmp = my_doc; cout << "原来文件为:" << endl; print(tmp); cout << endl; cout << "文件的字符数为:" << number(tmp) << endl; cout << "文件的字数为(根据第一种算法):" << number1(tmp) << endl; cout << "其中字母序列(第二种算法):" << number2(tmp)<<endl; const string pre= "i7"; cout << "查找单词为:" << pre<<endl; Text_iterator p = find_text(tmp, pre); if (p==tmp.end() ) { cout << "不存在该单词" << endl; } else { cout << "存在该单词" << endl; int length = pre.length(); string now = "wa56 ker"; cout << "替换为:" << now << endl; cout << "替换后的文件为:" << endl; p.change(length, now); print(tmp); cout << endl; cout << "文件的字符数为:" << number(tmp) << endl; cout << "文件的字数为(根据第一种算法):" << number1(tmp) << endl; cout << "其中字母序列(第二种算法):" << number2(tmp) << endl; } tmp = my_doc; string pres = "crl"; cout << "查找单词为:" << pres << endl; Text_iterator s = find_text(tmp, pres); if (s == tmp.end()) { cout << "不存在该单词" << endl; } else { cout << "存在该单词" << endl; int length = pres.length(); string now = "wa56 er"; cout << "替换为:" << now << endl; cout << "替换后的文件为:" << endl; s.change(length, now); print(tmp); cout << endl; cout << "文件的字符数为:" << number(tmp) << endl; cout << "文件的字数为(根据第一种算法):" << number1(tmp) << endl; cout << "其中字母序列(第二种算法):" << number2(tmp) << endl; } getchar(); getchar(); getchar(); }
std::tuple<bool, vector, float, vector, vector> shape::distance(shape const& shape) const { vector direction(shape.centroid() - centroid()); vector a1(vertices_[support(direction)]); vector a2(shape.vertices()[shape.support(-direction)]); vector a(a1 - a2); vector b1(vertices_[support(-direction)]); vector b2(shape.vertices()[shape.support(direction)]); vector b(b1 - b2); vector c1, c2, c; direction = segment(b, a).closest(vector()); for(int unsigned iterations(0); iterations < 10; ++iterations) { direction = -direction.normalize(); if(!direction) return std::make_tuple(false, vector(), 0.0f, vector(), vector()); c1 = vertices_[support(direction)]; c2 = shape.vertices()[shape.support(-direction)]; c = c1 - c2; if(a.cross(b) * b.cross(c) > 0.0f && a.cross(b) * c.cross(a) > 0.0f) return std::make_tuple(false, vector(), 0.0f, vector(), vector()); float const projection(c.dot(direction)); if(projection - a.dot(direction) < std::sqrt(std::numeric_limits<float>::epsilon())) { std::tuple<vector, vector> const closest_points(get_closest_points(a1, a2, a, b1, b2, b)); return std::make_tuple(true, direction, -projection, std::get<0>(closest_points), std::get<1>(closest_points)); } vector const point1(segment(a, c).closest(vector())); vector const point2(segment(c, b).closest(vector())); float const point1_length(point1.length()); float const point2_length(point2.length()); if(point1_length <= std::numeric_limits<float>::epsilon()) { std::tuple<vector, vector> const closest_points(get_closest_points(a1, a2, a, c1, c2, c)); return std::make_tuple(true, direction, point1_length, std::get<0>(closest_points), std::get<1>(closest_points)); } else if(point2_length <= std::numeric_limits<float>::epsilon()) { std::tuple<vector, vector> const closest_points(get_closest_points(c1, c2, c, b1, b2, b)); return std::make_tuple(true, direction, point2_length, std::get<0>(closest_points), std::get<1>(closest_points)); } if(point1_length < point2_length) { b1 = c1; b2 = c2; b = c; direction = point1; } else { a1 = c1; a2 = c2; a = c; direction = point2; } } std::tuple<vector, vector> const closest_points(get_closest_points(a1, a2, a, b1, b2, b)); return std::make_tuple(true, direction, -c.dot(direction), std::get<0>(closest_points), std::get<1>(closest_points)); }
float f2(float x,float y,float z) { return (f(x)-a1(x)*z-a2(x)*y) / a0(x); }
/************************************************************************* Tests EVD problem *************************************************************************/ static void testevdproblem(const ap::real_1d_array& d, const ap::real_1d_array& e, int n, double& valerr, double& vecerr, bool& wnsorted, int& failc) { ap::real_1d_array lambda; ap::real_1d_array lambdaref; ap::real_2d_array z; ap::real_2d_array zref; ap::real_2d_array a1; ap::real_2d_array a2; ap::real_2d_array ar; bool wsucc; int i; int j; int k; int m; int i1; int i2; double v; double a; double b; lambdaref.setbounds(0, n-1); zref.setbounds(0, n-1, 0, n-1); a1.setbounds(0, n-1, 0, n-1); a2.setbounds(0, n-1, 0, n-1); // // Reference EVD // if( !refevd(d, e, n, lambdaref, zref) ) { failc = failc+1; return; } // // Test different combinations // for(i1 = 0; i1 <= n-1; i1++) { for(i2 = i1; i2 <= n-1; i2++) { // // Select A, B // if( i1>0 ) { a = 0.5*(lambdaref(i1)+lambdaref(i1-1)); } else { a = lambdaref(0)-1; } if( i2<n-1 ) { b = 0.5*(lambdaref(i2)+lambdaref(i2+1)); } else { b = lambdaref(n-1)+1; } // // Test interval, no vectors // lambda.setbounds(0, n-1); for(i = 0; i <= n-1; i++) { lambda(i) = d(i); } if( !smatrixtdevdr(lambda, e, n, 0, a, b, m, z) ) { failc = failc+1; return; } if( m!=i2-i1+1 ) { failc = failc+1; return; } for(k = 0; k <= m-1; k++) { valerr = ap::maxreal(valerr, fabs(lambda(k)-lambdaref(i1+k))); } // // Test indexes, no vectors // lambda.setbounds(0, n-1); for(i = 0; i <= n-1; i++) { lambda(i) = d(i); } if( !smatrixtdevdi(lambda, e, n, 0, i1, i2, z) ) { failc = failc+1; return; } m = i2-i1+1; for(k = 0; k <= m-1; k++) { valerr = ap::maxreal(valerr, fabs(lambda(k)-lambdaref(i1+k))); } // // Test interval, transform vectors // lambda.setbounds(0, n-1); for(i = 0; i <= n-1; i++) { lambda(i) = d(i); } a1.setbounds(0, n-1, 0, n-1); a2.setbounds(0, n-1, 0, n-1); for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a1(i,j) = 2*ap::randomreal()-1; a2(i,j) = a1(i,j); } } if( !smatrixtdevdr(lambda, e, n, 1, a, b, m, a1) ) { failc = failc+1; return; } if( m!=i2-i1+1 ) { failc = failc+1; return; } for(k = 0; k <= m-1; k++) { valerr = ap::maxreal(valerr, fabs(lambda(k)-lambdaref(i1+k))); } ar.setbounds(0, n-1, 0, m-1); for(i = 0; i <= n-1; i++) { for(j = 0; j <= m-1; j++) { v = ap::vdotproduct(a2.getrow(i, 0, n-1), zref.getcolumn(i1+j, 0, n-1)); ar(i,j) = v; } } for(j = 0; j <= m-1; j++) { v = ap::vdotproduct(a1.getcolumn(j, 0, n-1), ar.getcolumn(j, 0, n-1)); if( v<0 ) { ap::vmul(ar.getcolumn(j, 0, n-1), -1); } } for(i = 0; i <= n-1; i++) { for(j = 0; j <= m-1; j++) { vecerr = ap::maxreal(vecerr, fabs(a1(i,j)-ar(i,j))); } } // // Test indexes, transform vectors // lambda.setbounds(0, n-1); for(i = 0; i <= n-1; i++) { lambda(i) = d(i); } a1.setbounds(0, n-1, 0, n-1); a2.setbounds(0, n-1, 0, n-1); for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a1(i,j) = 2*ap::randomreal()-1; a2(i,j) = a1(i,j); } } if( !smatrixtdevdi(lambda, e, n, 1, i1, i2, a1) ) { failc = failc+1; return; } m = i2-i1+1; for(k = 0; k <= m-1; k++) { valerr = ap::maxreal(valerr, fabs(lambda(k)-lambdaref(i1+k))); } ar.setbounds(0, n-1, 0, m-1); for(i = 0; i <= n-1; i++) { for(j = 0; j <= m-1; j++) { v = ap::vdotproduct(a2.getrow(i, 0, n-1), zref.getcolumn(i1+j, 0, n-1)); ar(i,j) = v; } } for(j = 0; j <= m-1; j++) { v = ap::vdotproduct(a1.getcolumn(j, 0, n-1), ar.getcolumn(j, 0, n-1)); if( v<0 ) { ap::vmul(ar.getcolumn(j, 0, n-1), -1); } } for(i = 0; i <= n-1; i++) { for(j = 0; j <= m-1; j++) { vecerr = ap::maxreal(vecerr, fabs(a1(i,j)-ar(i,j))); } } // // Test interval, do not transform vectors // lambda.setbounds(0, n-1); for(i = 0; i <= n-1; i++) { lambda(i) = d(i); } z.setbounds(0, 0, 0, 0); if( !smatrixtdevdr(lambda, e, n, 2, a, b, m, z) ) { failc = failc+1; return; } if( m!=i2-i1+1 ) { failc = failc+1; return; } for(k = 0; k <= m-1; k++) { valerr = ap::maxreal(valerr, fabs(lambda(k)-lambdaref(i1+k))); } for(j = 0; j <= m-1; j++) { v = ap::vdotproduct(z.getcolumn(j, 0, n-1), zref.getcolumn(i1+j, 0, n-1)); if( v<0 ) { ap::vmul(z.getcolumn(j, 0, n-1), -1); } } for(i = 0; i <= n-1; i++) { for(j = 0; j <= m-1; j++) { vecerr = ap::maxreal(vecerr, fabs(z(i,j)-zref(i,i1+j))); } } // // Test interval, do not transform vectors // lambda.setbounds(0, n-1); for(i = 0; i <= n-1; i++) { lambda(i) = d(i); } z.setbounds(0, 0, 0, 0); if( !smatrixtdevdi(lambda, e, n, 2, i1, i2, z) ) { failc = failc+1; return; } m = i2-i1+1; for(k = 0; k <= m-1; k++) { valerr = ap::maxreal(valerr, fabs(lambda(k)-lambdaref(i1+k))); } for(j = 0; j <= m-1; j++) { v = ap::vdotproduct(z.getcolumn(j, 0, n-1), zref.getcolumn(i1+j, 0, n-1)); if( v<0 ) { ap::vmul(z.getcolumn(j, 0, n-1), -1); } } for(i = 0; i <= n-1; i++) { for(j = 0; j <= m-1; j++) { vecerr = ap::maxreal(vecerr, fabs(z(i,j)-zref(i,i1+j))); } } } } }
void ArraysTestCase::wxStringArrayTest() { wxArrayString a1; a1.Add(wxT("thermit")); a1.Add(wxT("condor")); a1.Add(wxT("lion"), 3); a1.Add(wxT("dog")); a1.Add(wxT("human")); a1.Add(wxT("alligator")); CPPUNIT_ASSERT( COMPARE_8_VALUES( a1 , wxT("thermit") , wxT("condor") , wxT("lion") , wxT("lion") , wxT("lion") , wxT("dog") , wxT("human") , wxT("alligator") ) ); CPPUNIT_ASSERT( COMPARE_COUNT( a1 , 8 ) ); wxArrayString a2(a1); CPPUNIT_ASSERT( COMPARE_8_VALUES( a2 , wxT("thermit") , wxT("condor") , wxT("lion") , wxT("lion") , wxT("lion") , wxT("dog") , wxT("human") , wxT("alligator") ) ); CPPUNIT_ASSERT( COMPARE_COUNT( a2 , 8 ) ); wxSortedArrayString a3(a1); CPPUNIT_ASSERT( COMPARE_8_VALUES( a3 , wxT("alligator") , wxT("condor") , wxT("dog") , wxT("human") , wxT("lion") , wxT("lion") , wxT("lion") , wxT("thermit") ) ); CPPUNIT_ASSERT( COMPARE_COUNT( a3 , 8 ) ); wxSortedArrayString a4; for (wxArrayString::iterator it = a1.begin(), en = a1.end(); it != en; ++it) a4.Add(*it); CPPUNIT_ASSERT( COMPARE_8_VALUES( a4 , wxT("alligator") , wxT("condor") , wxT("dog") , wxT("human") , wxT("lion") , wxT("lion") , wxT("lion") , wxT("thermit") ) ); CPPUNIT_ASSERT( COMPARE_COUNT( a4 , 8 ) ); a1.RemoveAt(2,3); CPPUNIT_ASSERT( COMPARE_5_VALUES( a1 , wxT("thermit") , wxT("condor") , wxT("dog") , wxT("human") , wxT("alligator") ) ); CPPUNIT_ASSERT( COMPARE_COUNT( a1 , 5 ) ); a2 = a1; CPPUNIT_ASSERT( COMPARE_5_VALUES( a2 , wxT("thermit") , wxT("condor") , wxT("dog") , wxT("human") , wxT("alligator") ) ); CPPUNIT_ASSERT( COMPARE_COUNT( a2 , 5 ) ); a1.Sort(false); CPPUNIT_ASSERT( COMPARE_5_VALUES( a1 , wxT("alligator") , wxT("condor") , wxT("dog") , wxT("human") , wxT("thermit") ) ); CPPUNIT_ASSERT( COMPARE_COUNT( a1 , 5 ) ); a1.Sort(true); CPPUNIT_ASSERT( COMPARE_5_VALUES( a1 , wxT("thermit") , wxT("human") , wxT("dog") , wxT("condor") , wxT("alligator") ) ); CPPUNIT_ASSERT( COMPARE_COUNT( a1 , 5 ) ); a1.Sort(&StringLenCompare); CPPUNIT_ASSERT( COMPARE_5_VALUES( a1 , wxT("dog") , wxT("human") , wxT("condor") , wxT("thermit") , wxT("alligator") ) ); CPPUNIT_ASSERT( COMPARE_COUNT( a1 , 5 ) ); CPPUNIT_ASSERT( a1.Index( wxT("dog") ) == 0 ); CPPUNIT_ASSERT( a1.Index( wxT("human") ) == 1 ); CPPUNIT_ASSERT( a1.Index( wxT("humann") ) == wxNOT_FOUND ); CPPUNIT_ASSERT( a1.Index( wxT("condor") ) == 2 ); CPPUNIT_ASSERT( a1.Index( wxT("thermit") ) == 3 ); CPPUNIT_ASSERT( a1.Index( wxT("alligator") ) == 4 ); CPPUNIT_ASSERT( a1.Index( wxT("dog"), /*bCase=*/true, /*fromEnd=*/true ) == 0 ); CPPUNIT_ASSERT( a1.Index( wxT("human"), /*bCase=*/true, /*fromEnd=*/true ) == 1 ); CPPUNIT_ASSERT( a1.Index( wxT("humann"), /*bCase=*/true, /*fromEnd=*/true ) == wxNOT_FOUND ); CPPUNIT_ASSERT( a1.Index( wxT("condor"), /*bCase=*/true, /*fromEnd=*/true ) == 2 ); CPPUNIT_ASSERT( a1.Index( wxT("thermit"), /*bCase=*/true, /*fromEnd=*/true ) == 3 ); CPPUNIT_ASSERT( a1.Index( wxT("alligator"), /*bCase=*/true, /*fromEnd=*/true ) == 4 ); wxArrayString a5; CPPUNIT_ASSERT( a5.Add( wxT("x"), 1 ) == 0 ); CPPUNIT_ASSERT( a5.Add( wxT("a"), 3 ) == 1 ); CPPUNIT_ASSERT( COMPARE_4_VALUES( a5, wxT("x") , wxT("a") , wxT("a") , wxT("a") ) ); a5.assign(a1.end(), a1.end()); CPPUNIT_ASSERT( a5.empty() ); a5.assign(a1.begin(), a1.end()); CPPUNIT_ASSERT( a5 == a1 ); const wxString months[] = { "Jan", "Feb", "Mar" }; a5.assign(months, months + WXSIZEOF(months)); CPPUNIT_ASSERT_EQUAL( WXSIZEOF(months), a5.size() ); CPPUNIT_ASSERT( COMPARE_3_VALUES(a5, "Jan", "Feb", "Mar") ); a5.clear(); CPPUNIT_ASSERT_EQUAL( 0, a5.size() ); a5.resize(7, "Foo"); CPPUNIT_ASSERT_EQUAL( 7, a5.size() ); CPPUNIT_ASSERT_EQUAL( "Foo", a5[3] ); a5.resize(3); CPPUNIT_ASSERT_EQUAL( 3, a5.size() ); CPPUNIT_ASSERT_EQUAL( "Foo", a5[2] ); wxArrayString a6; a6.Add("Foo"); a6.Insert(a6[0], 1, 100); wxArrayString a7; a7 = a7; CPPUNIT_ASSERT_EQUAL( 0, a7.size() ); a7.Add("Bar"); a7 = a7; CPPUNIT_ASSERT_EQUAL( 1, a7.size() ); }
void hongocompleto() { int i=0; do{ //for(i=6;i<9;i++) //{ setbkcolor(WHITE); construccion(); ////C setcolor (7); settextstyle (0,0,5); outtextxy (30,50,"C"); ////A setcolor (7); settextstyle (0,0,5); outtextxy (70,55,"A"); /////R setcolor (7); settextstyle (0,0,5); outtextxy (110,50,"R"); /////G setcolor (7); settextstyle (0,0,5); outtextxy (150,55,"G"); /////A setcolor (7); settextstyle (0,0,5); outtextxy (190,50,"A"); /////N setcolor (7); settextstyle (0,0,5); outtextxy (230,55,"N"); /////D setcolor (7); settextstyle (0,0,5); outtextxy (270,50,"D"); /////O setcolor (7); settextstyle (0,0,5); outtextxy (310,55,"O"); c(); //a1(); //r(); //g(); //a2(); //n(); //d(); //o(); //c(); delay(200); cabeza(); a1(); delay(200); ojo(); r(); delay(200); mancha1(); g(); delay(200); mancha2(); a2(); delay(200); mancha3(); n(); delay(200); mancha4(); d(); delay(200); mancha5(); o(); delay(200); //getch(); i=i++; //kbhit(); }while (i<2); //}while (!kbhit()); }