diff -r 21d1b4fa1b24 -r 062f98d96f40 src/work/alpar/matrix.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/alpar/matrix.cc Mon Nov 15 15:05:00 2004 +0000 @@ -0,0 +1,75 @@ +#include +#include + +template +class Matrix +{ +public: + int m,n; + std::vector values; + + Matrix(int _m, int _n) : m(_m), n(_n), values(n*m) {} + typename std::vector::reference operator()(int i, int j) + { return values[i*n+j];} + + class Row + { + public: + Matrix &mat; + int row; + + Row(Matrix &_mat,int _row) : mat(_mat), row(_row) {} + typename std::vector::reference operator()(int j) + { return mat.values[row*mat.n+j];} + }; + class Column + { + public: + Matrix &mat; + int col; + + Column(Matrix &_mat,int _col) : mat(_mat), col(_col) {} + typename std::vector::reference operator[](int i) + { return mat.values[i*mat.n+col];} + }; + + Row operator[](int i) { return Row(*this,i); } + Column operator()(int j) { return Column(*this,j); } +}; + +main() +{ + const int COUNT=1000000; + const int SIZE=100; + + Matrix A(SIZE,SIZE); + + for(int i=0;i