星期六, 7月 28, 2007

方向

我得說我沒有方向感,程式寫錯的問題是....我又把xy搞錯了...Orz,用手寫板畫了好幾張圖,終於搞懂方向,我不要再搞錯了...Orz

Matrix Multiplication Native Algorithm - divide and conquer

  • Application Function
    void mulitplication(vector<vector<int> >& r, vector<vector<int> >& u,
    vector<vector<int> >& v){
    mult(make_pair(0,0), make_pair(0,0), make_pair(0,0), r.size(),
    r, u, v);
    }
  • Recursive Function
    void mult(pair<int,int> lr, pair<int,int> lu, pair<int,int> lv,
    int size, vector<vector<int> >& r,
    vector<vector<int> >& u, vector<vector<int> >& v){

    static const int addr[8][2] = {{0,0}, {0,0}, {0,1}, {0,1},
    {1,0}, {1,0}, {1,1}, {1,1}};
    static const int addu[8][2] = {{0,0}, {0,1}, {0,0}, {0,1},
    {1,0}, {1,1}, {1,0}, {1,1}};
    static const int addv[8][2] = {{0,0}, {1,0}, {0,1}, {1,1},
    {0,0}, {1,0}, {0,1}, {1,1}};

    if(size>2){
    for(unsigned int i=0;i<8;i++){
    mult(make_pair(lr.first+((size >> 1)*addr[i][0]),
    lr.second+((size >> 1)*addr[i][1])),
    make_pair(lu.first+((size >> 1)*addu[i][0]),
    lu.second+((size >> 1)*addu[i][1])),
    make_pair(lv.first+((size >> 1)*addv[i][0]),
    lv.second+((size >> 1)*addv[i][1])),
    size/2,
    r,
    u,
    v);
    }
    }
    else{
    for(unsigned int i=0;i<8;i++){
    r[lr.first + addr[i][0]][lr.second + addr[i][1]] +=
    u[lu.first + addu[i][0]][lu.second + addu[i][1]] *
    v[lv.first + addv[i][0]][lv.second + addv[i][1]];
    }
    }
    }


---
因為方向搞錯而debug...Orz

沒有留言: