[numerics] improve performance of is_symmetric
@@ -3249,20 +3249,30 @@ double NM_norm_inf(NumericsMatrix* A)
}
int NM_is_symmetric(NumericsMatrix* A)
{
- int n = A->size0;
- int m = A->size1;
- for (int i =0; i < n ; i++)
- {
- for (int j =0 ; j < m ; j++)
+ NumericsMatrix * Atrans = NM_transpose(A);
+ NumericsMatrix * AplusATrans = NM_add(1/2.0, A, -1/2.0, Atrans);
+ double norm_inf = NM_norm_inf(AplusATrans);
+ NM_free(Atrans); free(Atrans);
+ NM_free(AplusATrans); free(AplusATrans);
+
+ if (norm_inf <= DBL_EPSILON*10)
{
- if (fabs(NM_get_value(A,i,j)-NM_get_value(A,j,i)) >= DBL_EPSILON)
- return 0;
- }
- }
return 1;
}
+ /* int n = A->size0; */
+ /* int m = A->size1; */
+ /* for (int i =0; i < n ; i++) */
+ /* { */
+ /* for (int j =0 ; j < m ; j++) */
+ /* { */
+ /* if (fabs(NM_get_value(A,i,j)-NM_get_value(A,j,i)) >= DBL_EPSILON) */
+ /* return 0; */
+ /* } */
+ /* } */
+ return 0;
+}
double NM_symmetry_discrepancy(NumericsMatrix* A)
{
