# Resize to bigger dimension removes non-zero coefficients in sparse matrix?

**URL:** <https://community.freefem.org/t/resize-to-bigger-dimension-removes-non-zero-coefficients-in-sparse-matrix/477>\
**Category:** General Discussion\
**Created:** [June 19, 2020, 9:05am UTC](https://community.freefem.org/t/resize-to-bigger-dimension-removes-non-zero-coefficients-in-sparse-matrix/477 "2020-06-19T09:05:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@Colin](https://community.freefem.org/u/Colin)\
**Post date:** [June 19, 2020, 9:05am UTC](https://community.freefem.org/t/resize-to-bigger-dimension-removes-non-zero-coefficients-in-sparse-matrix/477/1 "2020-06-19T09:05:57Z")

</div>

Hello,

I am trying to resize a sparse matrix, but it appears to eliminate non-zeros coefficients? See below code and output. Many thanks for the help!

Regards,

Colin

Code:

int nnz=44330306;  
int[int] I(nnz),J(nnz);  
complex[int] C(nnz);  
{  
ifstream fileI(dir+“Qu\_Chol.txt”);  
for(int i=0; i\<nnz; i++) fileI \>\> I[i] \>\> J[i] \>\> C[i];  
}

matrix QuChol=[I,J,C];

cout \<\< "QuChol.n = " \<\<QuChol.n \<\< endl;  
cout \<\< "QuChol.m = " \<\<QuChol.m \<\< endl;  
cout \<\< "QuChol.nbcoef = " \<\<QuChol.nbcoef \<\< endl;

QuChol.resize(191720,191720);

cout \<\< "QuChol.n = " \<\<QuChol.n \<\< endl;  
cout \<\< "QuChol.m = " \<\<QuChol.m \<\< endl;  
cout \<\< "QuChol.nbcoef = " \<\<QuChol.nbcoef \<\< endl;

Output:

– Raw Matrix nxm =170260x170260 nb none zero coef. 44330306  
QuChol.n = 170260  
QuChol.m = 170260  
QuChol.nbcoef = 44330306  
QuChol.n = 191720  
QuChol.m = 191720  
QuChol.nbcoef = 44150820

---

<div class="post-metadata">

**Author:** ![Colin](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@Colin](https://community.freefem.org/u/Colin)\
**Post date:** [June 19, 2020, 9:39am UTC](https://community.freefem.org/t/resize-to-bigger-dimension-removes-non-zero-coefficients-in-sparse-matrix/477/2 "2020-06-19T09:39:09Z")

</div>

OK, it seems it is implicitly calling the threshold function.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [June 19, 2020, 2:33pm UTC](https://community.freefem.org/t/resize-to-bigger-dimension-removes-non-zero-coefficients-in-sparse-matrix/477/3 "2020-06-19T14:33:01Z")

</div>

No,

```
mesh Th=square(10,10);
varf vM(u,v)= int2d(Th,qft=qf1pTlump)(u*v);
fespace Vh(Th,P1);
matrix A=vM(Vh,Vh);
cout << A.n << " nzz "<< A.nnz << endl;
A.resize(1000,1000);
cout << A.n << " nzz "<< A.nnz << endl;

```

the output is:

```
121 nzz 761

1000 nzz 761

```

I thing your version is very old …  
Frederic Hecht.
