 # About new sparse matrix structure

I had a c++ code linked with FreeFem version 3, in which I built a matrix using

``````MatriceMorse<double> * ret = new MatriceMorse<double>(np,np,newnnz,false,newa,newlg,newcl);
``````

However, in version 4, I get:

``````error: no matching function for call to ‘HashMatrix<int, double>::HashMatrix(int&, int&, int&,       bool, double*&, int*&, int*&)’
``````

How can I adapt my code to the new sparse matrix structure?

The new matrix have completely change

the new code can be like :

``````MatriceMorse<double> * ret = new MatriceMorse<double>(np);
// build
for (int k=0; k< newnnz; ++k);
{
int i =
int j =
double aij =
(*ret)( i,j) = aijj;
}

sparce_mat->Uh = UniqueffId();
sparce_mat->Vh = UniqueffId();
sparce_mat->A.master(ret);
sparce_mat->typemat = 0;

return sparce_mat;
``````

Sorry @frederichecht but I don’t understand very well what I have to do.
My code was very similar to that you wrote, except that MatriceMorse had to be created using the usual arrays [I,J,A] of sparse matrices. I mean, before I wrote

``````MatriceMorse<double> * ret = new MatriceMorse<double>(np,np,newnnz,false,newa,newlg,newcl);
``````

where A = newa, I=newlg and J=newcl.

And now, I have to write:

``````   MatriceMorse<double> * ret = new MatriceMorse<double>(np);
for (int k=0; k< newnnz; ++k)
(*ret)( newlg[k],newcl[k]) = newa[k];

``````

but it does not work. What I am doing wrong?

No because your previous matrix is a CSR format so your core is wrong

``````   MatriceMorse<double> * mA = new MatriceMorse<double>(np);

``````
``````
``````

mA->j=0;

mA->p=0;

mA->aij=0;

``````mA->set(np,np,0,newnnz,newlg,newcl,newa,1,1);
``````

remarque the army newlg, ewel, new can be freed after.

Thanks @frederichecht, just a little remark,
`mA->set(np,np,0,newnnz,newlg,newcl,newa,1,1);`
gives an error:
`free(): invalid next size (normal)`

I need to put
`mA->set(np,np,0,newnnz,newlg,newcl,newa,0,1);`
and it seems ok.

ok, sorry for the mistake.