#include "csr_sparse_matrix.h" CsrSparseMatrix initCsrSparseMatrix() { CsrSparseMatrix sparseMatrix; sparseMatrix.size = 0; sparseMatrix.numberOfNonZeroElements = 0; sparseMatrix.values = NULL; sparseMatrix.columnIndexes = NULL; sparseMatrix.rowCumulativeIndexes = NULL; return sparseMatrix; } void allocMemoryForCsr(CsrSparseMatrix *sparseMatrix, int numberOfElements) { sparseMatrix->values = (double *) malloc(numberOfElements * sizeof(double)); sparseMatrix->columnIndexes = (int *) malloc( numberOfElements * sizeof(int)); sparseMatrix->rowCumulativeIndexes = (int *) malloc( (numberOfElements + 1) * sizeof(int)); for (int i=0; irowCumulativeIndexes[i] = 0; } sparseMatrix->size = numberOfElements; } // Row indexes start from 0! void zeroOutRow(CsrSparseMatrix *sparseMatrix, int row) { int startIndex = sparseMatrix->rowCumulativeIndexes[row], endIndex = sparseMatrix->rowCumulativeIndexes[row+1]; for (int i=startIndex; ivalues[i] = 0; } } void zeroOutColumn(CsrSparseMatrix *sparseMatrix, int column) { for (int i=0; inumberOfNonZeroElements; ++i){ if(sparseMatrix->columnIndexes[i] == column){ // Zeros out this element sparseMatrix->values[i] = 0; } } } void csrSparseMatrixVectorMultiplication(CsrSparseMatrix sparseMatrix, double *vector, double **product, int vectorSize) { // Initializes the elements of the product vector to zero for (int i=0; ivalues); free(sparseMatrix->rowCumulativeIndexes); free(sparseMatrix->columnIndexes); } void printCsrSparseMatrix(CsrSparseMatrix sparseMatrix) { if (sparseMatrix.size == 0) { return; } for (int i=0; i