R
Ray D.
I'm trying to write a C function to compute the compressed row storage
(CRS) vectors of a 2-d matrix. This is used primarily for increasing
computing efficiency of matrices whose main elements are zeros. So
for example, if you were given the following matrix:
A = { 0, 0, 1, 0;
0, 3, 0, 0;
6, 0, 4, 0}
the function would compute three vectors - the non-zero element
vector, the column index vector for each element, and the row pointer
vector. For this example, the element vector would be {1, 3, 6, 4},
the column index vector would be {2, 1, 0, 2}, and the row pointer
vector would be {0, 1, 2, 5}.
Now what I want to do is generate these arrays from matrix A, so
clearly I don't know the array size until I begin to go through each
row of the matrix to see which elements are non-zero. Because of
this, how would I go about allocating the array size at run-time? I'm
assuming you can use the malloc() function, but I'm new to this so any
help would be appreciated. Thanks!
(CRS) vectors of a 2-d matrix. This is used primarily for increasing
computing efficiency of matrices whose main elements are zeros. So
for example, if you were given the following matrix:
A = { 0, 0, 1, 0;
0, 3, 0, 0;
6, 0, 4, 0}
the function would compute three vectors - the non-zero element
vector, the column index vector for each element, and the row pointer
vector. For this example, the element vector would be {1, 3, 6, 4},
the column index vector would be {2, 1, 0, 2}, and the row pointer
vector would be {0, 1, 2, 5}.
Now what I want to do is generate these arrays from matrix A, so
clearly I don't know the array size until I begin to go through each
row of the matrix to see which elements are non-zero. Because of
this, how would I go about allocating the array size at run-time? I'm
assuming you can use the malloc() function, but I'm new to this so any
help would be appreciated. Thanks!