Fix matrixRead routine
This commit is contained in:
parent
d267a6d550
commit
3428d84c3d
20
src/matrix.c
20
src/matrix.c
@ -29,6 +29,13 @@ static inline int compareRow(const void* a, const void* b)
|
||||
return (a_->row > b_->row) - (a_->row < b_->row);
|
||||
}
|
||||
|
||||
static void dumpMMMatrix(Entry* mm, int nz)
|
||||
{
|
||||
for (int i = 0; i < nz; i++) {
|
||||
printf("%d %d: %f\n", mm[i].row, mm[i].col, mm[i].val);
|
||||
}
|
||||
}
|
||||
|
||||
void matrixRead(Matrix* m, char* filename)
|
||||
{
|
||||
MM_typecode matcode;
|
||||
@ -80,7 +87,7 @@ void matrixRead(Matrix* m, char* filename)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Read matrix %s with %d non zeroes and %d rows", filename, nz, M);
|
||||
printf("Read matrix %s with %d non zeroes and %d rows\n", filename, nz, M);
|
||||
|
||||
m->nr = M;
|
||||
m->nnz = nz;
|
||||
@ -126,8 +133,10 @@ void matrixRead(Matrix* m, char* filename)
|
||||
|
||||
// sort by column
|
||||
qsort(mm, mms, sizeof(Entry), compareColumn);
|
||||
// dumpMMMatrix(mm, nz);
|
||||
// sort by row
|
||||
qsort(mm, mms, sizeof(Entry), compareRow);
|
||||
mergesort(mm, mms, sizeof(Entry), compareRow);
|
||||
// dumpMMMatrix(mm, nz);
|
||||
|
||||
m->rowPtr = (CG_UINT*)allocate(64, (m->nr + 1) * sizeof(CG_UINT));
|
||||
m->colInd = (CG_UINT*)allocate(64, m->nnz * sizeof(CG_UINT));
|
||||
@ -143,7 +152,6 @@ void matrixRead(Matrix* m, char* filename)
|
||||
valsPerRow[mm[i].row]++;
|
||||
}
|
||||
|
||||
int* offsets = (int*)allocate(64, (m->nr + 1) * sizeof(int));
|
||||
m->rowPtr[0] = 0;
|
||||
|
||||
// convert to CRS format
|
||||
@ -153,8 +161,8 @@ void matrixRead(Matrix* m, char* filename)
|
||||
|
||||
// loop over all elements in Row
|
||||
for (int id = m->rowPtr[rowID]; id < m->rowPtr[rowID + 1]; id++) {
|
||||
m->val[id] = (CG_UINT)mm[id].val;
|
||||
m->colInd[id] = (CG_FLOAT)mm[id].col;
|
||||
m->val[id] = (CG_FLOAT)mm[id].val;
|
||||
m->colInd[id] = (CG_UINT)mm[id].col;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -166,7 +174,7 @@ void matrixDump(Matrix* m)
|
||||
CG_UINT* colInd = m->colInd;
|
||||
CG_FLOAT* val = m->val;
|
||||
|
||||
printf("Matrix: %lld non zeroes, number of rows %lld\n", numRows, m->nnz);
|
||||
printf("Matrix: %lld non zeroes, number of rows %lld\n", m->nnz, numRows);
|
||||
|
||||
for (int rowID = 0; rowID < numRows; rowID++) {
|
||||
printf("Row [%d]: ", rowID);
|
||||
|
Loading…
Reference in New Issue
Block a user