00001 #include "Teuchos_SerialDenseMatrix.hpp"
00002 #include "Teuchos_SerialDenseSolver.hpp"
00003 #include "Teuchos_RCP.hpp"
00004 #include "Teuchos_Version.hpp"
00005
00006 int main(int argc, char* argv[])
00007 {
00008 std::cout << Teuchos::Teuchos_Version() << std::endl << std::endl;
00009
00010
00011
00012 Teuchos::SerialDenseMatrix<int,double> Empty_Matrix;
00013
00014 Teuchos::SerialDenseMatrix<int,double> My_Matrix( 3, 4 );
00015
00016 Teuchos::SerialDenseMatrix<int,double> My_Copy1( My_Matrix ),
00017
00018 My_Copy2( Teuchos::Copy, My_Matrix, 3, 3 ),
00019
00020 My_Copy3( Teuchos::View, My_Matrix, 2, 3, 1, 1 );
00021
00022
00023 int rows, cols, stride;
00024 rows = My_Copy3.numRows();
00025 cols = My_Copy3.numCols();
00026 stride = My_Copy3.stride();
00027
00028
00029 Empty_Matrix.shape( 3, 3 );
00030 My_Matrix.reshape( 3, 3 );
00031
00032
00033 My_Matrix.random();
00034 My_Copy1.putScalar( 1.0 );
00035 My_Copy2(1,1) = 10.0;
00036 Empty_Matrix = My_Matrix;
00037
00038
00039 Teuchos::SerialDenseMatrix<int,double> My_Prod( 3, 2 );
00040
00041 My_Prod.multiply( Teuchos::NO_TRANS, Teuchos::TRANS,
00042 1.0, My_Matrix, My_Copy3, 0.0 );
00043 My_Copy2 += My_Matrix;
00044 My_Copy2.scale( 0.5 );
00045
00046
00047 double *My_Array=0, *My_Column=0;
00048 My_Array = My_Matrix.values();
00049 My_Column = My_Matrix[2];
00050
00051
00052 double norm_one, norm_inf, norm_fro;
00053 norm_one = My_Matrix.normOne();
00054 norm_inf = My_Matrix.normInf();
00055 norm_fro = My_Matrix.normFrobenius();
00056
00057
00058
00059 if (Empty_Matrix == My_Matrix) {
00060 std::cout<< "The matrices are the same!" <<std::endl;
00061 }
00062
00063 if (My_Copy2 != My_Matrix) {
00064 std::cout<< "The matrices are different!" <<std::endl;
00065 }
00066
00067
00068 Teuchos::SerialDenseSolver<int,double> My_Solver;
00069 Teuchos::SerialDenseMatrix<int,double> X(3,1), B(3,1);
00070 X.putScalar(1.0);
00071 B.multiply( Teuchos::NO_TRANS, Teuchos::NO_TRANS, 1.0, My_Matrix, X, 0.0 );
00072 X.putScalar(0.0);
00073
00074 int info = 0;
00075 My_Solver.setMatrix( Teuchos::rcp( &My_Matrix, false ) );
00076 My_Solver.setVectors( Teuchos::rcp( &X, false ), Teuchos::rcp( &B, false ) );
00077 info = My_Solver.factor();
00078 if (info != 0)
00079 std::cout << "Teuchos::SerialDenseSolver::factor() returned : " << info << std::endl;
00080 info = My_Solver.solve();
00081 if (info != 0)
00082 std::cout << "Teuchos::SerialDenseSolver::solve() returned : " << info << std::endl;
00083
00084
00085 std::cout<< std::endl << My_Matrix << std::endl;
00086 std::cout<< X << std::endl;
00087
00088 return 0;
00089 }