void SparseMatrix::setColumn(unsigned i, const SparseArray& col) { unsigned nnz = col.numNonZeros(); for (unsigned j=0; j<nnz; ++j) { int index = col.readIndex(j); double value = col.readValue(j); _row[index].setValue(i, value); } }
unsigned SparseMatrix::copyCCS(long*& colptr, long*& index, double*& value) const { unsigned N = numNonZeros(); colptr = (long int*) malloc((numColumns() + 1) * sizeof(long int)); index = (long int*) malloc(N * sizeof(long int)); value = (double*) malloc(N * sizeof(double)); colptr[0] = 0; for (unsigned i = 0; i < numColumns(); ++i) { SparseArray col = getColumn(i); int offset = col.numNonZeros(); col.copy( &(index[colptr[i]]), &(value[colptr[i]]) ); colptr[i+1] = colptr[i] + offset; } return N; }