int main(void) { x1(); x2(); x3(); x4(); printf("%d, %d, %d, %u\n", x1(), x2(), x3(), x4()); }
int main(void) { x1(0); x2(0); x3(0); x4(0); printf("%d, %d, %d, %u\n", x1(0), x2(0), x3(0), x4(0)); }
void plop (){ gca :: GCA_vector a (1.0 ,2.0 ,3.0 ,1.0); gca :: GCA_vector b ; b << 3.0 , 2.0 , 1.0 , 1.0; gca :: GCA_bivector l = a ^ b ; // l is a Plucker line std :: cout << "\n--------------- Plucker line ---------------" << std :: endl ; std :: cout << "point ^ point l : " << l << std :: endl ; gca :: GCA_vector x1 (2.0 , -1.0 , -1.0 ,1.0); gca :: GCA_vector x2 (1.0 , -1.0 ,1.0 ,1.0); gca :: GCA_vector x3 ( -1.0 , -1.0 , -2.0 ,1.0); gca :: GCA_trivector d = x1 ^ x2 ^ x3 ; // d is a plane gca :: GCA_trivector p = x1 ^ l ; gca :: GCA_trivector r = x3 ^ l ; std :: cout << "\n--------------- Plans ---------------" << std :: endl ; std :: cout << "point ^ point ^ point d: " << d << std :: endl ; std :: cout << "point ^ droite p: " << p << std :: endl ; std :: cout << "Plan r: " << r << std :: endl ; std :: cout << "\n--------------- Intersections ---------------" << std :: endl ; std :: cout << "plan v plan v plan : " << (~d ^ ~p ^ ~r) << std :: endl ; std :: cout << "plan v droite : " << (~d ^ ~l) << std :: endl ; std :: cout << "plan v plan : " << (~d ^ ~p) << std :: endl ; std :: cout << "\n--------------- Appartenances ---------------" << std :: endl ; std :: cout << "point ^ droite : " << (l ^ a) << std :: endl; std :: cout << "point ^ plan : " << (x1 ^ p) << std :: endl; }
void test() { CXCode x1(CXCode::CHARSET_UTF8); std::string sUTF8 = "abc\xe4\xb8\xad\xe5\x9b\xbd\xe4\xba\xba"; EXPECT_EQ(std::string("abc%u4E2D%u56FD%u4EBA"), CXCode::escape(sUTF8)); EXPECT_EQ(sUTF8, CXCode::unescape(CXCode::escape(sUTF8))); EXPECT_EQ(std::string("abc%u4E2D%u56FD%u4EBA"), CXCode::escape(CXCode::unescape(CXCode::escape(sUTF8)))); EXPECT_EQ(sUTF8, CXCode::unescape((sUTF8))); EXPECT_EQ(std::string("abc%E4%B8%AD%E5%9B%BD%E4%BA%BA"), CXCode::encodeURIComponent(sUTF8)); EXPECT_EQ(std::string("abc\\u4E2D\\u56FD\\u4EBA"), CXCode::encodeJSONComponent(sUTF8)); EXPECT_EQ(std::string("abc中国人"), CXCode::encodeXMLComponent(sUTF8)); std::string sUCS2 = CXCode::UCS2(CXCode::escape(sUTF8)); CXCode x2(CXCode::CHARSET_GBS); std::string sGB="abc\xd6\xd0\xb9\xfa\xc8\xcb"; EXPECT_EQ(std::string("abc%u4E2D%u56FD%u4EBA"), CXCode::escape(sGB)); EXPECT_EQ(sGB, CXCode::unescape(CXCode::escape(sGB))); EXPECT_EQ(std::string("abc%u4E2D%u56FD%u4EBA"), CXCode::escape(CXCode::unescape(CXCode::escape(sGB)))); EXPECT_EQ(sGB, CXCode::unescape((sGB))); EXPECT_EQ(std::string("abc%E4%B8%AD%E5%9B%BD%E4%BA%BA"), CXCode::encodeURIComponent(sGB)); EXPECT_EQ(std::string("abc\\u4E2D\\u56FD\\u4EBA"), CXCode::encodeJSONComponent(sGB)); EXPECT_EQ(std::string("abc中国人"), CXCode::encodeXMLComponent(sGB)); CXCode x3(CXCode::CHARSET_UCS2); T_UC tUC[6] = {'a','b','c',20013,22269,20154}; std::string sUC((char *)tUC, 12); EXPECT_EQ(sUC, CXCode::UCS2(sUC)); EXPECT_EQ(sUCS2, CXCode::escape(sUC)); EXPECT_EQ(CXCode::UCS2(sUCS2), CXCode::escape(sUC)); EXPECT_EQ(CXCode::escape(sUC), CXCode::UCS2(CXCode::escape(sUC))); EXPECT_EQ(sUC, CXCode::unescape(CXCode::escape(sUC))); EXPECT_EQ(sUCS2, CXCode::escape(CXCode::unescape(CXCode::escape(sUC)))); EXPECT_EQ(sUC, CXCode::unescape((sUC))); EXPECT_EQ(std::string("abc%E4%B8%AD%E5%9B%BD%E4%BA%BA"), CXCode::encodeURIComponent(sUC)); EXPECT_EQ(std::string("abc\\u4E2D\\u56FD\\u4EBA"), CXCode::encodeJSONComponent(sUC)); EXPECT_EQ(std::string("abc中国人"), CXCode::encodeXMLComponent(sUC)); EXPECT_EQ(sUC, CXCode::GBS2UCS((sGB))); EXPECT_EQ(sUTF8, CXCode::GBS2UTF8((sGB))); EXPECT_EQ(sUC, CXCode::UTF82UCS((sUTF8))); EXPECT_EQ(sGB, CXCode::UTF82GBS((sUTF8))); EXPECT_EQ(sGB, CXCode::UCS2GBS((sUC))); EXPECT_EQ(sUTF8, CXCode::UCS2UTF8((sUC))); //std::cout << sUC << std::endl; //std::cout << CXCode::UCS2(CXCode::escape(sUC))<<std::endl; //std::cout << CXCode::escape(sUC) <<std::endl; //std::cout << CXCode::unescape(CXCode::escape(sUC)) <<std::endl; //std::cout << std::string("abc%u4E2D%u56FD%u4EBA") <<std::endl; //std::cout << CXCode::UCS2("abc%u4E2D%u56FD%u4EBA") <<std::endl; //std::cout << CXCode::encodeJSONComponent(CXCode::GBS2UCS((sGB)))<<std::endl; // return 0; }
void plop(){ std::cout<<"Début de l'exemple de Nozick sensei"<<std::endl; gca::GCA_vector a(1.0, 2.0, 3.0, 1.0); gca::GCA_vector b; b << -1.0, -3.0, 2.0, 1.0; gca::GCA_bivector l = a ^ b; // l is a PLucker line l.show(); gca::GCA_vector x1(2.0, -1.0, -1.0, 1.0); gca::GCA_vector x2(1.0, -1.0, 1.0, 1.0); gca::GCA_vector x3(-1.0, -1.0, -2.0, 1.0); gca::GCA_trivector d = x1^x2^x3; //d is a plane std::cout << d<<std::endl; std::cout << "(~d^~l) n'est pas l'intersection : "<< (~d^~l) <<std::endl; gca::GCA_antivector croisement = (~d^~l); std::cout << "~(~d^~l) est l'intersection : "<< ~croisement <<std::endl; //std::cout << "intersection : "<< ~d^~l <<std::endl;// ne peux pas pas compiler selon les normes du c++ std::cout<<"Fin de l'exemple de Nozick sensei"<<std::endl; }
void fn () { X x1(3.5); // WARNING - double to int X x2(3.5f); // WARNING - float to int X x3(1, 3.5); // WARNING - double to int X x4(1, 3.5f); // WARNING - float to int X x5(3.5, 1); // WARNING - double to int X x6(3.5f, 1); // WARNING - float to int X y1 = 3.5; // WARNING - double to int X y2 = 3.5f; // WARNING - float to int int j1 (3.5); // WARNING - double to int int j2 (3.5f); // WARNING - float to int int k1 = 3.5; // WARNING - double to int int k2 = 3.5f; // WARNING - float to int j1 = 3.5; // WARNING - double to int j2 = 3.5f; // WARNING - float to int foo (3.5); // WARNING - double to int foo (3.5f); // WARNING - float to int wibble (3.5); // WARNING - double to int wibble (3.5f); // WARNING - float to int wibble (1, 3.5); // WARNING - double to int wibble (1, 3.5f); // WARNING - float to int wibble (3.5, 1); // WARNING - double to int wibble (3.5f, 1); // WARNING - float to int punk (); // WARNING - double to int rock (1); // WARNING - double to int }
int main( void ) { unsigned long ul = 0xCCCCCCCC; void *pv = NULL; x1 = test1; x1( 1, 2, 3, 4, 5 ); if( res[0] != 1 ) fail( __LINE__ ); if( res[1] != 2 ) fail( __LINE__ ); if( res[2] != 3 ) fail( __LINE__ ); if( res[3] != 4 ) fail( __LINE__ ); if( res[4] != 5 ) fail( __LINE__ ); x2 = test1; x2( 1, 2, 3, 4, 5 ); if( res[0] != 1 ) fail( __LINE__ ); if( res[1] != 2 ) fail( __LINE__ ); if( res[2] != 3 ) fail( __LINE__ ); if( res[3] != 4 ) fail( __LINE__ ); if( res[4] != 5 ) fail( __LINE__ ); x3 = test2; x3( 1, 2, 3, 4, 5 ); if( res[0] != 1 ) fail( __LINE__ ); if( res[1] != 2 ) fail( __LINE__ ); if( res[2] != 3 ) fail( __LINE__ ); if( res[3] != 4 ) fail( __LINE__ ); if( res[4] != 5 ) fail( __LINE__ ); if( !fn1( ul, 0x55AA ) ) fail( __LINE__ ); if( !fn2( pv, 0x55AA ) ) fail( __LINE__ ); _PASS; }
void g() { X x1(5); X x2(1.0, 3, 4.2); X x3(1.0, 1.0); // expected-error{{no matching constructor for initialization of 'x3'; candidates are:}} Y y(1.0); X x4(3.14, y); Z z; // expected-error{{no matching constructor for initialization of 'z'}} }
void g() { X x1(5); X x2(1.0, 3, 4.2); X x3(1.0, 1.0); // expected-error{{no matching constructor for initialization of 'X'}} Y y(1.0); X x4(3.14, y); Z z; // expected-error{{no matching constructor for initialization of 'Z'}} }
bool PolygonLine :: intersects(Element *element) { printf("Warning: entering PolygonLine :: intersects(Element *element).\n"); #ifdef __BOOST_MODULE if ( !boundingBoxIntersects(element) ) { return false; } double distTol = 1.0e-9; int numSeg = this->giveNrVertices() - 1; // Loop over the crack segments and test each segment for // overlap with the element for ( int segId = 1; segId <= numSeg; segId++ ) { if ( element->giveGeometryType() == EGT_triangle_1 ) { // Crack segment bPoint2 crackP1( this->giveVertex ( segId )->at(1), this->giveVertex ( segId )->at(2) ); bPoint2 crackP2( this->giveVertex ( segId + 1 )->at(1), this->giveVertex ( segId + 1 )->at(2) ); bSeg2 crackSeg(crackP1, crackP2); // Triangle vertices bPoint2 x1( element->giveNode ( 1 )->giveCoordinate(1), element->giveNode ( 1 )->giveCoordinate(2) ); bPoint2 x2( element->giveNode ( 2 )->giveCoordinate(1), element->giveNode ( 2 )->giveCoordinate(2) ); bPoint2 x3( element->giveNode ( 3 )->giveCoordinate(1), element->giveNode ( 3 )->giveCoordinate(2) ); bSeg2 edge1(x1, x2); bSeg2 edge2(x2, x3); bSeg2 edge3(x3, x1); double d1 = bDist(crackSeg, edge1); if ( d1 < distTol ) { return true; } double d2 = bDist(crackSeg, edge2); if ( d2 < distTol ) { return true; } double d3 = bDist(crackSeg, edge3); if ( d3 < distTol ) { return true; } } } #endif return false; }
int main() { char user[3]; read(0, user, 3); if (x0(user) || x1(user) || x2(user) || x3(user) || x4(user)) { failure(); } else { success(); } }
NT2_TEST_CASE_TPL( cols_nd_typed, NT2_TYPES ) { nt2::table<T> x2 = nt2::cols(8,4, T(22.5) ); for(int i=1;i<=8;++i) for(int j=1;j<=4;++j) NT2_TEST_EQUAL( T(22.5+j-1), T(x2(i, j)) ); nt2::table<T> x3 = nt2::cols(2,4, T(22.5) ); for(int i=1;i<=2;++i) for(int j=1;j<=4;++j) NT2_TEST_EQUAL( T(22.5+j-1), T(x3(i, j)) ); nt2::table<T> x4 = nt2::cols(nt2::of_size(8, 6), T(22.5) ); for(int i=1;i<=8;++i) for(int j=1;j<=6;++j) NT2_TEST_EQUAL( T(22.5+j-1), T(x4(i, j)) ); }
Cube::Cube(float scale){ if(!ModelBase::GetInstance().HasModel("cube")){ ModelBase::GetInstance().AddModelTriangles("cube",12, { -1.0f,-1.0f,-1.0f, -1.0f,-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, // 1.0f, 1.0f,-1.0f, -1.0f,-1.0f,-1.0f, -1.0f, 1.0f,-1.0f, // 1.0f,-1.0f, 1.0f, -1.0f,-1.0f,-1.0f, 1.0f,-1.0f,-1.0f, // 1.0f, 1.0f,-1.0f, 1.0f,-1.0f,-1.0f, -1.0f,-1.0f,-1.0f, // -1.0f,-1.0f,-1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f,-1.0f, 1.0f,-1.0f, 1.0f, -1.0f,-1.0f, 1.0f, -1.0f,-1.0f,-1.0f, -1.0f, 1.0f, 1.0f, -1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f,-1.0f, 1.0f,-1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f, -1.0f, 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f,-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,-1.0f, 1.0f}, // { x3b(-1.0f, 0.0f, 0.0f), x3b(0.0f, 0.0f, -1.0f), x3b(0.0f, -1.0f, 0.0f), // x3b(0.0f, 0.0f, -1.0f),}, { { CL,CD,CD,CL,CL,CL,CG,CG,CG, CL,CL,CL,CL,CD,CL,CG,CG,CG, CD,CD,CD,CD,CL,CL,CL,CD,CD, CD,CL,CL,CD,CL,CD,CD,CD,CD,}, { x4(x3(C_GREEN),x3(C_RED),x3(C_BLUE)),}, { x4(x3(C_RED),x3(C_RED),x3(C_RED)),}, } ); } model_id = "cube"; SetScale(scale); }
/////////////////////////////////////////////////////////////////////////////////////////////////// //int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR, int) int main() { { X x1(4.5, 6); X x2(x1); x2 = x1; X x3(std::move(x1)); x3 = std::move(x2); X x4(4.5, 6); } return 0; }
TEST(XmlEquality, SimpleValues) { AmfXml x1; AmfXml x2(""); EXPECT_EQ(x1, x2); AmfXml x3("foo"); AmfXml x4("foo"); EXPECT_EQ(x3, x4); EXPECT_NE(x1, x3); AmfXml x5("foobar"); EXPECT_NE(x3, x5); }
NT2_TEST_CASE_TPL( ric_nd_typed, NT2_TYPES ) { nt2::table<T> x1 = nt2::ric(8, nt2::meta::as_<T>() ); for(int i=1;i<=8;++i) for(int j=1;j<=8;++j) NT2_TEST_EQUAL( T(i-1), T(x1(i, j)) ); nt2::table<T> x2 = nt2::ric(8,4, nt2::meta::as_<T>() ); for(int i=1;i<=8;++i) for(int j=1;j<=4;++j) NT2_TEST_EQUAL( T(i-1), T(x2(i, j)) ); nt2::table<T> x3 = nt2::ric(2,4, nt2::meta::as_<T>() ); for(int i=1;i<=2;++i) for(int j=1;j<=4;++j) NT2_TEST_EQUAL( T(i-1), T(x3(i, j)) ); nt2::table<T> x4 = nt2::ric(nt2::of_size(8, 6), nt2::meta::as_<T>() ); for(int i=1;i<=8;++i) for(int j=1;j<=6;++j) NT2_TEST_EQUAL( T(i-1), T(x4(i, j)) ); }
void tst_match(ast_manager & m, app * t, app * i) { substitution s(m); s.reserve(2, 10); // reserving a big number of variables to be safe. matcher match; std::cout << "Is " << mk_pp(i, m) << " an instance of " << mk_pp(t, m) << "\n"; if (match(t, i, s)) { std::cout << "yes\n"; s.display(std::cout); } else { std::cout << "no\n"; } s.reset(); if (t->get_decl() == i->get_decl()) { // trying to match the arguments of t and i std::cout << "Are the arguments of " << mk_pp(i, m) << " an instance of the arguments of " << mk_pp(t, m) << "\n"; unsigned num_args = t->get_num_args(); unsigned j; for (j = 0; j < num_args; j++) { if (!match(t->get_arg(j), i->get_arg(j), s)) break; } if (j == num_args) { std::cout << "yes\n"; s.display(std::cout); // create some dummy term to test for applying the substitution. sort_ref S( m.mk_uninterpreted_sort(symbol("S")), m); sort * domain[3] = {S, S, S}; func_decl_ref r( m.mk_func_decl(symbol("r"), 3, domain, S), m); expr_ref x1( m.mk_var(0, S), m); expr_ref x2( m.mk_var(1, S), m); expr_ref x3( m.mk_var(2, S), m); app_ref rxyzw( m.mk_app(r, x1.get(), x2.get(), x3.get()), m); expr_ref result(m); unsigned deltas[2] = {0,0}; s.apply(2, deltas, expr_offset(rxyzw, 0), result); std::cout << "applying substitution to\n" << mk_pp(rxyzw,m) << "\nresult:\n" << mk_pp(result,m) << "\n"; } else { std::cout << "no\n"; } } std::cout << "\n"; }
void string0_tests() { std::string x1(1, '\0'); std::string x2(2, '\0'); std::string x3(3, '\0'); std::string x4(10, '\0'); BOOST_HASH_TEST_NAMESPACE::hash<std::string> hasher; BOOST_TEST(hasher(x1) != hasher(x2)); BOOST_TEST(hasher(x1) != hasher(x3)); BOOST_TEST(hasher(x1) != hasher(x4)); BOOST_TEST(hasher(x2) != hasher(x3)); BOOST_TEST(hasher(x2) != hasher(x4)); BOOST_TEST(hasher(x3) != hasher(x4)); }
void fwd_test() { test::test_type1<int> x1(3); test::test_type1<std::string> y1("Black"); test::test_type2<int> x2(25, 16); test::test_type2<std::string> y2("White", "Green"); std::vector<int> empty; std::vector<std::string> empty2; test::test_type3<int> x3(empty.begin(), empty.end()); test::test_type3<std::string> y3(empty2.begin(), empty2.end()); // Prevent gcc warnings: unused(x1); unused(x2); unused(x3); unused(y1); unused(y2); unused(y3); }
void IntegrationRule::DefineIntegrationRuleTetrahedron(IntegrationRule & integrationRule, int ruleOrder) { // we use a ready function, which provides a tetrahedral integration rule Vector x1, x2, x3, w; GetIntegrationRuleTet(x1, x2, x3, w, ruleOrder); // and now we create a 3D integration rule integrationRule.integrationPoints.SetLen(x1.Length()); assert(x1.Length() == x2.Length()); assert(x1.Length() == x3.Length()); assert(x1.Length() == w.Length()); for (int i1 = 1; i1 <= x1.GetLen(); i1++) { integrationRule.integrationPoints(i1).x = x1(i1); integrationRule.integrationPoints(i1).y = x2(i1); integrationRule.integrationPoints(i1).z = x3(i1); integrationRule.integrationPoints(i1).weight = w(i1); } }
void RSA_TestInstantiations() { RSASS<PKCS1v15, SHA>::Verifier x1(1, 1); RSASS<PKCS1v15, SHA>::Signer x2(NullRNG(), 1); RSASS<PKCS1v15, SHA>::Verifier x3(x2); RSASS<PKCS1v15, SHA>::Verifier x4(x2.GetKey()); RSASS<PSS, SHA>::Verifier x5(x3); #ifndef __MWERKS__ RSASS<PSSR, SHA>::Signer x6 = x2; x3 = x2; x6 = x2; #endif RSAES<PKCS1v15>::Encryptor x7(x2); #ifndef __GNUC__ RSAES<PKCS1v15>::Encryptor x8(x3); #endif RSAES<OAEP<SHA> >::Encryptor x9(x2); x4 = x2.GetKey(); }
void IntegrationRulesCreator::CreateTetrahedralRule(int order) { // we use a ready function, which provides a one-dimensional integration rule Vector x1, x2, x3, w; GetIntegrationRuleTet(x1, x2, x3, w, order); // and now we create a 3D integration rule currentIntegrationRuleInfo = new IntegrationRule::IntegrationRuleInfo(); currentIntegrationRuleInfo->integrationRule.SetLen(x1.Length()); assert(x1.Length() == x2.Length()); assert(x1.Length() == x3.Length()); assert(x1.Length() == w.Length()); for (int i1 = 1; i1 <= x1.GetLen(); i1++) { currentIntegrationRuleInfo->integrationRule(i1).x = x1(i1); currentIntegrationRuleInfo->integrationRule(i1).y = x2(i1); currentIntegrationRuleInfo->integrationRule(i1).z = x3(i1); currentIntegrationRuleInfo->integrationRule(i1).weight = w(i1); } }
boost::shared_ptr<Mesh<Simplex<2> > > createMeshLaplacianLM() { typedef Mesh<Simplex<2> > mesh_type; double meshSize = option("gmsh.hsize").as<double>(); GeoTool::Node x1(-2,-1); GeoTool::Node x2(2,1); GeoTool::Rectangle R( meshSize ,"OMEGA",x1,x2); //R.setMarker(_type="line",_name="Paroi",_marker3=true); R.setMarker(_type="line",_name="gamma",_markerAll=true); R.setMarker(_type="surface",_name="Omega",_markerAll=true); GeoTool::Node x3(0,0); //center GeoTool::Node x4(1);//majorRadiusParam GeoTool::Node x5(0.7);//minorRadiusParam GeoTool::Node x6(0.1);//penautRadiusParam GeoTool::Peanut P( meshSize ,"OMEGA2",x3,x4,x5,x6); P.setMarker(_type="line",_name="peanut",_markerAll=true); P.setMarker(_type="surface",_name="Omega2",_markerAll=true); auto mesh = (R-P).createMesh(_mesh=new mesh_type,_name="mymesh.msh"); return mesh; }
void MathPlot::setupMultiAxisDemo(QCustomPlot *customPlot) { customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // period as decimal separator and comma as thousand separator customPlot->legend->setVisible(true); QFont legendFont = font(); // start out with MainWindow's font.. legendFont.setPointSize(9); // and make a bit smaller for legend customPlot->legend->setFont(legendFont); customPlot->legend->setBrush(QBrush(QColor(255,255,255,230))); // by default, the legend is in the inset layout of the main axis rect. So this is how we access it to change legend placement: customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignBottom|Qt::AlignRight); // setup for graph 0: key axis left, value axis bottom // will contain left maxwell-like function customPlot->addGraph(customPlot->yAxis, customPlot->xAxis); customPlot->graph(0)->setPen(QPen(QColor(255, 100, 0))); customPlot->graph(0)->setBrush(QBrush(QPixmap("://skin/images/balboa.jpg"))); // fill with texture of specified image customPlot->graph(0)->setLineStyle(QCPGraph::lsLine); customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5)); customPlot->graph(0)->setName("Left maxwell function"); // setup for graph 1: key axis bottom, value axis left (those are the default axes) // will contain bottom maxwell-like function customPlot->addGraph(); customPlot->graph(1)->setPen(QPen(Qt::red)); customPlot->graph(1)->setBrush(QBrush(QPixmap("://skin/images/balboa.jpg"))); // same fill as we used for graph 0 customPlot->graph(1)->setLineStyle(QCPGraph::lsStepCenter); customPlot->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::red, Qt::white, 7)); customPlot->graph(1)->setErrorType(QCPGraph::etValue); customPlot->graph(1)->setName("Bottom maxwell function"); // setup for graph 2: key axis top, value axis right // will contain high frequency sine with low frequency beating: customPlot->addGraph(customPlot->xAxis2, customPlot->yAxis2); customPlot->graph(2)->setPen(QPen(Qt::blue)); customPlot->graph(2)->setName("High frequency sine"); // setup for graph 3: same axes as graph 2 // will contain low frequency beating envelope of graph 2 customPlot->addGraph(customPlot->xAxis2, customPlot->yAxis2); QPen blueDotPen; blueDotPen.setColor(QColor(30, 40, 255, 150)); blueDotPen.setStyle(Qt::DotLine); blueDotPen.setWidthF(4); customPlot->graph(3)->setPen(blueDotPen); customPlot->graph(3)->setName("Sine envelope"); // setup for graph 4: key axis right, value axis top // will contain parabolically distributed data points with some random perturbance customPlot->addGraph(customPlot->yAxis2, customPlot->xAxis2); customPlot->graph(4)->setPen(QColor(50, 50, 50, 255)); customPlot->graph(4)->setLineStyle(QCPGraph::lsNone); customPlot->graph(4)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 4)); customPlot->graph(4)->setName("Some random data around\na quadratic function"); // generate data, just playing with numbers, not much to learn here: QVector<double> x0(25), y0(25); QVector<double> x1(15), y1(15), y1err(15); QVector<double> x2(250), y2(250); QVector<double> x3(250), y3(250); QVector<double> x4(250), y4(250); for (int i=0; i<25; ++i) // data for graph 0 { x0[i] = 3*i/25.0; y0[i] = exp(-x0[i]*x0[i]*0.8)*(x0[i]*x0[i]+x0[i]); } for (int i=0; i<15; ++i) // data for graph 1 { x1[i] = 3*i/15.0;; y1[i] = exp(-x1[i]*x1[i])*(x1[i]*x1[i])*2.6; y1err[i] = y1[i]*0.25; } for (int i=0; i<250; ++i) // data for graphs 2, 3 and 4 { x2[i] = i/250.0*3*M_PI; x3[i] = x2[i]; x4[i] = i/250.0*100-50; y2[i] = sin(x2[i]*12)*cos(x2[i])*10; y3[i] = cos(x3[i])*10; y4[i] = 0.01*x4[i]*x4[i] + 1.5*(rand()/(double)RAND_MAX-0.5) + 1.5*M_PI; } // pass data points to graphs: customPlot->graph(0)->setData(x0, y0); customPlot->graph(1)->setDataValueError(x1, y1, y1err); customPlot->graph(2)->setData(x2, y2); customPlot->graph(3)->setData(x3, y3); customPlot->graph(4)->setData(x4, y4); // activate top and right axes, which are invisible by default: customPlot->xAxis2->setVisible(true); customPlot->yAxis2->setVisible(true); // set ranges appropriate to show data: customPlot->xAxis->setRange(0, 2.7); customPlot->yAxis->setRange(0, 2.6); customPlot->xAxis2->setRange(0, 3.0*M_PI); customPlot->yAxis2->setRange(-70, 35); // set pi ticks on top axis: QVector<double> piTicks; QVector<QString> piLabels; piTicks << 0 << 0.5*M_PI << M_PI << 1.5*M_PI << 2*M_PI << 2.5*M_PI << 3*M_PI; piLabels << "0" << QString::fromUtf8("½π") << QString::fromUtf8("π") << QString::fromUtf8("1½π") << QString::fromUtf8("2π") << QString::fromUtf8("2½π") << QString::fromUtf8("3π"); customPlot->xAxis2->setAutoTicks(false); customPlot->xAxis2->setAutoTickLabels(false); customPlot->xAxis2->setTickVector(piTicks); customPlot->xAxis2->setTickVectorLabels(piLabels); // add title layout element: customPlot->plotLayout()->insertRow(0); customPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(customPlot, "Way too many graphs in one plot")); // set labels: customPlot->xAxis->setLabel("Bottom axis with outward ticks"); customPlot->yAxis->setLabel("Left axis label"); customPlot->xAxis2->setLabel("Top axis label"); customPlot->yAxis2->setLabel("Right axis label"); // make ticks on bottom axis go outward: customPlot->xAxis->setTickLength(0, 5); customPlot->xAxis->setSubTickLength(0, 3); // make ticks on right axis go inward and outward: customPlot->yAxis2->setTickLength(3, 3); customPlot->yAxis2->setSubTickLength(1, 1); }
// This function creates the following model: // Minimize // obj: x1 + x2 + x3 + x4 + x5 + x6 // Subject To // c1: x1 + x2 + x5 = 8 // c2: x3 + x5 + x6 = 10 // q1: [ -x1^2 + x2^2 + x3^2 ] <= 0 // q2: [ -x4^2 + x5^2 ] <= 0 // Bounds // x2 Free // x3 Free // x5 Free // End // which is a second order cone program in standard form. // The function returns objective, variables and constraints in the // values obj, vars and rngs. // The function also sets up cone so that for a column j we have // cone[j] >= 0 Column j is in a cone constraint and is the // cone's head variable. // cone[j] == NOT_CONE_HEAD Column j is in a cone constraint but is // not the cone's head variable.. // cone[j] == NOT_IN_CONE Column j is not contained in any cone constraint. static void createmodel (IloModel& model, IloObjective &obj, IloNumVarArray &vars, IloRangeArray &rngs, IloIntArray& cone) { // The indices we assign as user objects to the modeling objects. // We define them as static data so that we don't have to worry about // dynamic memory allocation/leakage. static int indices[] = { 0, 1, 2, 3, 4, 5, 6 }; IloEnv env = model.getEnv(); // Create variables. IloNumVar x1(env, 0, IloInfinity, "x1"); IloNumVar x2(env, -IloInfinity, IloInfinity, "x2"); IloNumVar x3(env, -IloInfinity, IloInfinity, "x3"); IloNumVar x4(env, 0, IloInfinity, "x4"); IloNumVar x5(env, -IloInfinity, IloInfinity, "x5"); IloNumVar x6(env, 0, IloInfinity, "x6"); // Create objective function and immediately store it in return value. obj = IloMinimize(env, x1 + x2 + x3 + x4 + x5 + x6); // Create constraints. IloRange c1(env, 8, x1 + x2 + x5, 8, "c1"); IloRange c2(env, 10, x3 + x5 + x6, 10, "c2"); IloRange q1(env, -IloInfinity, -x1*x1 + x2*x2 + x3*x3, 0, "q1"); cone.add(2); // x1, cone head of constraint at index 2 cone.add(NOT_CONE_HEAD); // x2 cone.add(NOT_CONE_HEAD); // x3 IloRange q2(env, -IloInfinity, -x4*x4 + x5*x5, 0, "q2"); cone.add(3); // x4, cone head of constraint at index 3 cone.add(NOT_CONE_HEAD); // x5 cone.add(NOT_IN_CONE); // x6 // Setup model. model.add(obj); model.add(obj); model.add(c1); model.add(c2); model.add(q1); model.add(q2); // Setup return values. vars.add(x1); vars.add(x2); vars.add(x3); vars.add(x4); vars.add(x5); vars.add(x6); rngs.add(c1); rngs.add(c2); rngs.add(q1); rngs.add(q2); // We set the user object for each modeling object to its index in the // respective array. This makes the code in checkkkt a little simpler. for (IloInt i = 0; i < vars.getSize(); ++i) vars[i].setObject(&indices[i]); for (IloInt i = 0; i < rngs.getSize(); ++i) rngs[i].setObject(&indices[i]); }
int main() { X x1( 1 ); X x2( 2 ); X x3( 3 ); static_assert( noexcept( x1 + x2 ), "oops" ); static_assert( !noexcept( x1 * x2 ), "oops" ); assert( x1 == x1 ); assert( x1 != x2 ); assert( x1 == 1 ); assert( 2 == x2 ); assert( x3 != 1 ); assert( 2 != x3 ); assert( x1 < x2 ); assert( x1 <= x2 ); assert( x2 <= x2 ); assert( x3 > x2 ); assert( x3 >= x2 ); assert( x2 >= x2 ); assert( x1 < 2 ); assert( x1 <= 2 ); assert( x2 <= 2 ); assert( x3 > 2 ); assert( x3 >= 2 ); assert( x2 >= 2 ); assert( 1 < x2 ); assert( 1 <= x2 ); assert( 2 <= x2 ); assert( 3 > x2 ); assert( 3 >= x2 ); assert( 2 >= x2 ); assert( x1 + x2 == x3 ); assert( 1 + x2 == x3 ); assert( x1 + 2 == x3 ); assert( x2 + x1 == 3 ); assert( x3 - x1 == x2 ); assert( 3 - x1 == x2 ); assert( x3 - 1 == x2 ); assert( x1 - x3 == -2 ); assert( x2 * x2 == 4 ); assert( x2 * 3 == 6 ); assert( 4 * x2 == 8 ); assert( ( x3 + x1 ) / x2 == 2 ); assert( ( x1 + x3 ) / 2 == x2 ); assert( x3 % x2 == 1 ); assert( x3 % 2 == 1 ); static_assert( std::is_empty< E >::value, "oops" ); adl_test( E{} ); S s; S s2( s, s ); #if !defined( _MSC_VER ) || defined( __clang__ ) constexpr C c1( 1 ); constexpr C c2( 2 ); constexpr C c3( 3 ); static_assert( c1 < c2, "oops" ); static_assert( c2 < c3, "oops" ); static_assert( c1 < c3, "oops" ); static_assert( c1 < 2, "oops" ); static_assert( c2 < 3, "oops" ); static_assert( c1 < 3, "oops" ); static_assert( c1 <= c2, "oops" ); static_assert( c2 <= c3, "oops" ); static_assert( c1 <= c3, "oops" ); static_assert( c1 <= 2, "oops" ); static_assert( c2 <= 3, "oops" ); static_assert( c1 <= 3, "oops" ); static_assert( 1 <= c2, "oops" ); static_assert( 2 <= c3, "oops" ); static_assert( 1 <= c3, "oops" ); static_assert( c2 > c1, "oops" ); static_assert( c3 > c2, "oops" ); static_assert( c3 > c1, "oops" ); static_assert( c2 > 1, "oops" ); static_assert( c3 > 2, "oops" ); static_assert( c3 > 1, "oops" ); static_assert( 2 > c1, "oops" ); static_assert( 3 > c2, "oops" ); static_assert( 3 > c1, "oops" ); static_assert( c2 >= c1, "oops" ); static_assert( c3 >= c2, "oops" ); static_assert( c3 >= c1, "oops" ); static_assert( c2 >= 1, "oops" ); static_assert( c3 >= 2, "oops" ); static_assert( c3 >= 1, "oops" ); static_assert( 2 >= c1, "oops" ); static_assert( 3 >= c2, "oops" ); static_assert( 3 >= c1, "oops" ); static_assert( !( c1 < c1 ), "oops" ); // NOLINT static_assert( !( c1 > c1 ), "oops" ); // NOLINT static_assert( c1 <= c1, "oops" ); // NOLINT static_assert( c1 >= c1, "oops" ); // NOLINT #endif }
//--------------------------------------------------------- DMat& NDG2D::ConformingHrefine2D(IMat& edgerefineflag, const DMat& Qin) //--------------------------------------------------------- { #if (0) OutputNodes(false); // volume nodes //OutputNodes(true); // face nodes #endif // function newQ = ConformingHrefine2D(edgerefineflag, Q) // Purpose: apply edge splits as requested by edgerefineflag IVec v1("v1"), v2("v2"), v3("v3"), tvi; DVec x1("x1"), x2("x2"), x3("x3"), y1("y1"), y2("y2"), y3("y3"); DVec a1("a1"), a2("a2"), a3("a3"); // count vertices assert (VX.size() == Nv); // find vertex triplets for elements to be refined v1 = EToV(All,1); v2 = EToV(All,2); v3 = EToV(All,3); x1 = VX(v1); x2 = VX(v2); x3 = VX(v3); y1 = VY(v1); y2 = VY(v2); y3 = VY(v3); // find angles at each element vertex (in radians) VertexAngles(x1,x2,x3,y1,y2,y3, a1,a2,a3); // absolute value of angle size a1.set_abs(); a2.set_abs(); a3.set_abs(); int k=0,k1=0,f1=0,k2=0,f2=0, e1=0,e2=0,e3=0, b1=0,b2=0,b3=0, ref=0; IVec m1,m2,m3; DVec mx1, my1, mx2, my2, mx3, my3; // create new vertices at edge centers of marked elements // (use unique numbering derived from unique edge number)) m1 = max(IVec(Nv*(v1-1)+v2+1), IVec(Nv*(v2-1)+v1+1)); mx1=0.5*(x1+x2); my1=0.5*(y1+y2); m2 = max(IVec(Nv*(v2-1)+v3+1), IVec(Nv*(v3-1)+v2+1)); mx2=0.5*(x2+x3); my2=0.5*(y2+y3); m3 = max(IVec(Nv*(v1-1)+v3+1), IVec(Nv*(v3-1)+v1+1)); mx3=0.5*(x3+x1); my3=0.5*(y3+y1); // ensure that both elements sharing an edge are split for (k1=1; k1<=K; ++k1) { for (f1=1; f1<=Nfaces; ++f1) { if (edgerefineflag(k1,f1)) { k2 = EToE(k1,f1); f2 = EToF(k1,f1); edgerefineflag(k2,f2) = 1; } } } // store old data IMat oldEToV = EToV; DVec oldVX = VX, oldVY = VY; // count the number of elements in the refined mesh int newK = countrefinefaces(edgerefineflag); EToV.resize(newK, Nfaces, true, 0); IMat newBCType(newK,3, "newBCType"); // kold = []; IVec kold(newK, "kold"); Index1D KI,KIo; int sk=1, skstart=0, skend=0; for (k=1; k<=K; ++k) { skstart = sk; e1 = edgerefineflag(k,1); b1 = BCType(k,1); e2 = edgerefineflag(k,2); b2 = BCType(k,2); e3 = edgerefineflag(k,3); b3 = BCType(k,3); ref = e1 + 2*e2 + 4*e3; switch (ref) { case 0: EToV(sk, All) = IVec(v1(k),v2(k),v3(k)); newBCType(sk,All) = IVec(b1, b2, b3); ++sk; break; case 1: EToV(sk, All) = IVec(v1(k),m1(k),v3(k)); newBCType(sk,All) = IVec(b1, 0, b3); ++sk; EToV(sk, All) = IVec(m1(k),v2(k),v3(k)); newBCType(sk,All) = IVec(b1, b2, 0); ++sk; break; case 2: EToV(sk, All) = IVec(v2(k),m2(k),v1(k)); newBCType(sk,All) = IVec(b2, 0, b1); ++sk; EToV(sk, All) = IVec(m2(k),v3(k),v1(k)); newBCType(sk,All) = IVec(b2, b3, 0); ++sk; break; case 4: EToV(sk, All) = IVec(v3(k),m3(k),v2(k)); newBCType(sk,All) = IVec(b3, 0, b2); ++sk; EToV(sk, All) = IVec(m3(k),v1(k),v2(k)); newBCType(sk,All) = IVec(b3, b1, 0); ++sk; break; case 3: EToV(sk, All) = IVec(m1(k),v2(k),m2(k)); newBCType(sk,All) = IVec(b1, b2, 0); ++sk; if (a1(k) > a3(k)) { // split largest angle EToV(sk, All) = IVec(v1(k),m1(k),m2(k)); newBCType(sk,All) = IVec(b1, 0, 0); ++sk; EToV(sk, All) = IVec(v1(k),m2(k),v3(k)); newBCType(sk,All) = IVec( 0, b2, b3); ++sk; } else { EToV(sk, All) = IVec(v3(k),m1(k),m2(k)); newBCType(sk,All) = IVec( 0, 0, b2); ++sk; EToV(sk, All) = IVec(v3(k),v1(k),m1(k)); newBCType(sk,All) = IVec(b3, b1, 0); ++sk; } break; case 5: EToV(sk, All) = IVec(v1(k),m1(k),m3(k)); newBCType(sk,All) = IVec(b1, 0, b3); ++sk; if (a2(k) > a3(k)) { // split largest angle EToV(sk, All) = IVec(v2(k),m3(k),m1(k)); newBCType(sk,All) = IVec( 0, 0, b1); ++sk; EToV(sk, All) = IVec(v2(k),v3(k),m3(k)); newBCType(sk,All) = IVec(b2, b3, 0); ++sk; } else { EToV(sk, All) = IVec(v3(k),m3(k),m1(k)); newBCType(sk,All) = IVec(b3, 0, 0); ++sk; EToV(sk, All) = IVec(v3(k),m1(k),v2(k)); newBCType(sk,All) = IVec( 0, b1, b2); ++sk; } break; case 6: EToV(sk, All) = IVec(v3(k),m3(k),m2(k)); newBCType(sk,All) = IVec(b3, 0, b2); ++sk; if (a1(k) > a2(k)) { // split largest angle EToV(sk, All) = IVec(v1(k),m2(k),m3(k)); newBCType(sk,All) = IVec( 0, 0, b3); ++sk; EToV(sk, All) = IVec(v1(k),v2(k),m2(k)); newBCType(sk,All) = IVec(b1, b2, 0); ++sk; } else { EToV(sk, All) = IVec(v2(k),m2(k),m3(k)); newBCType(sk,All) = IVec(b2, 0, 0); ++sk; EToV(sk, All) = IVec(v2(k),m3(k),v1(k)); newBCType(sk,All) = IVec( 0 , b3, b1); ++sk; } break; default: // split all EToV(sk, All) = IVec(m1(k),m2(k),m3(k)); newBCType(sk, All) = IVec( 0, 0, 0); ++sk; EToV(sk, All) = IVec(v1(k),m1(k),m3(k)); newBCType(sk, All) = IVec(b1, 0, b3); ++sk; EToV(sk, All) = IVec(v2(k),m2(k),m1(k)); newBCType(sk, All) = IVec(b2, 0, b1); ++sk; EToV(sk, All) = IVec(v3(k),m3(k),m2(k)); newBCType(sk, All) = IVec(b3, 0, b2); ++sk; break; } skend = sk; // kold = [kold; k*ones(skend-skstart, 1)]; // element k is to be refined into (1:4) child elements. // store parent element numbers in array "kold" to help // with accessing parent vertex data during refinement. KI.reset(skstart, skend-1); // ids of child elements kold(KI) = k; // mark as children of element k } // Finished with edgerefineflag. Delete if OBJ_temp if (edgerefineflag.get_mode() == OBJ_temp) { delete (&edgerefineflag); } // renumber new nodes contiguously // ids = unique([v1;v2;v3;m1;m2;m3]); bool unique=true; IVec IDS, ids; IDS = concat( concat(v1,v2,v3), concat(m1,m2,m3) ); ids = sort(IDS, unique); Nv = ids.size(); int max_id = EToV.max_val(); umMSG(1, "max id in EToV is %d\n", max_id); // M N nnz vals triplet CSi newids(max_id,1, Nv, 1, 1 ); // newids = sparse(max(max(EToV)),1); int i=0, j=1; for (i=1; i<=Nv; ++i) { // newids(ids)= (1:Nv); newids.set1(ids(i),j, i); // load 1-based triplets } // row col x newids.compress(); // convert to csc form // Matlab ----------------------------------------------- // v1 = newids(v1); v2 = newids(v2); v3 = newids(v3); // m1 = newids(m1); m2 = newids(m2); m3 = newids(m3); //------------------------------------------------------- int KVi=v1.size(), KMi=m1.size(); // read from copies, overwrite originals // 1. reload ids for new vertices tvi = v1; for (i=1;i<=KVi;++i) {v1(i) = newids(tvi(i), 1);} tvi = v2; for (i=1;i<=KVi;++i) {v2(i) = newids(tvi(i), 1);} tvi = v3; for (i=1;i<=KVi;++i) {v3(i) = newids(tvi(i), 1);} // 2. load ids for new (midpoint) vertices tvi = m1; for (i=1;i<=KMi;++i) {m1(i) = newids(tvi(i), 1);} tvi = m2; for (i=1;i<=KMi;++i) {m2(i) = newids(tvi(i), 1);} tvi = m3; for (i=1;i<=KMi;++i) {m3(i) = newids(tvi(i), 1);} VX.resize(Nv); VY.resize(Nv); VX(v1) = x1; VX(v2) = x2; VX(v3) = x3; VY(v1) = y1; VY(v2) = y2; VY(v3) = y3; VX(m1) = mx1; VX(m2) = mx2; VX(m3) = mx3; VY(m1) = my1; VY(m2) = my2; VY(m3) = my3; if (newK != (sk-1)) { umERROR("NDG2D::ConformingHrefine2D", "Inconsistent element count: expect %d, but sk = %d", newK, (sk-1)); } else { K = newK; // sk-1; } // dumpIMat(EToV, "EToV (before)"); // EToV = newids(EToV); for (j=1; j<=3; ++j) { for (k=1; k<=K; ++k) { EToV(k,j) = newids(EToV(k,j), 1); } } #if (0) dumpIMat(EToV, "EToV (after)"); // umERROR("Checking ids", "Nigel, check EToV"); #endif BCType = newBCType; Nv = VX.size(); // xold = x; yold = y; StartUp2D(); #if (1) OutputNodes(false); // volume nodes //OutputNodes(true); // face nodes //umERROR("Exiting early", "Check adapted {volume,face} nodes"); #endif // allocate return object int Nfields = Qin.num_cols(); DMat* tmpQ = new DMat(Np*K, Nfields, "newQ", OBJ_temp); DMat& newQ = *tmpQ; // use a reference for syntax // quick return, if no interpolation is required if (Qin.size()<1) { return newQ; } DVec rOUT(Np),sOUT(Np),xout,yout,xy1(2),xy2(2),xy3(2),tmp(2),rhs; int ko=0,kv1=0,kv2=0,kv3=0,n=0; DMat A(2,2), interp; DMat oldQ = const_cast<DMat&>(Qin); for (k=1; k<=K; ++k) { ko = kold(k); xout = x(All,k); yout = y(All,k); kv1=oldEToV(ko,1); kv2=oldEToV(ko,2); kv3=oldEToV(ko,3); xy1.set(oldVX(kv1), oldVY(kv1)); xy2.set(oldVX(kv2), oldVY(kv2)); xy3.set(oldVX(kv3), oldVY(kv3)); A.set_col(1, xy2-xy1); A.set_col(2, xy3-xy1); for (i=1; i<=Np; ++i) { tmp.set(xout(i), yout(i)); rhs = 2.0*tmp - xy2 - xy3; tmp = A|rhs; rOUT(i) = tmp(1); sOUT(i) = tmp(2); } KI.reset (Np*(k -1)+1, Np*k ); // nodes in new element k KIo.reset(Np*(ko-1)+1, Np*ko); // nodes in old element ko interp = Vandermonde2D(N, rOUT, sOUT)*invV; for (n=1; n<=Nfields; ++n) { //newQ(:,k,n)= interp* Q(:,ko,n); //DVec tm1 = interp*oldQ(KIo,n); //dumpDVec(tm1, "tm1"); newQ(KI,n) = interp*oldQ(KIo,n); } } return newQ; }
int main(int argc, char *argv[]) { int i; char *passPhrase; int outputLen = 0; FILE *inputFile; if (argc <= 1) { usage(); return 0; } // Variable parsing for tablecheck if (strncmp(argv[1], "rc4", 3) == 0) { if (argc < 3) { usage(); return 0; } for (i = 1; i < argc; i++) { if (argc == 4) { if (strncmp(argv[i], "-p=", 3) == 0) { passPhrase = argv[i] + 3; } if (strncmp(argv[i], "-l=", 3) == 0) { outputLen = atoi(argv[i] + 3); } if (!argv[i]) { usage(); return 0; } } else if (argc == 3) { if (strncmp(argv[i], "-p=", 3) == 0) { passPhrase = argv[i] + 3; } outputLen = 256; } else { usage(); return 0; } } if (passPhrase == NULL || outputLen < 1) { usage(); return 0; } else { // Call tablecheck function rc4(passPhrase, outputLen); } } else if (strncmp(argv[1], "x1", 2) == 0) { if (argc < 2) { usage(); return 0; } //for (i = 1; i < argc; i++) { if (argc == 3) { inputFile = fopen(argv[2], "rb"); } else if (argc == 2) { inputFile = stdin; if(isatty(fileno(inputFile))) { fprintf(stderr, "Invalid use of arguments. Please specify a file name or pipe input.\n"); return -1; } } else { usage(); return 0; } //} if (inputFile == NULL) { usage(); return 0; } else { // Call keyExpand function x1(inputFile); } } else if (strncmp(argv[1], "x2", 2) == 0) { if (argc < 2) { usage(); return 0; } //for (i = 1; i < argc; i++) { if (argc == 3) { inputFile = fopen(argv[2], "rb"); } else if (argc == 2) { inputFile = stdin; if(isatty(fileno(inputFile))) { fprintf(stderr, "Invalid use of arguments. Please specify a file name or pipe input.\n"); return -1; } } else { usage(); return 0; } //} if (inputFile == NULL) { usage(); return 0; } else { // Call keyExpand function x2(inputFile); } } else if (strncmp(argv[1], "x3", 2) == 0) { if (argc < 2) { usage(); return 0; } //for (i = 1; i < argc; i++) { if (argc == 3) { inputFile = fopen(argv[2], "rb"); } else if (argc == 2) { inputFile = stdin; if(isatty(fileno(inputFile))) { fprintf(stderr, "Invalid use of arguments. Please specify a file name or pipe input.\n"); return -1; } } else { usage(); return 0; } //} if (inputFile == NULL) { usage(); return 0; } else { // Call keyExpand function x3(inputFile); } } // If these conditions are not met, then print usage and quit. else { usage(); return 0; } return 0; }
Vector Rosen34( Fun &F , size_t M , const Scalar &ti , const Scalar &tf , const Vector &xi , Vector &e ) { CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL; // check numeric type specifications CheckNumericType<Scalar>(); // check simple vector class specifications CheckSimpleVector<Scalar, Vector>(); // Parameters for Shampine's Rosenbrock method // are static to avoid recalculation on each call and // do not use Vector to avoid possible memory leak static Scalar a[3] = { Scalar(0), Scalar(1), Scalar(3) / Scalar(5) }; static Scalar b[2 * 2] = { Scalar(1), Scalar(0), Scalar(24) / Scalar(25), Scalar(3) / Scalar(25) }; static Scalar ct[4] = { Scalar(1) / Scalar(2), - Scalar(3) / Scalar(2), Scalar(121) / Scalar(50), Scalar(29) / Scalar(250) }; static Scalar cg[3 * 3] = { - Scalar(4), Scalar(0), Scalar(0), Scalar(186) / Scalar(25), Scalar(6) / Scalar(5), Scalar(0), - Scalar(56) / Scalar(125), - Scalar(27) / Scalar(125), - Scalar(1) / Scalar(5) }; static Scalar d3[3] = { Scalar(97) / Scalar(108), Scalar(11) / Scalar(72), Scalar(25) / Scalar(216) }; static Scalar d4[4] = { Scalar(19) / Scalar(18), Scalar(1) / Scalar(4), Scalar(25) / Scalar(216), Scalar(125) / Scalar(216) }; CPPAD_ASSERT_KNOWN( M >= 1, "Error in Rosen34: the number of steps is less than one" ); CPPAD_ASSERT_KNOWN( e.size() == xi.size(), "Error in Rosen34: size of e not equal to size of xi" ); size_t i, j, k, l, m; // indices size_t n = xi.size(); // number of components in X(t) Scalar ns = Scalar(double(M)); // number of steps as Scalar object Scalar h = (tf - ti) / ns; // step size Scalar zero = Scalar(0); // some constants Scalar one = Scalar(1); Scalar two = Scalar(2); // permutation vectors needed for LU factorization routine CppAD::vector<size_t> ip(n), jp(n); // vectors used to store values returned by F Vector E(n * n), Eg(n), f_t(n); Vector g(n * 3), x3(n), x4(n), xf(n), ftmp(n), xtmp(n), nan_vec(n); // initialize e = 0, nan_vec = nan for(i = 0; i < n; i++) { e[i] = zero; nan_vec[i] = nan(zero); } xf = xi; // initialize solution for(m = 0; m < M; m++) { // time at beginning of this interval Scalar t = ti * (Scalar(int(M - m)) / ns) + tf * (Scalar(int(m)) / ns); // value of x at beginning of this interval x3 = x4 = xf; // evaluate partial derivatives at beginning of this interval F.Ode_ind(t, xf, f_t); F.Ode_dep(t, xf, E); // E = f_x if( hasnan(f_t) || hasnan(E) ) { e = nan_vec; return nan_vec; } // E = I - f_x * h / 2 for(i = 0; i < n; i++) { for(j = 0; j < n; j++) E[i * n + j] = - E[i * n + j] * h / two; E[i * n + i] += one; } // LU factor the matrix E # ifndef NDEBUG int sign = LuFactor(ip, jp, E); # else LuFactor(ip, jp, E); # endif CPPAD_ASSERT_KNOWN( sign != 0, "Error in Rosen34: I - f_x * h / 2 not invertible" ); // loop over integration steps for(k = 0; k < 3; k++) { // set location for next function evaluation xtmp = xf; for(l = 0; l < k; l++) { // loop over previous function evaluations Scalar bkl = b[(k-1)*2 + l]; for(i = 0; i < n; i++) { // loop over elements of x xtmp[i] += bkl * g[i*3 + l] * h; } } // ftmp = F(t + a[k] * h, xtmp) F.Ode(t + a[k] * h, xtmp, ftmp); if( hasnan(ftmp) ) { e = nan_vec; return nan_vec; } // Form Eg for this integration step for(i = 0; i < n; i++) Eg[i] = ftmp[i] + ct[k] * f_t[i] * h; for(l = 0; l < k; l++) { for(i = 0; i < n; i++) Eg[i] += cg[(k-1)*3 + l] * g[i*3 + l]; } // Solve the equation E * g = Eg LuInvert(ip, jp, E, Eg); // save solution and advance x3, x4 for(i = 0; i < n; i++) { g[i*3 + k] = Eg[i]; x3[i] += h * d3[k] * Eg[i]; x4[i] += h * d4[k] * Eg[i]; } } // Form Eg for last update to x4 only for(i = 0; i < n; i++) Eg[i] = ftmp[i] + ct[3] * f_t[i] * h; for(l = 0; l < 3; l++) { for(i = 0; i < n; i++) Eg[i] += cg[2*3 + l] * g[i*3 + l]; } // Solve the equation E * g = Eg LuInvert(ip, jp, E, Eg); // advance x4 and accumulate error bound for(i = 0; i < n; i++) { x4[i] += h * d4[3] * Eg[i]; // cant use abs because cppad.hpp may not be included Scalar diff = x4[i] - x3[i]; if( diff < zero ) e[i] -= diff; else e[i] += diff; } // advance xf for this step using x4 xf = x4; } return xf; }
TEST(MathLib, DenseGaussAlgorithmDenseVector) { std::size_t n_rows(50); std::size_t n_cols(n_rows); MathLib::DenseMatrix<double,std::size_t> mat(n_rows, n_cols); // *** fill matrix with arbitrary values // ** initialize random seed srand ( static_cast<unsigned>(time(nullptr)) ); // ** loop over rows and columns for (std::size_t i(0); i<n_rows; i++) { for (std::size_t j(0); j<n_cols; j++) { mat(i,j) = rand()/static_cast<double>(RAND_MAX); } } // *** create solution vector, set all entries to 0.0 MathLib::DenseVector<double> x(n_cols); std::fill(std::begin(x), std::end(x), 0.0); MathLib::DenseVector<double> b0(mat * x); // *** create other right hand sides, // set all entries of the solution vector to 1.0 std::fill(std::begin(x), std::end(x), 1.0); MathLib::DenseVector<double> b1(mat * x); std::generate(std::begin(x), std::end(x), std::rand); MathLib::DenseVector<double> b2(mat * x); // right hand side and solution vector with random entries MathLib::DenseVector<double> b3(mat * x); MathLib::DenseVector<double> b3_copy(mat * x); MathLib::DenseVector<double> x3 (n_cols); std::generate(std::begin(x3),std::end(x3), std::rand); MathLib::GaussAlgorithm<MathLib::DenseMatrix<double, std::size_t>, MathLib::DenseVector<double>> gauss(mat); // solve with b0 as right hand side gauss.solve(b0, true); for (std::size_t i(0); i<n_rows; i++) { ASSERT_NEAR(b0[i], 0.0, 1e5 * std::numeric_limits<float>::epsilon()); } // solve with b1 as right hand side gauss.solve(b1, false); for (std::size_t i(0); i<n_rows; i++) { ASSERT_NEAR(b1[i], 1.0, std::numeric_limits<float>::epsilon()); } // solve with b2 as right hand side gauss.solve(b2, false); for (std::size_t i(0); i<n_rows; i++) { ASSERT_NEAR(fabs(b2[i]-x[i])/fabs(x[i]), 0.0, std::numeric_limits<float>::epsilon()); } gauss.solve(b3, x3, false); for (std::size_t i(0); i<n_rows; i++) { ASSERT_NEAR(fabs(x3[i]-x[i])/fabs(x[i]), 0.0, std::numeric_limits<float>::epsilon()); } // assure entries of vector b3 are not changed for (std::size_t i(0); i<n_rows; i++) { ASSERT_NEAR(fabs(b3[i]-b3_copy[i])/fabs(b3[i]), 0.0, std::numeric_limits<float>::epsilon()); } }