With an example, Explain the procedure of transposing a sparse matrix?
Answers
Answer:
hrkk3mdmdoenenrndkdke
djsnnemsmsmenxsnw
Explanation:
ebsuznwns
Answer:
Algorithm for the Transpose of a Sparse-Matrix:
This is the algorithm that converts a compressed-column sparse matrix into a compressed-row sparse matrix. It computes number of rows in A, compares the cummulative sum to generate row pointers and then iterates over each nonzero entry in A, storing the entry in its corresponding row vector. If the matrix resulted in this procedure is a sparce matrix C and can be interpreted as a matrix in compressed-row form then, C is equal to A. If C is a compressed-column matrix, then C contains Transpose of A.
The code is
cs *cs_transpose(const cs *A, int values)
{
int p,q,j,*cp,*ci,n,m,*Ap,*Ai,*W;
cs *C;
double *Cx,*Ax;
if(!CS_CSC(A))
return(NULL);
m=A->m;
n=A->n;
Ap=A->p;
Ai=A->i;
Ax=A->x;
C=cs_spalloc(n,m,Ap[n],values && Ax,0);
W=cs_calloc(m,sizeof(int));
if(!C||!W)
return(cs_done(C,W,NULL,0));
Cp=C->p;
Ci=C->i;
Cx=C->x;
for(p=0;pW[Ai[p]]++;
cs_cumsum(Cp,W,m);
for(j=0;j{
for(p=Ap[j];p{
Ci[q=W[Ai[p]]++]=j;
if(Cx)
Cx[q]=Ax=[p];
}
}
return(cs_done(C,W,NULL,1));
}