Matrix vector multiplication CCS c++ -


i trying multiply matrix , vector matrix in compressed column storage. matrix :

0   3   0    4   0   0    2   0   0 

here ccs form:

[ 4 2 3 ] [ 2 3 1 ] [ 1 3 4 4 ] 

the vector is:

[ 1 3 4 ] 

so product should be

[ 9 4 2 ] 

here function trying create

vector<int> multiply(vector<int> val,vector<int> col,vector<int> row,vector<int> v, int r){      vector<int> x(v.size());     (int j=0; j<r; j++) {         (int i=col[j]-1; i<col[j+1]-1; i++) {             cout<<"\n"<<val[i]<<"*"<<v[j]<<"\n";             x[j]+= val[i]*v[j];         }     }     return x; } 

but returns

[ 6 9 0 ] 

this closest i've gotten real solution, how can fix this?

i think driven col_ptr vector.

1.) wasn't sure value(s) r take, removed it, don't need information solve problem 2.) should note have not compiled this, believe algorithm correct 3.) there obvious ways optimize memory usage of code, left variables in explain process. 4.) main problem code posted doesn't seem use row array tell row value in!

vector<int> multiply(vector<int> val,vector<int> col,vector<int> row,vector<int> v) {    vector<int> x(v.size());    //we may need initialize x zeroes, forget    int col_size = col.size();    int column_idx = 0;    (int j=0; j<col_size-1; j++) {       //j indicates columns start going!       //columns end prior next column start       //val_index need start in val array, column       int val_index_start = col[j]-1; //this redunda       //we keep traversing forward until next column starts       int next_column_start = col[j+1]-1;       (int k=val_index_start; k < next_column_start && k < v.size(); k++) {         int row_of_cell = row[k] - 1;         int column_of_cell = column_idx;         int product = v[column_idx]*val[k];         x[row_of_cell] += product;       }       column_idx++;    }    return x; } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -