questions about sparse multiplication
Created by: shenhuinuist
I verified sparse multiplication according to your codes. I designed my demo which is as follows:
include
include<stdlib.h>
using namespace std; int main() { void colVecAddTo(int* a, int* b, int c, int len, int aWidth, int bWidth); int a[3] = {1, 1, 1};
//b=[0, 1, 0, 2, 0; 1, 0, 0, 0, 0; 0, 0, 0, 2, 5] SPARSE_CSR
int b_value[5] = {1, 2, 1, 2, 5};
int b_col[5] = {1, 3, 0, 3, 4};
int b_row[4] = {0, 2, 3, 5};
int f[5] = {0, 0, 0, 0, 0};
int *A = a;
int *B = b_value;
int *C = f;
int *rows = b_row;
int *cols = b_col;
int m = 3; //a->getWidth()
int width_ = 5; //b->getWidth()
int height_ = 1; //a->getHeight()
for (int j = 0 ;j < 3; ++j ) //3 is b->getHeight()
{
int start = b_row[j]; //start = b->getRowStartIdx(j)
int end = b_row[j + 1]; //end = b->getRowStartIdx(j + 1)
for (int i = start; i < end; ++i)
{
colVecAddTo(C + cols[i], A + j, B[i], height_, width_, 3);
//cout<<*(C + cols[i])<<endl;
}
}
system("pause");
return 0;
}
void colVecAddTo(int* aa, int* bb, int cc, int len, int aWidth, int bWidth) { for ( int ii = 0; ii < len; ++ii) { aa[ii * aWidth] += bb[ii * bWidth] * cc; cout<<aa[ii * aWidth]<<endl; } } The correct result should be 1 1 0 4 5, but the rusult of my demo is 1 2 1 4 5 . Could you help me ?
What's more , could you show me more details or reference materials about sparse multiplication? Thank you very much.