#include #include #include /* Defines the maximum number of non-zero entries per row */ # define MAXNONZERO 16; /* Structure Defs A sparse row contains the row length n #non-zero entries p max #non-zero entries PMax column array pointer cols value array pointer vals A sparse matrix contains number of rows m number of columns n row pointers row */ struct row_sp {int n; int p; int pMax; int * cols; float * vals;}; struct mat_sp {int m; int n; struct row_sp ** row;}; /* Prototypes: Intialization and clean up */ struct mat_sp InitializeSparseMat(int m, int n); struct row_sp * InitializeSparseRow(int n, int pMax); void FreeSparseRow(struct row_sp * row); void FreeSparseMat(struct mat_sp A); /* Prototypes: Input and output */ struct mat_sp ReadSparseMat( char FileName[]); void WriteSparseMat(char FileName[], struct mat_sp); void AppendToSparseRow(struct row_sp * row, int j, float z); /* Prototypes: Structure */ struct mat_sp TransposeSparseMat(struct mat_sp A); /* Prototypes: Matrix Arithmetic */ float MultiplySparseRows(struct row_sp * row1, struct row_sp * row2); float * MultiplySparseMats(struct mat_sp, struct mat_sp);