?
#include
#include
#include
"mtl/mtl.h"???????????????????????????????????????????????????????????????????????????????????????
#include
using
namespace std;
using
namespace mtl;
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
template
<
class Matrix>
void
print_matrix(Matrix& mat,const string& description)
{
?????? std::cout << description;
?
?????? std::cout <<'[';
??????
for
(Matrix::iterator i = mat.begin(); i!=mat.end();++i)
??????
{
??????
?
for
(Matrix::OneD::iterator j =(*i).begin(); j!=(*i).end();++j)
??????
?
{
?????????????
? std::cout <<'\t'<<*j;
??????
?
}
?
??????
? std::cout <<((i+1== mat.end())?"\t]\n":? "\n");
??????
}
}
?
int
main(int argc,char* argv[])
{
?
typedef matrix<float, rectangle<>, dense<>, row_major>::type Matrix;
?
?
const Matrix::size_type MAX_ROW =3, MAX_COL =3;
?
? Matrix? A(MAX_ROW,MAX_COL),B(MAX_ROW,MAX_COL),C(MAX_ROW,MAX_COL);
?
?
// fill Matrix A with the index syntax
?
for
(Matrix::size_type i=0; i<MAX_ROW;++i)
?
{
??????
?
for
(Matrix::size_type j=0; j<MAX_COL;++j)
??????
?
{
?????????????
? A(i, j)= Matrix::value_type(rand()%50);
??????
?
}
?
}
?
?
// fill Matrix B with the iterator syntax
?
for
(Matrix::iterator i=B.begin(); i!=B.end();++i)
?
{
??????
?
for
(Matrix::OneD::iterator j=(*i).begin(); j!=(*i).end();++j)
??????
?
{
?????????????
?
*j = Matrix::value_type(rand()%50);
??????
?
}
?
}
?
? print_matrix(A,"A=\n");
? print_matrix(B,"B=\n");
?
?
// Matrix C = A + B
? add(A, C);
? add(B,C);
? print_matrix(C,"C = A + B? \n");
?
?
// Matrix C = A * B^T,? B^T: transpose of B
? transpose(B);
? print_matrix(B,"B^T=\n");
? zero_matrix(C);??????? // because mult(A, B, C): C += A*B ? mult(A,B,C);
? print_matrix(C,"C = A * B^T\n");
?
return
0
;
}
?
|