#include "csr_sparse_matrix.h" CsrSparseMatrix initCsrSparseMatrix() { CsrSparseMatrix sparseMatrix; sparseMatrix.size = 0; sparseMatrix.numberOfElements = 0; sparseMatrix.values = NULL; sparseMatrix.columnIndexes = NULL; sparseMatrix.rowCumulativeIndexes = NULL; return sparseMatrix; } void allocMemoryForCsr(CsrSparseMatrix *sparseMatrix, int size, int numberOfElements) { sparseMatrix->values = (double *) malloc(numberOfElements * sizeof(double)); sparseMatrix->columnIndexes = (int *) malloc( numberOfElements * sizeof(int)); sparseMatrix->rowCumulativeIndexes = (int *) malloc( (size + 1) * sizeof(int)); for (int i=0; irowCumulativeIndexes[i] = 0; } sparseMatrix->size = size; sparseMatrix->numberOfElements = numberOfElements; } void zeroOutRow(CsrSparseMatrix *sparseMatrix, int row) { // Gets start and end indexes of the row's elements 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; inumberOfElements; ++i){ if(sparseMatrix->columnIndexes[i] == column){ 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