[numerics] copy matrix for preserving original one in NM_inv
@@ -1964,6 +1964,8 @@ void NM_gemm(const double alpha, NumericsMatrix* A, NumericsMatrix* B,
assert(A->matrix1);
assert(B->matrix1);
assert(C->matrix1);
+
+ SBM_alloc_for_gemm(A->matrix1, B->matrix1, C->matrix1);
SBM_gemm(alpha, A->matrix1, B->matrix1, beta, C->matrix1);
NM_clearDense(C);
@@ -2433,10 +2435,12 @@ int NM_inv(NumericsMatrix* A, NumericsMatrix* Ainv)
{
b[i]=0.0;
}
- int info =-1;
- // get internal data (allocation of needed)
- NM_internalData(A);
+
+ NumericsMatrix* Atmp = NM_new();
+ NM_copy(A,Atmp);
+
+ int info =-1;
switch (A->storageType)
{
@@ -2456,28 +2460,26 @@ int NM_inv(NumericsMatrix* A, NumericsMatrix* Ainv)
NM_triplet_alloc(Ainv, A->size0);
Ainv->matrix2->origin = NS_TRIPLET;
-
for( int col_rhs =0; col_rhs < A->size1; col_rhs++ )
{
if (col_rhs >0) b[col_rhs-1] = 0.0;
b[col_rhs] = 1.0;
- info = NM_gesv_expert(A, b, 0);
-
- DEBUG_EXPR(NM_dense_display(b,A->size1,1,1););
+ //info = NM_gesv_expert(Atmp, b, NM_PRESERVE);
+ info = NM_gesv_expert(Atmp, b, NM_KEEP_FACTORS);
for (int i = 0; i < A->size0; ++i)
{
CHECK_RETURN(cs_zentry(Ainv->matrix2->triplet, i, col_rhs, b[i]));
}
}
- NM_display(Ainv);
break;
}
default:
assert (0 && "NM_inv : unknown storageType");
}
-
+ NM_free(Atmp);
+ free(Atmp);
free(b);
DEBUG_END("NM_inv(NumericsMatrix* A, double *b, unsigned keep)\n");
return (int)info;
