1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib>
#include<conio.h>
#include <iostream>
#include <cmath>
#include <vector>
#define nxsrc 12
#define nysrc 28
using namespace std;
void print(vector<vector<int> > matrix, int r, int c)
{ for (int i=0; i<r; ++i)
{
for (int j=0;j<c;++j){
cout<<matrix[i][j];
cout<<" " ;}
cout<<endl;
}
}
vector<vector<int> > transpose(vector<vector<int> > matrix, int r, int c)
{
vector<vector< int> > outtrans(nysrc);
for ( int i=0;i<c;i++){
outtrans[i].resize(r);
}
for (int i=0;i<r;++i){
for (int j=0;j<c;++j)
outtrans[j][i] = matrix[i][j];
}
return outtrans;
}
vector<vector<int> > multiply(vector<vector<int> > m1,vector<vector<int> > m2,int a,int b,int e,int f)
{
vector<vector<int> > d(a);
for ( unsigned int i=0;i<f;i++){
d[i].resize(a);
}
for (unsigned int i=0;i<a;i++) {
vector<int> myRow;
myRow.reserve(a);
// myRow.push_back({});
// d.push_back(myRow);
for (unsigned int j=0;j<f;j++) {
int sum=0;
for (unsigned int k=0;k<f;k++) {
sum+=m1[i][k]*m2[k][j];
myRow.push_back(sum);
// d.push_back(myRow);
}
d.push_back(myRow);
}
}
return d;
}
int main()
{
int src[nxsrc][nysrc];
int count;
for (int i=0 ; i<nxsrc ; i++ ){
for( int j=0; j<nysrc ; j++){
src[i][j] = 2;
}
}
vector<vector< int> > src_vec(nxsrc);
for ( int i = 0 ; i < nxsrc ; i++ ){
src_vec[i].resize(nysrc);
}
for (int m = 0; m < nxsrc; m++){
for (int n = 0; n < nysrc; n++){
src_vec[m][n] = src[m][n];
}
}
getch();
cout<<"src matrix"<<endl;
print(src_vec,nxsrc,nysrc); /*initializing src_trans with zeros*/
vector<vector< int> > src_trans(nysrc);
for ( int i = 0 ; i < nysrc ; i++ ){
src_trans[i].resize(nxsrc);
}
cout<<"rows of src"<<src_vec.size()<<endl;
cout<<"cols of src"<<src_vec[0].size()<<endl;
cout<<endl;
getch();
src_trans=transpose(src_vec,nxsrc,nysrc);
cout<<"transpose of src"<<endl;
print(src_trans,nysrc,nxsrc);
cout<<endl;
vector<vector< int> > src_src_trans(nxsrc);
for ( int i = 0 ; i < nxsrc ; i++ ){
src_src_trans[i].resize(nxsrc);
}
print(src_src_trans,nxsrc,nxsrc);
cout<<endl;
getch();
int r_src_trans=src_src_trans.size();
int c_src_trans=src_src_trans[0].size();
src_src_trans = multiply(src_trans,src_vec,nxsrc,nysrc,r_src_trans,c_src_trans);
getch();
cout<<endl<<"product of src & src_trans"<<endl;
print(src_src_trans,nxsrc,nxsrc);
cout<<endl
|