// tsncom29.cc // Nick Macks (macks@fnal.gov), Summer 2002 // CovMatrices: CovMatrixX*VectorX multiplication #include "CovMatrices/CovMatrix.h" #include "CovMatrices/CovMatrix2.h" #include "CovMatrices/CovMatrix3.h" #include "CovMatrices/CovMatrix4.h" #include "CovMatrices/CovMatrix5.h" #include "CovMatrices/CovMatrix6.h" #include #include "CovMatrices/Vector2.h" #include "CovMatrices/Vector3.h" #include "CovMatrices/Vector4.h" #include "CovMatrices/Vector5.h" #include "CovMatrices/Vector6.h" using namespace std; using CovMatrices::CovMatrix; using CovMatrices::CovMatrix2; using CovMatrices::CovMatrix3; using CovMatrices::CovMatrix4; using CovMatrices::CovMatrix5; using CovMatrices::CovMatrix6; using CovMatrices::Vector2; using CovMatrices::Vector3; using CovMatrices::Vector4; using CovMatrices::Vector5; using CovMatrices::Vector6; // Function declarations void Identification(); void GetDimension(int&); void Describe(const int&); void BuildCovMatrix(CovMatrix&); void BuildCovMatrix2(CovMatrix2&); void BuildCovMatrix3(CovMatrix3&); void BuildCovMatrix4(CovMatrix4&); void BuildCovMatrix5(CovMatrix5&); void BuildCovMatrix6(CovMatrix6&); void BuildVector(vector&); void BuildVector2(Vector2&); void BuildVector3(Vector3&); void BuildVector4(Vector4&); void BuildVector5(Vector5&); void BuildVector6(Vector6&); void Show(const CovMatrix&, const vector&); void Show2(const CovMatrix2&, const Vector2&); void Show3(const CovMatrix3&, const Vector3&); void Show4(const CovMatrix4&, const Vector4&); void Show5(const CovMatrix5&, const Vector5&); void Show6(const CovMatrix6&, const Vector6&); void GetCalcs(int&); void GetRuns(int&); void Calculate(CovMatrix&, vector&, const int&, const int&); void Calculate2(CovMatrix2&, Vector2&, const int&, const int&); void Calculate3(CovMatrix3&, Vector3&, const int&, const int&); void Calculate4(CovMatrix4&, Vector4&, const int&, const int&); void Calculate5(CovMatrix5&, Vector5&, const int&, const int&); void Calculate6(CovMatrix6&, Vector6&, const int&, const int&); // Package ID void Identification() { cout << "Using CovMatrices\n"; } // Ask for the desired dimension void GetDimension(int& dimension) { cout << "Enter the desired dimension(1-6): "; cin >> dimension; while ( (dimension < 1) || (dimension > 6) ) { cout << "Enter an integer between 1 and 6: "; cin >> dimension; } } // Describe how the matrix and the vector were defined void Describe(const int& dimension) { if (dimension == 1) cout << "Matrix was defined 'CovMatrix'\n"; else cout << "Matrix was defined 'CovMatrix" << dimension << "'\n"; if (dimension == 1) cout << "Vector was defined 'vector'\n"; else cout << "Vector was defined 'Vector" << dimension << "'\n"; } // Built a 1-dimension CovMatrix void BuildCovMatrix(CovMatrix& matrix) { matrix(0,0) = 1000; } // Built a 2-dimension CovMatrix void BuildCovMatrix2(CovMatrix2& matrix2) { for (int i=0; i<2; ++i) { for (int j=0; j<2; ++j) { if (i == j) matrix2(i,j) = 1000 + i*100; else if (i > j) matrix2(i,j) = 2 + i*2 + j*(2*2); } } } // Built a 3-dimension CovMatrix void BuildCovMatrix3(CovMatrix3& matrix3) { for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { if (i == j) matrix3(i,j) = 1000 + i*100; else if (i > j) matrix3(i,j) = 2 + i*2 + j*(3*2); } } } // Built a 4-dimension CovMatrix void BuildCovMatrix4(CovMatrix4& matrix4) { for (int i=0; i<4; ++i) { for (int j=0; j<4; ++j) { if (i == j) matrix4(i,j) = 1000 + i*100; else if (i > j) matrix4(i,j) = 2 + i*2 + j*(4*2); } } } // Built a 5-dimension CovMatrix void BuildCovMatrix5(CovMatrix5& matrix5) { for (int i=0; i<5; ++i) { for (int j=0; j<5; ++j) { if (i == j) matrix5(i,j) = 1000 + i*100; else if (i > j) matrix5(i,j) = 2 + i*2 + j*(5*2); } } } // Built a 6-dimension CovMatrix void BuildCovMatrix6(CovMatrix6& matrix6) { for (int i=0; i<6; ++i) { for (int j=0; j<6; ++j) { if (i == j) matrix6(i,j) = 1000 + i*100; else if (i > j) matrix6(i,j) = 2 + i*2 + j*(6*2); } } } // Build a 1-dimensional Vector void BuildVector(vector& vector) { vector.push_back(2); } // Build a 2-dimensional Vector void BuildVector2(Vector2& vector2) { for (int i=0; i<2; ++i) { vector2[i] = 2 + 2*i; } } // Build a 3-dimensional Vector void BuildVector3(Vector3& vector3) { for (int i=0; i<3; ++i) { vector3[i] = 2 + 2*i; } } // Build a 4-dimensional Vector void BuildVector4(Vector4& vector4) { for (int i=0; i<4; ++i) { vector4[i] = 2 + 2*i; } } // Build a 5-dimensional Vector void BuildVector5(Vector5& vector5) { for (int i=0; i<5; ++i) { vector5[i] = 2 + 2*i; } } // Build a 6-dimensional Vector void BuildVector6(Vector6& vector6) { for (int i=0; i<6; ++i) { vector6[i] = 2 + 2*i; } } // Show the 1-dimensional CovMatrix and vector void Show(const CovMatrix& matrix, const vector& vector) { cout << "Using matrix =\n" << matrix << "\n"; cout << "Using vector =\n" << vector[0] << "\n"; } // Show the 2-dimensional CovMatrix and vector void Show2(const CovMatrix2& matrix2, const Vector2& vector2) { cout << "Using matrix =\n" << matrix2 << "\n"; cout << "Using vector =\n" << vector2 << "\n"; } // Show the 3-dimensional CovMatrix and vector void Show3(const CovMatrix3& matrix3, const Vector3& vector3) { cout << "Using matrix =\n" << matrix3 << "\n"; cout << "Using vector =\n" << vector3 << "\n"; } // Show the 4-dimensional CovMatrix and vector void Show4(const CovMatrix4& matrix4, const Vector4& vector4) { cout << "Using matrix =\n" << matrix4 << "\n"; cout << "Using vector =\n" << vector4 << "\n"; } // Show the 5-dimensional CovMatrix and vector void Show5(const CovMatrix5& matrix5, const Vector5& vector5) { cout << "Using matrix =\n" << matrix5 << "\n"; cout << "Using vector =\n" << vector5 << "\n"; } // Show the 6-dimensional CovMatrix and vector void Show6(const CovMatrix6& matrix6, const Vector6& vector6) { cout << "Using matrix =\n" << matrix6 << "\n"; cout << "Using vector =\n" << vector6 << "\n"; } // Get the number of calculations void GetCalcs(int& N) { cout << "How many multiplications? "; cin >> N; } // Get the number of runs void GetRuns(int& run) { cout << "How many runs? "; cin >> run; cout << "\n"; } // Multiply the 1-dimensional matrix and vector void Calculate(CovMatrix& matrix1, vector& vector1, const int& N, const int& runs) { // Define a counter int counter = 0; // Definee a double to hold the product // and a temporary vector to hold the result double product = 0.; vector temp; // Loop "run" times for (int r=0; r v; Vector2 v2; Vector3 v3; Vector4 v4; Vector5 v5; Vector6 v6; // Describe how the matrix and the vector were defined Describe (dim); // Build the matrix switch(dim) { case 1: BuildCovMatrix(m); break; case 2: BuildCovMatrix2(m2); break; case 3: BuildCovMatrix3(m3); break; case 4: BuildCovMatrix4(m4); break; case 5: BuildCovMatrix5(m5); break; case 6: BuildCovMatrix6(m6); break; } // Build the vector switch(dim) { case 1: BuildVector(v); break; case 2: BuildVector2(v2); break; case 3: BuildVector3(v3); break; case 4: BuildVector4(v4); break; case 5: BuildVector5(v5); break; case 6: BuildVector6(v6); break; } // Show the actual matrix and vector switch(dim) { case 1: Show(m, v); break; case 2: Show2(m2, v2); break; case 3: Show3(m3, v3); break; case 4: Show4(m4, v4); break; case 5: Show5(m5, v5); break; case 6: Show6(m6, v6); break; } // Calculation parameters int calc = 0; GetCalcs(calc); // times to perform the calculation int run = 0; GetRuns(run); // number of runs // Do the multiplications switch(dim) { case 1: Calculate(m, v, calc, run); break; case 2: Calculate2(m2, v2, calc, run); break; case 3: Calculate3(m3, v3, calc, run); break; case 4: Calculate4(m4, v4, calc, run); break; case 5: Calculate5(m5, v5, calc, run); break; case 6: Calculate6(m6, v6, calc, run); break; } return 0; }