void FunctorClass::fundapcpp() { double arrl[LIM] = {1, 2, 3, 4, 5, 6}; double arr2[LIM] = {7, 8, 9, 1, 2, 3}; std::vector<double> gr8(arrl, arrl + LIM); std::vector<double> m8(arr2, arr2 + LIM); std::cout.setf(std::ios_base::fixed); std::cout.precision(2); // number of numbers after dot std::cout << "gr8:\t"; for_each(gr8.begin(), gr8.end(), show); std::cout << std::endl; std::cout << "m8: \t"; for_each(m8.begin (), m8.end(), show); std::cout << std::endl; std::vector<double> sum(LIM); transform(gr8.begin (), gr8.end(), m8.begin(), sum.begin(), std::plus<double> ()); std::cout << "sum:\t"; for_each(sum.begin (), sum.end(), show); std::cout << std::endl; std::vector<double> prod(LIM); transform(gr8.begin (), gr8.end(), prod.begin(), bind1st(std::multiplies<double> (), 2.5)); std::cout << "prod:\t"; for_each(prod.begin (), prod.end(), show); std::cout << std::endl; }
void CCuboid::GetGripperPositions(std::list<GripData> *list, bool just_for_endof) { gp_Pnt o = m_pos.Location(); gp_Pnt px(o.XYZ() + m_pos.XDirection().XYZ() * m_x); gp_Pnt py(o.XYZ() + m_pos.YDirection().XYZ() * m_y); gp_Dir z_dir = m_pos.XDirection() ^ m_pos.YDirection(); gp_Pnt pz(o.XYZ() + z_dir.XYZ() * m_z); gp_Pnt m2(o.XYZ() + m_pos.XDirection().XYZ() * m_x + m_pos.YDirection().XYZ() * m_y/2); gp_Pnt m3(o.XYZ() + m_pos.XDirection().XYZ() * m_x/2 + m_pos.YDirection().XYZ() * m_y); gp_Pnt m8(o.XYZ() + m_pos.YDirection().XYZ() * m_y/2 + z_dir.XYZ() * m_z); gp_Pnt pxy(o.XYZ() + m_pos.XDirection().XYZ() * m_x + m_pos.YDirection().XYZ() * m_y); gp_Pnt pxz(o.XYZ() + m_pos.XDirection().XYZ() * m_x + z_dir.XYZ() * m_z); gp_Pnt pyz(o.XYZ() + m_pos.YDirection().XYZ() * m_y + z_dir.XYZ() * m_z); gp_Pnt pxyz(o.XYZ() + m_pos.XDirection().XYZ() * m_x + m_pos.YDirection().XYZ() * m_y + z_dir.XYZ() * m_z); list->push_back(GripData(GripperTypeTranslate,o.X(),o.Y(),o.Z(),NULL)); list->push_back(GripData(GripperTypeRotateObject,px.X(),px.Y(),px.Z(),NULL)); list->push_back(GripData(GripperTypeRotateObject,py.X(),py.Y(),py.Z(),NULL)); list->push_back(GripData(GripperTypeRotateObject,pz.X(),pz.Y(),pz.Z(),NULL)); list->push_back(GripData(GripperTypeScale,pxyz.X(),pxyz.Y(),pxyz.Z(),NULL)); list->push_back(GripData(GripperTypeRotate,pxy.X(),pxy.Y(),pxy.Z(),NULL)); list->push_back(GripData(GripperTypeRotate,pxz.X(),pxz.Y(),pxz.Z(),NULL)); list->push_back(GripData(GripperTypeRotate,pyz.X(),pyz.Y(),pyz.Z(),NULL)); list->push_back(GripData(GripperTypeObjectScaleX,m2.X(),m2.Y(),m2.Z(),NULL)); list->push_back(GripData(GripperTypeObjectScaleY,m3.X(),m3.Y(),m3.Z(),NULL)); list->push_back(GripData(GripperTypeObjectScaleZ,m8.X(),m8.Y(),m8.Z(),NULL)); }
TEST(Matrix, shouldCompare) { Matrix m1(1,1,1); Matrix m2(1,1,1); Matrix m3(2,1,1); Matrix m4(1,2,1); Matrix m5(1,1,2); CHECK(m1 == m1); CHECK(m1 == m2); CHECK(m2 == m1); CHECK(!(m1 == m3)); CHECK(!(m1 == m4)); CHECK(!(m5 == m1)); CHECK(m5 != m1); float v6[] = { 1, 1, 1, 1 }; Matrix m6(2,2); m6.setAll(v6); float v7[] = { 1, 1, 1, 1 }; Matrix m7(2,2); m7.setAll(v7); float v8[] = { 1, 1, 1, 2 }; Matrix m8(2,2); m8.setAll(v8); CHECK(m7 == m6); CHECK(!(m8 == m6)); CHECK(m6 != m8); CHECK(m1 != m6); CHECK(m6 != m1); }
bool CCuboid::Stretch(const double *p, const double* shift, void* data) { gp_Pnt vp = make_point(p); gp_Vec vshift = make_vector(shift); gp_Pnt o = m_pos.Location(); gp_Dir z_dir = m_pos.XDirection() ^ m_pos.YDirection(); gp_Pnt m2(o.XYZ() + m_pos.XDirection().XYZ() * m_x + m_pos.YDirection().XYZ() * m_y/2); gp_Pnt m3(o.XYZ() + m_pos.XDirection().XYZ() * m_x/2 + m_pos.YDirection().XYZ() * m_y); gp_Pnt m8(o.XYZ() + m_pos.YDirection().XYZ() * m_y/2 + z_dir.XYZ() * m_z); bool make_a_new_cuboid = false; if(m2.IsEqual(vp, wxGetApp().m_geom_tol)){ m2 = m2.XYZ() + vshift.XYZ(); double new_x = gp_Vec(m2.XYZ()) * gp_Vec(m_pos.XDirection()) - gp_Vec(o.XYZ()) * gp_Vec(m_pos.XDirection()); if(new_x > 0){ make_a_new_cuboid = true; m_x = new_x; } } else if(m3.IsEqual(vp, wxGetApp().m_geom_tol)){ m3 = m3.XYZ() + vshift.XYZ(); double new_y = gp_Vec(m3.XYZ()) * gp_Vec(m_pos.YDirection()) - gp_Vec(o.XYZ()) * gp_Vec(m_pos.YDirection()); if(new_y > 0){ make_a_new_cuboid = true; m_y = new_y; } } else if(m8.IsEqual(vp, wxGetApp().m_geom_tol)){ m8 = m8.XYZ() + vshift.XYZ(); double new_z = gp_Vec(m8.XYZ()) * gp_Vec(z_dir) - gp_Vec(o.XYZ()) * gp_Vec(z_dir); if(new_z > 0){ make_a_new_cuboid = true; m_z = new_z; } } if(make_a_new_cuboid) { CCuboid* new_object = new CCuboid(m_pos, m_x, m_y, m_z, m_title.c_str(), m_color, m_opacity); new_object->CopyIDsFrom(this); HEEKSOBJ_OWNER->Add(new_object, NULL); HEEKSOBJ_OWNER->Remove(this); wxGetApp().m_marked_list->Clear(false); wxGetApp().m_marked_list->Add(new_object, true); } return true; }
void FunctorClass::transform_func() { const int LIM = 5; double arrl[LIM] = {36, 39, 42, 45, 48}; double arr2[LIM] = {64, 61, 58, 55, 52}; std::vector<double> m8(arr2, arr2 + LIM); std::vector<double> gr8(arrl, arrl + LIM); std::ostream_iterator<double, char> out(std::cout, "\t"); std::cout << "simply container:\n\t"; copy(gr8.begin(), gr8.end(), out); std::cout << "\n\t"; copy(m8.begin(), m8.end(), out); std::cout << "\nsqrt:\n\t"; transform(gr8.begin(), gr8.end(), out, sqrt); std::cout << "\naverage:\n\t"; transform(gr8.begin(), gr8.end(), m8.begin(), out, average); std::cout << "\nstd::plus<double>()\n\t"; transform(gr8.begin(), gr8.end(), m8.begin(), out, std::plus<double>()); std::cout << "\nstd::minus<double>()\n\t"; transform(gr8.begin(), gr8.end(), m8.begin(), out, std::minus<double>()); std::cout << "\nstd::multiplies<double>()\n\t"; transform(gr8.begin(), gr8.end(), m8.begin(), out, std::multiplies<double>()); // or times, for old realization std::cout << "\nstd::divides<double>()\n\t"; transform(gr8.begin(), gr8.end(), m8.begin(), out, std::divides<double>()); std::cout << "\nstd::greater<double>()\t(it means '>')\n\t"; transform(gr8.begin(), gr8.end(), m8.begin(), out, std::greater<double>()); // it means '>' std::cout << "\nstd::less<double>()\t(it means '<')\n\t"; transform(gr8.begin(), gr8.end(), m8.begin(), out, std::less<double>()); // it means '<' /* + plus - minus * multiplies // or times, for old realization / divides % modulus - negate == equal_to != not_equal_to > greater < less >= greater_equal <= less_equal && logical_and || logical_or ! logical_not */ }
void funclike(void) { #define stringify(x) #x expect_string("5", stringify(5)); expect_string("x", stringify(x)); expect_string("x y", stringify(x y)); expect_string("x y", stringify( x y )); expect_string("x + y", stringify( x + y )); expect_string("x + y", stringify(/**/x/**/+/**//**/ /**/y/**/)); expect_string("x+y", stringify( x+y )); expect_string("'a'", stringify('a')); expect_string("'\\''", stringify('\'')); expect_string("\"abc\"", stringify("abc")); expect_string("ZERO", stringify(ZERO)); #define m1(x) x expect(5, m1(5)); expect(7, m1((5 + 2))); expect(8, m1(plus(5, 3))); expect(10, m1() 10); expect(14, m1(2 + 2 +) 10); #define m2(x) x + x expect(10, m2(5)); #define m3(x, y) x * y expect(50, m3(5, 10)); expect(11, m3(2 + 2, 3 + 3)); #define m4(x, y) x + y + TWO expect(17, m4(5, 10)); #define m6(x, ...) x + __VA_ARGS__ expect(20, m6(2, 18)); expect(25, plus(m6(2, 18, 5))); #define plus(x, y) x * y + plus(x, y) expect(11, plus(2, 3)); #undef plus #define plus(x, y) minus(x, y) #define minus(x, y) plus(x, y) expect(31, plus(30, 1)); expect(29, minus(30, 1)); // This is not a function-like macro. #define m7 (0) + 1 expect(1, m7); #define m8(x, y) x ## y expect(2, m8(TW, O)); expect(0, m8(ZERO,)); #define m9(x, y, z) x y + z expect(8, m9(1,, 7)); #define m10(x) x ## x expect_string("a", "a" m10()); #define hash_hash # ## # #define mkstr(a) # a #define in_between(a) mkstr(a) #define join(c, d) in_between(c hash_hash d) expect_string("x ## y", join(x, y)); int m14 = 67; #define m14(x) x expect(67, m14); expect(67, m14(m14)); int a = 68; #define glue(x, y) x ## y glue(a+, +); expect(69, a); #define identity(x) stringify(x) expect_string("aa A B aa C", identity(m10(a) A B m10(a) C)); #define identity2(x) stringify(z ## x) expect_string("zA aa A B aa C", identity2(A m10(a) A B m10(a) C)); #define m15(x) x x expect_string("a a", identity(m15(a))); #define m16(x) (x,x) expect_string("(a,a)", identity(m16(a))); }
/*int testMat3Implementation() { int nrOfErrors = 0; std::cout << "Testing mat3 class" << std::endl; float a1[] = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f}; float a2[] = {3.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 1.0f}; float a3[] = {4.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 1.0f, 1.0f, 2.0f}; egc::mat3 m1(a1), m2(a2), m3(a3), m4; m4 = m1 + m2; if(m4 == m3) std::cout << "\tCorrect + operation" << std::endl; else { std::cout << "\tIncorrect + operation" << std::endl; nrOfErrors++; } float a5[] = {3.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 3.0f, 3.0f, 3.0f}; egc::mat3 m5(a5); m4 = m1 * 3.0f; if(m4 == m5) std::cout << "\tCorrect * (with scalar value) operation" << std::endl; else { std::cout << "\tIncorrect * (with scalar value) operation" << std::endl; nrOfErrors++; } float a6[] = {3.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 1.0f, 1.0f, 1.0f}; egc::mat3 m6(a6); m4 = m1 * m2; if(m4 == m6) std::cout << "\tCorrect * (with another matrix) operation" << std::endl; else { std::cout << "\tIncorrect * (with another matrix) operation" << std::endl; nrOfErrors++; } egc::vec3 v1(1.0f, 1.0f, 1.0f); egc::vec3 v2(4.0f, 4.0f, 1.0f); egc::vec3 v3; v3 = m4 * v1; if(v3 == v2) std::cout << "\tCorrect * (with a vec3) operation" << std::endl; else { std::cout << "\tIncorrect * (with a vec3) operation" << std::endl; nrOfErrors++; } float a7[] = {-4.0f, 0.0f, 1.0f, -3.0f, 2.0f, 4.0f, 3.0f, -2.0f, -1.0f}; egc::mat3 m7(a7); if(std::abs(m7.determinant() + 24.0f) < std::numeric_limits<float>::epsilon()) std::cout << "\tCorrect determinant operation" << std::endl; else { std::cout << "\tIncorrect determinant operation" << std::endl; nrOfErrors++; } float a8[] = {-4.0f, -3.0f, 3.0f, 0.0f, 2.0f, -2.0f, 1.0f, 4.0f, -1.0f}; egc::mat3 m8(a8); if(m7.transpose() == m8) std::cout << "\tCorrect transpose operation" << std::endl; else { std::cout << "\tIncorrect transpose operation" << std::endl; nrOfErrors++; } float a9[] = {-1.0f/4.0f, 1.0f/12.0f, 1.0f/12.0f, -3.0f/8.0f, -1.0f/24.0f, -13.00f/24.0f, 0.0f, 1.0f/3.0f, 1.0f/3.0f}; egc::mat3 m9(a9); if(m7.inverse() == m9) std::cout << "\tCorrect inverse operation" << std::endl; else { std::cout << "\tIncorrect inverse operation" << std::endl; nrOfErrors++; } return nrOfErrors; } */ int testMat4Implementation() { int nrOfErrors = 0; std::cout << "Testing mat4 class" << std::endl; float a1[] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f}; float a2[] = {3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; float a3[] = {4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 1.0f, 1.0f, 1.0f, 2.0f}; egc::mat4 m1(a1), m2(a2), m3(a3), m4; m4 = m1 + m2; if(m4 == m3) std::cout << "\tCorrect + operation" << std::endl; else { std::cout << "\tIncorrect + operation" << std::endl; nrOfErrors++; } float a5[] = {3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 3.0f, 3.0f, 3.0f, 3.0f}; egc::mat4 m5(a5); m4 = m1 * 3.0f; if(m4 == m5) std::cout << "\tCorrect * (with scalar value) operation" << std::endl; else { std::cout << "\tIncorrect * (with scalar value) operation" << std::endl; nrOfErrors++; } float a6[] = {3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f}; egc::mat4 m6(a6); m4 = m1 * m2; if(m4 == m6) std::cout << "\tCorrect * (with another matrix) operation" << std::endl; else { std::cout << "\tIncorrect * (with another matrix) operation" << std::endl; nrOfErrors++; } egc::vec4 v1(1.0f, 1.0f, 1.0f, 1.0f); egc::vec4 v2(4.0f, 4.0f, 4.0f, 1.0f); egc::vec4 v3; v3 = m4 * v1; if(v3 == v2) std::cout << "\tCorrect * (with a vec4) operation" << std::endl; else { std::cout << "\tIncorrect * (with a vec4) operation" << std::endl; nrOfErrors++; } float a7[] = {3.0f, 4.0f, 3.0f, 9.0f, 2.0f, 0.0f, 0.0f, 2.0f, 0.0f, 1.0f, 2.0f, 3.0f, 1.0f, 2.0f, 1.0f, 1.0f}; egc::mat4 m7(a7); if(std::abs(m7.determinant() - 24.0f) < std::numeric_limits<float>::epsilon()) std::cout << "\tCorrect determinant operation" << std::endl; else { std::cout << "\tIncorrect determinant operation" << std::endl; nrOfErrors++; } float a8[] = {3.0f, 2.0f, 0.0f, 1.0f, 4.0f, 0.0f, 1.0f, 2.0f, 3.0f, 0.0f, 2.0f, 1.0f, 9.0f, 2.0f, 3.0f, 1.0f}; egc::mat4 m8(a8); if(m7.transpose() == m8) std::cout << "\tCorrect transpose operation" << std::endl; else { std::cout << "\tIncorrect transpose operation" << std::endl; nrOfErrors++; } float a9[] = {-1.0f/4.0f, 2.0f/3.0f, 1.0f/6.0f, 5.0f/12.0f, 1.0f/4.0f, -1.0f/2.0f, -1.0/2.0f, 1.0f/4.0f, -1.0f/2.0f, 1.0f/2.0f, 1.0f, 1.0f/2.0f, 1.0f/4.0f, -1.0f/6.0f, -1.0/6.0f, -5.0f/12.0f}; egc::mat4 m9(a9); if(m7.inverse() == m9) std::cout << "\tCorrect inverse operation" << std::endl; else { std::cout << "\tIncorrect inverse operation" << std::endl; nrOfErrors++; } return nrOfErrors; }
void MatrixTest::test_constructor(void) { message += "test_constructor\n"; std::string file_name = "../data/matrix.dat"; // Default Matrix<size_t> m1; assert_true(m1.get_rows_number() == 0, LOG); assert_true(m1.get_columns_number() == 0, LOG); // Rows and columns numbers Matrix<size_t> m2(0, 0); assert_true(m2.get_rows_number() == 0, LOG); assert_true(m2.get_columns_number() == 0, LOG); Matrix<double> m3(1, 1, 1.0); assert_true(m3.get_rows_number() == 1, LOG); assert_true(m3.get_columns_number() == 1, LOG); // Rows and columns numbers and initialization Matrix<size_t> m4(0, 0, 1); assert_true(m4.get_rows_number() == 0, LOG); assert_true(m4.get_columns_number() == 0, LOG); Matrix<size_t> m5(1, 1, 1); assert_true(m5.get_rows_number() == 1, LOG); assert_true(m5.get_columns_number() == 1, LOG); assert_true(m5 == true, LOG); // File constructor m1.save(file_name); Matrix<size_t> m6(file_name); assert_true(m6.get_rows_number() == 0, LOG); assert_true(m6.get_columns_number() == 0, LOG); m2.save(file_name); Matrix<size_t> m7(file_name); assert_true(m7.get_rows_number() == 0, LOG); assert_true(m7.get_columns_number() == 0, LOG); m3.save(file_name); Matrix<double> m8(file_name); assert_true(m8.get_rows_number() == 1, LOG); assert_true(m8.get_columns_number() == 1, LOG); m4.save(file_name); Matrix<size_t> m9(file_name); assert_true(m9.get_rows_number() == 0, LOG); assert_true(m9.get_columns_number() == 0, LOG); m5.save(file_name); Matrix<size_t> m10(file_name); assert_true(m10.get_rows_number() == 1, LOG); assert_true(m10.get_columns_number() == 1, LOG); assert_true(m10 == true, LOG); // Copy constructor Matrix<double> a5; Matrix<double> b5(a5); assert_true(b5.get_rows_number() == 0, LOG); assert_true(b5.get_columns_number() == 0, LOG); Matrix<size_t> a6(1, 1, true); Matrix<size_t> b6(a6); assert_true(b6.get_rows_number() == 1, LOG); assert_true(b6.get_columns_number() == 1, LOG); assert_true(b6 == true, LOG); // Operator ++ Matrix<size_t> m11(2, 2, 0); m11(0,0)++; m11(1,1)++; assert_true(m11(0,0) == 1, LOG); assert_true(m11(0,1) == 0, LOG); assert_true(m11(1,0) == 0, LOG); assert_true(m11(1,1) == 1, LOG); }
void wisaConfirmSubmit::onShow() { // overwrite buttons previousButton->setStyleClass("btn btn-success"); previousButton->setText("Toch maar niet"); nextButton->setStyleClass("btn btn-danger"); nextButton->setText("Wijzig Database"); // count accounts in wisa file container<wisaImport::wisaAccount> & wisaAccounts = parentObject->getWisaAccounts(); string m1("Nieuw bestand bevat "); m1 += wisaAccounts.elms(); m1 += " accounts."; message1->setText(m1.wt()); // load all accounts ACCOUNTS & accounts = parentObject->ldap()->getAccounts(); int validAccounts = accounts.elms(); int linkedAccounts = 0; int accountsToRemove = 0; for(int i = 0; i < accounts.elms(); i++) { if(accounts[i].getImportStatus() == WI_DISCARD) { validAccounts--; if(accounts[i].flaggedForRemoval()) accountsToRemove++; } } for(int i = 0; i < wisaAccounts.elms(); i++) { if(wisaAccounts[i].link != nullptr) { linkedAccounts++; } } int newAccounts = wisaAccounts.elms() - linkedAccounts; string m2("De database bevat "); m2 += validAccounts; m2 += " accounts."; message2->setText(m2.wt()); string m3("Er bestaat een geldige link voor "); m3 += linkedAccounts; m3 += " accounts."; message3->setText(m3.wt()); string m4; m4 += accountsToRemove; m4 += " accounts worden verwijderd."; message4->setText(m4.wt()); string m5; m5 += newAccounts; m5 += " accounts worden toegevoegd."; message5->setText(m5.wt()); // count groups in wisa file container<wisaImport::wisaClass> & wisaClasses = parentObject->getWisaClasses(); string m6("Nieuw bestand bevat "); m6 += wisaClasses.elms(); m6 += " klassen."; message6->setText(m6.wt()); // load all accounts GROUPS & groups = parentObject->ldap()->getGroups(); int validGroups = groups.elms(); int linkedGroups = 0; int groupsToRemove = 0; for(int i = 0; i < groups.elms(); i++) { if(groups[i].getImportStatus() == WI_DISCARD) { validGroups--; } else { if(groups[i].flaggedForRemoval()) groupsToRemove++; } } for(int i = 0; i < wisaClasses.elms(); i++) { if(wisaClasses[i].link != nullptr) { linkedGroups++; } } int newGroups = wisaClasses.elms() - linkedGroups; string m7("De database bevat "); m7 += validGroups; m7 += " klassen."; message7->setText(m7.wt()); string m8("Er bestaat een geldige link voor "); m8 += linkedGroups; m8 += " klassen."; message8->setText(m8.wt()); string m9; m9 += groupsToRemove; m9 += " klassen worden verwijderd."; message9->setText(m9.wt()); string m10; m10 += newGroups; m10 += " klassen worden toegevoegd."; message10->setText(m10.wt()); }
int main() try { // Several ways to create and initialize band matrices: // Create with uninitialized values tmv::BandMatrix<double> m1(6,6,1,2); for(int i=0;i<m1.nrows();i++) for(int j=0;j<m1.ncols();j++) if (i<=j+m1.nlo() && j<=i+m1.nhi()) m1(i,j) = 3.*i-j*j+7.; std::cout<<"m1 =\n"<<m1; //! m1 = //! 6 6 //! ( 7 6 3 0 0 0 ) //! ( 10 9 6 1 0 0 ) //! ( 0 12 9 4 -3 0 ) //! ( 0 0 12 7 0 -9 ) //! ( 0 0 0 10 3 -6 ) //! ( 0 0 0 0 6 -3 ) // Create with all 2's. tmv::BandMatrix<double> m2(6,6,1,3,2.); std::cout<<"m2 =\n"<<m2; //! m2 = //! 6 6 //! ( 2 2 2 2 0 0 ) //! ( 2 2 2 2 2 0 ) //! ( 0 2 2 2 2 2 ) //! ( 0 0 2 2 2 2 ) //! ( 0 0 0 2 2 2 ) //! ( 0 0 0 0 2 2 ) // A BandMatrix can be non-square: tmv::BandMatrix<double> m3(6,8,1,3,2.); std::cout<<"m3 =\n"<<m3; //! m3 = //! 6 8 //! ( 2 2 2 2 0 0 0 0 ) //! ( 2 2 2 2 2 0 0 0 ) //! ( 0 2 2 2 2 2 0 0 ) //! ( 0 0 2 2 2 2 2 0 ) //! ( 0 0 0 2 2 2 2 2 ) //! ( 0 0 0 0 2 2 2 2 ) // Create from given elements: double mm[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; tmv::BandMatrix<double,tmv::ColMajor> m4(6,6,2,1); std::copy(mm,mm+20,m4.colmajor_begin()); std::cout<<"m4 (ColMajor) =\n"<<m4; //! m4 (ColMajor) = //! 6 6 //! ( 1 4 0 0 0 0 ) //! ( 2 5 8 0 0 0 ) //! ( 3 6 9 12 0 0 ) //! ( 0 7 10 13 16 0 ) //! ( 0 0 11 14 17 19 ) //! ( 0 0 0 15 18 20 ) tmv::BandMatrix<double,tmv::RowMajor> m5(6,6,2,1); std::copy(mm,mm+20,m5.rowmajor_begin()); std::cout<<"m5 (RowMajor) =\n"<<m5; //! m5 (RowMajor) = //! 6 6 //! ( 1 2 0 0 0 0 ) //! ( 3 4 5 0 0 0 ) //! ( 6 7 8 9 0 0 ) //! ( 0 10 11 12 13 0 ) //! ( 0 0 14 15 16 17 ) //! ( 0 0 0 18 19 20 ) tmv::BandMatrix<double,tmv::DiagMajor> m6(6,6,2,1); std::copy(mm,mm+20,m6.diagmajor_begin()); std::cout<<"m6 (DiagMajor) =\n"<<m6; //! m6 (DiagMajor) = //! 6 6 //! ( 10 16 0 0 0 0 ) //! ( 5 11 17 0 0 0 ) //! ( 1 6 12 18 0 0 ) //! ( 0 2 7 13 19 0 ) //! ( 0 0 3 8 14 20 ) //! ( 0 0 0 4 9 15 ) // Can make from the banded portion of a regular Matrix: tmv::Matrix<double> xm(6,6); for(int i=0;i<xm.nrows();i++) for(int j=0;j<xm.ncols();j++) xm(i,j) = 5.*i-j*j+3.; tmv::BandMatrix<double> m7(xm,3,2); std::cout<<"m7 =\n"<<m7; //! m7 = //! 6 6 //! ( 3 2 -1 0 0 0 ) //! ( 8 7 4 -1 0 0 ) //! ( 13 12 9 4 -3 0 ) //! ( 18 17 14 9 2 -7 ) //! ( 0 22 19 14 7 -2 ) //! ( 0 0 24 19 12 3 ) // Or from a wider BandMatrix: tmv::BandMatrix<double> m8(m7,3,0); std::cout<<"m8 =\n"<<m8; //! m8 = //! 6 6 //! ( 3 0 0 0 0 0 ) //! ( 8 7 0 0 0 0 ) //! ( 13 12 9 0 0 0 ) //! ( 18 17 14 9 0 0 ) //! ( 0 22 19 14 7 0 ) //! ( 0 0 24 19 12 3 ) // Shortcuts to Bi- and Tri-diagonal matrices: tmv::Vector<double> v1(5,1.); tmv::Vector<double> v2(6,2.); tmv::Vector<double> v3(5,3.); tmv::BandMatrix<double> m9 = LowerBiDiagMatrix(v1,v2); tmv::BandMatrix<double> m10 = UpperBiDiagMatrix(v2,v3); tmv::BandMatrix<double> m11 = TriDiagMatrix(v1,v2,v3); std::cout<<"LowerBiDiagMatrix(v1,v2) =\n"<<m9; //! LowerBiDiagMatrix(v1,v2) = //! 6 6 //! ( 2 0 0 0 0 0 ) //! ( 1 2 0 0 0 0 ) //! ( 0 1 2 0 0 0 ) //! ( 0 0 1 2 0 0 ) //! ( 0 0 0 1 2 0 ) //! ( 0 0 0 0 1 2 ) std::cout<<"UpperBiDiagMatrix(v2,v3) =\n"<<m10; //! UpperBiDiagMatrix(v2,v3) = //! 6 6 //! ( 2 3 0 0 0 0 ) //! ( 0 2 3 0 0 0 ) //! ( 0 0 2 3 0 0 ) //! ( 0 0 0 2 3 0 ) //! ( 0 0 0 0 2 3 ) //! ( 0 0 0 0 0 2 ) std::cout<<"TriDiagMatrix(v1,v2,v3) =\n"<<m11; //! TriDiagMatrix(v1,v2,v3) = //! 6 6 //! ( 2 3 0 0 0 0 ) //! ( 1 2 3 0 0 0 ) //! ( 0 1 2 3 0 0 ) //! ( 0 0 1 2 3 0 ) //! ( 0 0 0 1 2 3 ) //! ( 0 0 0 0 1 2 ) // Norms, etc. std::cout<<"Norm1(m1) = "<<Norm1(m1)<<std::endl; //! Norm1(m1) = 30 std::cout<<"Norm2(m1) = "<<Norm2(m1)<<std::endl; //! Norm2(m1) = 24.0314 std::cout<<"NormInf(m1) = "<<NormInf(m1)<<std::endl; //! NormInf(m1) = 28 std::cout<<"NormF(m1) = "<<NormF(m1)<<" = "<<Norm(m1)<<std::endl; //! NormF(m1) = 32.0312 = 32.0312 std::cout<<"MaxAbsElement(m1) = "<<MaxAbsElement(m1)<<std::endl; //! MaxAbsElement(m1) = 12 std::cout<<"Trace(m1) = "<<Trace(m1)<<std::endl; //! Trace(m1) = 32 std::cout<<"Det(m1) = "<<Det(m1)<<std::endl; //! Det(m1) = 67635 // Views: std::cout<<"m1 =\n"<<m1; //! m1 = //! 6 6 //! ( 7 6 3 0 0 0 ) //! ( 10 9 6 1 0 0 ) //! ( 0 12 9 4 -3 0 ) //! ( 0 0 12 7 0 -9 ) //! ( 0 0 0 10 3 -6 ) //! ( 0 0 0 0 6 -3 ) std::cout<<"m1.diag() = "<<m1.diag()<<std::endl; //! m1.diag() = 6 ( 7 9 9 7 3 -3 ) std::cout<<"m1.diag(1) = "<<m1.diag(1)<<std::endl; //! m1.diag(1) = 5 ( 6 6 4 0 -6 ) std::cout<<"m1.diag(-1) = "<<m1.diag(-1)<<std::endl; //! m1.diag(-1) = 5 ( 10 12 12 10 6 ) std::cout<<"m1.subBandMatrix(0,3,0,3,1,1) =\n"<< m1.subBandMatrix(0,3,0,3,1,1); //! m1.subBandMatrix(0,3,0,3,1,1) = //! 3 3 //! ( 7 6 0 ) //! ( 10 9 6 ) //! ( 0 12 9 ) std::cout<<"m1.transpose() =\n"<<m1.transpose(); //! m1.transpose() = //! 6 6 //! ( 7 10 0 0 0 0 ) //! ( 6 9 12 0 0 0 ) //! ( 3 6 9 12 0 0 ) //! ( 0 1 4 7 10 0 ) //! ( 0 0 -3 0 3 6 ) //! ( 0 0 0 -9 -6 -3 ) // rowRange, colRange shrink both dimensions of the matrix to include only // the portions that are in those rows or columns: std::cout<<"m1.rowRange(0,4) =\n"<<m1.rowRange(0,4); //! m1.rowRange(0,4) = //! 4 6 //! ( 7 6 3 0 0 0 ) //! ( 10 9 6 1 0 0 ) //! ( 0 12 9 4 -3 0 ) //! ( 0 0 12 7 0 -9 ) std::cout<<"m1.colRange(1,4) =\n"<<m1.colRange(1,4); //! m1.colRange(1,4) = //! 5 3 //! ( 6 3 0 ) //! ( 9 6 1 ) //! ( 12 9 4 ) //! ( 0 12 7 ) //! ( 0 0 10 ) std::cout<<"m1.diagRange(0,2) =\n"<<m1.diagRange(0,2); //! m1.diagRange(0,2) = //! 6 6 //! ( 7 6 0 0 0 0 ) //! ( 0 9 6 0 0 0 ) //! ( 0 0 9 4 0 0 ) //! ( 0 0 0 7 0 0 ) //! ( 0 0 0 0 3 -6 ) //! ( 0 0 0 0 0 -3 ) std::cout<<"m1.diagRange(-1,1) =\n"<<m1.diagRange(-1,1); //! m1.diagRange(-1,1) = //! 6 6 //! ( 7 0 0 0 0 0 ) //! ( 10 9 0 0 0 0 ) //! ( 0 12 9 0 0 0 ) //! ( 0 0 12 7 0 0 ) //! ( 0 0 0 10 3 0 ) //! ( 0 0 0 0 6 -3 ) // Fortran Indexing: tmv::BandMatrix<double,tmv::FortranStyle> fm1 = m1; std::cout<<"fm1 = m1 =\n"<<fm1; //! fm1 = m1 = //! 6 6 //! ( 7 6 3 0 0 0 ) //! ( 10 9 6 1 0 0 ) //! ( 0 12 9 4 -3 0 ) //! ( 0 0 12 7 0 -9 ) //! ( 0 0 0 10 3 -6 ) //! ( 0 0 0 0 6 -3 ) std::cout<<"fm1(1,1) = "<<fm1(1,1)<<std::endl; //! fm1(1,1) = 7 std::cout<<"fm1(4,3) = "<<fm1(4,3)<<std::endl; //! fm1(4,3) = 12 std::cout<<"fm1.subBandMatrix(1,3,1,3,1,1) =\n"<< fm1.subBandMatrix(1,3,1,3,1,1); //! fm1.subBandMatrix(1,3,1,3,1,1) = //! 3 3 //! ( 7 6 0 ) //! ( 10 9 6 ) //! ( 0 12 9 ) std::cout<<"fm1.rowRange(1,4) =\n"<<fm1.rowRange(1,4); //! fm1.rowRange(1,4) = //! 4 6 //! ( 7 6 3 0 0 0 ) //! ( 10 9 6 1 0 0 ) //! ( 0 12 9 4 -3 0 ) //! ( 0 0 12 7 0 -9 ) std::cout<<"fm1.colRange(2,4) =\n"<<fm1.colRange(2,4); //! fm1.colRange(2,4) = //! 5 3 //! ( 6 3 0 ) //! ( 9 6 1 ) //! ( 12 9 4 ) //! ( 0 12 7 ) //! ( 0 0 10 ) std::cout<<"fm1.diagRange(0,1) =\n"<<fm1.diagRange(0,1); //! fm1.diagRange(0,1) = //! 6 6 //! ( 7 6 0 0 0 0 ) //! ( 0 9 6 0 0 0 ) //! ( 0 0 9 4 0 0 ) //! ( 0 0 0 7 0 0 ) //! ( 0 0 0 0 3 -6 ) //! ( 0 0 0 0 0 -3 ) std::cout<<"fm1.diagRange(-1,0) =\n"<<fm1.diagRange(-1,0); //! fm1.diagRange(-1,0) = //! 6 6 //! ( 7 0 0 0 0 0 ) //! ( 10 9 0 0 0 0 ) //! ( 0 12 9 0 0 0 ) //! ( 0 0 12 7 0 0 ) //! ( 0 0 0 10 3 0 ) //! ( 0 0 0 0 6 -3 ) // Matrix arithmetic: tmv::BandMatrix<double> m1pm2 = m1 + m2; std::cout<<"m1 + m2 =\n"<<m1pm2; //! m1 + m2 = //! 6 6 //! ( 9 8 5 2 0 0 ) //! ( 12 11 8 3 2 0 ) //! ( 0 14 11 6 -1 2 ) //! ( 0 0 14 9 2 -7 ) //! ( 0 0 0 12 5 -4 ) //! ( 0 0 0 0 8 -1 ) // Works correctly even if matrices are stored in different order: tmv::BandMatrix<double> m5pm6 = m5 + m6; std::cout<<"m5 + m6 =\n"<<m5pm6; //! m5 + m6 = //! 6 6 //! ( 11 18 0 0 0 0 ) //! ( 8 15 22 0 0 0 ) //! ( 7 13 20 27 0 0 ) //! ( 0 12 18 25 32 0 ) //! ( 0 0 17 23 30 37 ) //! ( 0 0 0 22 28 35 ) // Also expands the number of off-diagonals appropriately as needed: tmv::BandMatrix<double> m2pm4 = m2 + m4; std::cout<<"m2 + m4 =\n"<<m2pm4; //! m2 + m4 = //! 6 6 //! ( 3 6 2 2 0 0 ) //! ( 4 7 10 2 2 0 ) //! ( 3 8 11 14 2 2 ) //! ( 0 7 12 15 18 2 ) //! ( 0 0 11 16 19 21 ) //! ( 0 0 0 15 20 22 ) m1 *= 2.; std::cout<<"m1 *= 2 =\n"<<m1; //! m1 *= 2 = //! 6 6 //! ( 14 12 6 0 0 0 ) //! ( 20 18 12 2 0 0 ) //! ( 0 24 18 8 -6 0 ) //! ( 0 0 24 14 0 -18 ) //! ( 0 0 0 20 6 -12 ) //! ( 0 0 0 0 12 -6 ) m2 += m1; std::cout<<"m2 += m1 =\n"<<m2; //! m2 += m1 = //! 6 6 //! ( 16 14 8 2 0 0 ) //! ( 22 20 14 4 2 0 ) //! ( 0 26 20 10 -4 2 ) //! ( 0 0 26 16 2 -16 ) //! ( 0 0 0 22 8 -10 ) //! ( 0 0 0 0 14 -4 ) tmv::Vector<double> v = xm.col(0); std::cout<<"v = "<<v<<std::endl; //! v = 6 ( 3 8 13 18 23 28 ) std::cout<<"m1 * v = "<<m1*v<<std::endl; //! m1 * v = 6 ( 216 396 432 60 162 108 ) std::cout<<"v * m1 = "<<v*m1<<std::endl; //! v * m1 = 6 ( 202 492 780 832 396 -768 ) // Matrix * matrix product also expands bands appropriately: tmv::BandMatrix<double> m1m2 = m1 * m2; std::cout<<"m1 * m2 =\n"<<m1m2; //! m1 * m2 = //! 6 6 //! ( 488 592 400 136 0 12 ) //! ( 716 952 704 264 -8 -8 ) //! ( 528 948 904 272 -56 -32 ) //! ( 0 624 844 464 -320 -104 ) //! ( 0 0 520 452 -80 -332 ) //! ( 0 0 0 264 12 -96 ) // Can mix BandMatrix with other kinds of matrices: std::cout<<"xm * m1 =\n"<<xm*m1; //! xm * m1 = //! 6 6 //! ( 82 48 -120 -348 -336 396 ) //! ( 252 318 180 -128 -276 216 ) //! ( 422 588 480 92 -216 36 ) //! ( 592 858 780 312 -156 -144 ) //! ( 762 1128 1080 532 -96 -324 ) //! ( 932 1398 1380 752 -36 -504 ) tmv::UpperTriMatrix<double> um(xm); std::cout<<"um + m1 =\n"<<um+m1; //! um + m1 = //! 6 6 //! ( 17 14 5 -6 -13 -22 ) //! ( 20 25 16 1 -8 -17 ) //! ( 0 24 27 12 -9 -12 ) //! ( 0 0 24 23 2 -25 ) //! ( 0 0 0 20 13 -14 ) //! ( 0 0 0 0 12 -3 ) tmv::LowerTriMatrix<double> lm(xm); lm *= m8; std::cout<<"lm *= m8 =\n"<<lm; //! lm *= m8 = //! 6 6 //! ( 9 0 0 0 0 0 ) //! ( 80 49 0 0 0 0 ) //! ( 252 192 81 0 0 0 ) //! ( 534 440 252 81 0 0 ) //! ( 744 774 500 224 49 0 ) //! ( 954 1064 782 396 120 9 ) tmv::DiagMatrix<double> dm(xm); m1 *= dm; std::cout<<"m1 *= dm =\n"<<m1; //! m1 *= dm = //! 6 6 //! ( 42 84 54 0 0 0 ) //! ( 60 126 108 18 0 0 ) //! ( 0 168 162 72 -42 0 ) //! ( 0 0 216 126 0 -54 ) //! ( 0 0 0 180 42 -36 ) //! ( 0 0 0 0 84 -18 ) return 0; } catch (tmv::Error& e) { std::cerr<<e<<std::endl; return 1; }