28 static size_t size_of_matrix_type(
int type){
35 size = 2*
sizeof(
real);
72 int *ia = A->
ia, *ja = A->
ja, *ib, *jb, nz = A->
nz, m = A->
m, n = A->
n, type = A->
type, format = A->
format;
83 for (i = 0; i <= n; i++) ib[i] = 0;
84 for (i = 0; i < m; i++){
85 for (j = ia[i]; j < ia[i+1]; j++){
90 for (i = 0; i < n; i++) ib[i+1] += ib[i];
96 for (i = 0; i < m; i++){
97 for (j = ia[i]; j < ia[i+1]; j++){
99 b[ib[ja[j]]++] = a[j];
107 for (i = 0; i < m; i++){
108 for (j = ia[i]; j < ia[i+1]; j++){
110 b[2*ib[ja[j]]] = a[2*j];
111 b[2*ib[ja[j]]+1] = a[2*j+1];
118 int *ai = (
int*) A->
a;
119 int *bi = (
int*) B->
a;
120 for (i = 0; i < m; i++){
121 for (j = ia[i]; j < ia[i+1]; j++){
123 bi[ib[ja[j]]++] = ai[j];
129 for (i = 0; i < m; i++){
130 for (j = ia[i]; j < ia[i+1]; j++){
144 for (i = n-1; i >= 0; i--) ib[i+1] = ib[i];
179 if (!A)
return FALSE;
183 int *ia, *ja, *ib, *jb, type, m;
192 if (A->
m != A->
n)
return FALSE;
195 if (!B)
return FALSE;
203 mask =
MALLOC(
sizeof(
int)*((
size_t) m));
204 for (i = 0; i < m; i++) mask[i] = -1;
213 for (i = 0; i <= m; i++)
if (ia[i] != ib[i])
goto RETURN;
214 for (i = 0; i < m; i++){
215 for (j = ia[i]; j < ia[i+1]; j++){
218 for (j = ib[i]; j < ib[i+1]; j++){
219 if (mask[jb[j]] < ia[i])
goto RETURN;
221 for (j = ib[i]; j < ib[i+1]; j++){
231 for (i = 0; i <= m; i++)
if (ia[i] != ib[i])
goto RETURN;
232 for (i = 0; i < m; i++){
233 for (j = ia[i]; j < ia[i+1]; j++){
236 for (j = ib[i]; j < ib[i+1]; j++){
237 if (mask[jb[j]] < ia[i])
goto RETURN;
239 for (j = ib[i]; j < ib[i+1]; j++){
248 int *ai = (
int*) A->
a;
249 int *bi = (
int*) B->
a;
250 for (i = 0; i < m; i++){
251 for (j = ia[i]; j < ia[i+1]; j++){
254 for (j = ib[i]; j < ib[i+1]; j++){
255 if (mask[jb[j]] < ia[i])
goto RETURN;
257 for (j = ib[i]; j < ib[i+1]; j++){
258 if (bi[j] != ai[mask[jb[j]]])
goto RETURN;
265 for (i = 0; i < m; i++){
266 for (j = ia[i]; j < ia[i+1]; j++){
269 for (j = ib[i]; j < ib[i+1]; j++){
270 if (mask[jb[j]] < ia[i])
goto RETURN;
283 if (test_pattern_symmetry_only){
296 static SparseMatrix SparseMatrix_init(
int m,
int n,
int type,
size_t sz,
int format){
314 A->
ia =
MALLOC(
sizeof(
int)*((
size_t)(m+1)));
329 size_t nz_t = (size_t) nz;
342 if (A->
size > 0 && nz_t > 0) {
353 size_t nz_t = (size_t) nz;
390 sz = size_of_matrix_type(type);
391 A = SparseMatrix_init(m, n, type, sz, format);
393 if (nz > 0) A = SparseMatrix_alloc(A, nz);
404 A = SparseMatrix_init(m, n, type, sz, format);
406 if (nz > 0) A = SparseMatrix_alloc(A, nz);
427 printf(
"%s\n SparseArray[{",c);
434 for (i = 0; i < m; i++){
435 for (j = ia[i]; j < ia[i+1]; j++){
436 printf(
"{%d, %d}->%f",i+1, ja[j]+1, a[j]);
437 if (j != ia[m]-1) printf(
",");
443 for (i = 0; i < m; i++){
444 for (j = ia[i]; j < ia[i+1]; j++){
445 printf(
"{%d, %d}->%f + %f I",i+1, ja[j]+1, a[2*j], a[2*j+1]);
446 if (j != ia[m]-1) printf(
",");
453 for (i = 0; i < m; i++){
454 for (j = ia[i]; j < ia[i+1]; j++){
455 printf(
"{%d, %d}->%d",i+1, ja[j]+1, ai[j]);
456 if (j != ia[m]-1) printf(
",");
462 for (i = 0; i < m; i++){
463 for (j = ia[i]; j < ia[i+1]; j++){
464 printf(
"{%d, %d}->_",i+1, ja[j]+1);
465 if (j != ia[m]-1) printf(
",");
475 printf(
"},{%d, %d}]\n", m, A->
n);
488 printf(
"%s\n SparseArray[{",c);
495 for (i = 0; i < A->
nz; i++){
496 printf(
"{%d, %d}->%f",ia[i]+1, ja[i]+1, a[i]);
497 if (i != A->
nz - 1) printf(
",");
503 for (i = 0; i < A->
nz; i++){
504 printf(
"{%d, %d}->%f + %f I",ia[i]+1, ja[i]+1, a[2*i], a[2*i+1]);
505 if (i != A->
nz - 1) printf(
",");
511 for (i = 0; i < A->
nz; i++){
512 printf(
"{%d, %d}->%d",ia[i]+1, ja[i]+1, ai[i]);
513 if (i != A->
nz) printf(
",");
518 for (i = 0; i < A->
nz; i++){
519 printf(
"{%d, %d}->_",ia[i]+1, ja[i]+1);
520 if (i != A->
nz - 1) printf(
",");
529 printf(
"},{%d, %d}]\n", m, A->
n);
557 static void SparseMatrix_export_csr(FILE *f,
SparseMatrix A){
565 fprintf(f,
"%%%%MatrixMarket matrix coordinate real general\n");
568 fprintf(f,
"%%%%MatrixMarket matrix coordinate complex general\n");
571 fprintf(f,
"%%%%MatrixMarket matrix coordinate integer general\n");
574 fprintf(f,
"%%%%MatrixMarket matrix coordinate pattern general\n");
582 fprintf(f,
"%d %d %d\n",A->
m,A->
n,A->
nz);
589 for (i = 0; i < m; i++){
590 for (j = ia[i]; j < ia[i+1]; j++){
591 fprintf(f,
"%d %d %16.8g\n",i+1, ja[j]+1, a[j]);
597 for (i = 0; i < m; i++){
598 for (j = ia[i]; j < ia[i+1]; j++){
599 fprintf(f,
"%d %d %16.8g %16.8g\n",i+1, ja[j]+1, a[2*j], a[2*j+1]);
605 for (i = 0; i < m; i++){
606 for (j = ia[i]; j < ia[i+1]; j++){
607 fprintf(f,
"%d %d %d\n",i+1, ja[j]+1, ai[j]);
612 for (i = 0; i < m; i++){
613 for (j = ia[i]; j < ia[i+1]; j++){
614 fprintf(f,
"%d %d\n",i+1, ja[j]+1);
628 fwrite(&(A->
m),
sizeof(
int), 1, f);
629 fwrite(&(A->
n),
sizeof(
int), 1, f);
630 fwrite(&(A->
nz),
sizeof(
int), 1, f);
631 fwrite(&(A->
nzmax),
sizeof(
int), 1, f);
632 fwrite(&(A->
type),
sizeof(
int), 1, f);
633 fwrite(&(A->
format),
sizeof(
int), 1, f);
634 fwrite(&(A->
property),
sizeof(
int), 1, f);
635 fwrite(&(A->
size),
sizeof(
size_t), 1, f);
637 fwrite(A->
ia,
sizeof(
int), A->
nz, f);
639 fwrite(A->
ia,
sizeof(
int), A->
m + 1, f);
641 fwrite(A->
ja,
sizeof(
int), A->
nz, f);
650 f = fopen(name,
"wb");
664 int m, n, nz, nzmax, type, format, property, iread;
667 iread = fread(&m,
sizeof(
int), 1, f);
668 if (iread != 1)
return NULL;
669 iread = fread(&n,
sizeof(
int), 1, f);
670 if (iread != 1)
return NULL;
671 iread = fread(&nz,
sizeof(
int), 1, f);
672 if (iread != 1)
return NULL;
673 iread = fread(&nzmax,
sizeof(
int), 1, f);
674 if (iread != 1)
return NULL;
675 iread = fread(&type,
sizeof(
int), 1, f);
676 if (iread != 1)
return NULL;
677 iread = fread(&format,
sizeof(
int), 1, f);
678 if (iread != 1)
return NULL;
679 iread = fread(&property,
sizeof(
int), 1, f);
680 if (iread != 1)
return NULL;
681 iread = fread(&sz,
sizeof(
size_t), 1, f);
682 if (iread != 1)
return NULL;
689 iread = fread(A->
ia,
sizeof(
int), A->
nz, f);
690 if (iread != A->
nz)
return NULL;
692 iread = fread(A->
ia,
sizeof(
int), A->
m + 1, f);
693 if (iread != A->
m + 1)
return NULL;
695 iread = fread(A->
ja,
sizeof(
int), A->
nz, f);
696 if (iread != A->
nz)
return NULL;
699 iread = fread(A->
a, A->
size, A->
nz, f);
700 if (iread != A->
nz)
return NULL;
710 f = fopen(name,
"rb");
716 static void SparseMatrix_export_coord(FILE *f,
SparseMatrix A){
724 fprintf(f,
"%%%%MatrixMarket matrix coordinate real general\n");
727 fprintf(f,
"%%%%MatrixMarket matrix coordinate complex general\n");
730 fprintf(f,
"%%%%MatrixMarket matrix coordinate integer general\n");
733 fprintf(f,
"%%%%MatrixMarket matrix coordinate pattern general\n");
741 fprintf(f,
"%d %d %d\n",A->
m,A->
n,A->
nz);
748 for (i = 0; i < A->
nz; i++){
749 fprintf(f,
"%d %d %16.8g\n",ia[i]+1, ja[i]+1, a[i]);
754 for (i = 0; i < A->
nz; i++){
755 fprintf(f,
"%d %d %16.8g %16.8g\n",ia[i]+1, ja[i]+1, a[2*i], a[2*i+1]);
760 for (i = 0; i < A->
nz; i++){
761 fprintf(f,
"%d %d %d\n",ia[i]+1, ja[i]+1, ai[i]);
765 for (i = 0; i < A->
nz; i++){
766 fprintf(f,
"%d %d\n",ia[i]+1, ja[i]+1);
782 SparseMatrix_export_csr(f, A);
789 SparseMatrix_export_coord(f, A);
828 static SparseMatrix SparseMatrix_from_coordinate_arrays_internal(
int nz,
int m,
int n,
int *irn,
int *jcn,
void *val0,
int type,
size_t sz,
int sum_repeated){
843 assert(m > 0 && n > 0 && nz >= 0);
845 if (m <=0 || n <= 0 || nz < 0)
return NULL;
852 for (i = 0; i <= m; i++){
860 for (i = 0; i < nz; i++){
861 if (irn[i] < 0 || irn[i] >= m || jcn[i] < 0 || jcn[i] >= n) {
867 for (i = 0; i < m; i++) ia[i+1] += ia[i];
868 for (i = 0; i < nz; i++){
869 a[ia[irn[i]]] = val[i];
870 ja[ia[irn[i]]++] = jcn[i];
872 for (i = m; i > 0; i--) ia[i] = ia[i - 1];
878 for (i = 0; i < nz; i++){
879 if (irn[i] < 0 || irn[i] >= m || jcn[i] < 0 || jcn[i] >= n) {
885 for (i = 0; i < m; i++) ia[i+1] += ia[i];
886 for (i = 0; i < nz; i++){
887 a[2*ia[irn[i]]] = *(val++);
888 a[2*ia[irn[i]]+1] = *(val++);
889 ja[ia[irn[i]]++] = jcn[i];
891 for (i = m; i > 0; i--) ia[i] = ia[i - 1];
897 for (i = 0; i < nz; i++){
898 if (irn[i] < 0 || irn[i] >= m || jcn[i] < 0 || jcn[i] >= n) {
904 for (i = 0; i < m; i++) ia[i+1] += ia[i];
905 for (i = 0; i < nz; i++){
906 ai[ia[irn[i]]] = vali[i];
907 ja[ia[irn[i]]++] = jcn[i];
909 for (i = m; i > 0; i--) ia[i] = ia[i - 1];
913 for (i = 0; i < nz; i++){
914 if (irn[i] < 0 || irn[i] >= m || jcn[i] < 0 || jcn[i] >= n) {
920 for (i = 0; i < m; i++) ia[i+1] += ia[i];
921 for (i = 0; i < nz; i++){
922 ja[ia[irn[i]]++] = jcn[i];
924 for (i = m; i > 0; i--) ia[i] = ia[i - 1];
928 for (i = 0; i < nz; i++){
929 if (irn[i] < 0 || irn[i] >= m || jcn[i] < 0 || jcn[i] >= n) {
935 for (i = 0; i < m; i++) ia[i+1] += ia[i];
937 for (i = 0; i < nz; i++){
938 ja[ia[irn[i]]++] = jcn[i];
940 for (i = m; i > 0; i--) ia[i] = ia[i - 1];
958 return SparseMatrix_from_coordinate_arrays_internal(nz, m, n, irn, jcn, val0, type, sz,
SUM_REPEATED_ALL);
963 return SparseMatrix_from_coordinate_arrays_internal(nz, m, n, irn, jcn, val0, type, sz, what_to_sum);
970 int *ia = A->
ia, *ja = A->
ja, *ib = B->
ia, *jb = B->
ja, *ic, *jc;
978 if (m != B->
m || n != B->
n)
return NULL;
980 nzmax = A->
nz + B->
nz;
987 mask =
MALLOC(
sizeof(
int)*((
size_t) n));
989 for (i = 0; i < n; i++) mask[i] = -1;
998 for (i = 0; i < m; i++){
999 for (j = ia[i]; j < ia[i+1]; j++){
1005 for (j = ib[i]; j < ib[i+1]; j++){
1006 if (mask[jb[j]] < ic[i]){
1010 c[mask[jb[j]]] += b[j];
1021 for (i = 0; i < m; i++){
1022 for (j = ia[i]; j < ia[i+1]; j++){
1026 c[2*nz+1] = a[2*j+1];
1029 for (j = ib[i]; j < ib[i+1]; j++){
1030 if (mask[jb[j]] < ic[i]){
1033 c[2*nz+1] = b[2*j+1];
1036 c[2*mask[jb[j]]] += b[2*j];
1037 c[2*mask[jb[j]]+1] += b[2*j+1];
1045 int *a = (
int*) A->
a;
1046 int *b = (
int*) B->
a;
1047 int *c = (
int*) C->
a;
1048 for (i = 0; i < m; i++){
1049 for (j = ia[i]; j < ia[i+1]; j++){
1055 for (j = ib[i]; j < ib[i+1]; j++){
1056 if (mask[jb[j]] < ic[i]){
1061 c[mask[jb[j]]] += b[j];
1069 for (i = 0; i < m; i++){
1070 for (j = ia[i]; j < ia[i+1]; j++){
1075 for (j = ib[i]; j < ib[i+1]; j++){
1076 if (mask[jb[j]] < ic[i]){
1093 if (mask)
FREE(mask);
1100 static void dense_transpose(
real *v,
int m,
int n){
1104 u =
MALLOC(
sizeof(
real)*((
size_t) m)*((
size_t) n));
1105 MEMCPY(u,v,
sizeof(
real)*((
size_t) m)*((
size_t) n));
1107 for (i = 0; i < m; i++){
1108 for (j = 0; j < n; j++){
1109 v[j*m+i] = u[i*n+j];
1116 static void SparseMatrix_multiply_dense1(
SparseMatrix A,
real *v,
real **res,
int dim,
int transposed,
int res_transposed){
1118 int i, j, k, *ia, *ja, n, m;
1132 if (!u) u =
MALLOC(
sizeof(
real)*((
size_t) m)*((
size_t) dim));
1133 for (i = 0; i < m; i++){
1134 for (k = 0; k < dim; k++) u[i*dim+k] = 0.;
1135 for (j = ia[i]; j < ia[i+1]; j++){
1136 for (k = 0; k < dim; k++) u[i*dim+k] += a[j]*v[ja[j]*dim+k];
1139 if (res_transposed) dense_transpose(u, m, dim);
1141 if (!u) u =
MALLOC(
sizeof(
real)*((
size_t) n)*((
size_t) dim));
1142 for (i = 0; i < n*dim; i++) u[i] = 0.;
1143 for (i = 0; i < m; i++){
1144 for (j = ia[i]; j < ia[i+1]; j++){
1145 for (k = 0; k < dim; k++) u[ja[j]*dim + k] += a[j]*v[i*dim + k];
1148 if (res_transposed) dense_transpose(u, n, dim);
1156 static void SparseMatrix_multiply_dense2(
SparseMatrix A,
real *v,
real **res,
int dim,
int transposed,
int res_transposed){
1170 if (!u) u =
MALLOC(
sizeof(
real)*((
size_t)m)*((
size_t) dim));
1171 for (i = 0; i < dim; i++){
1175 if (!res_transposed) dense_transpose(u, dim, m);
1177 if (!u) u =
MALLOC(
sizeof(
real)*((
size_t)n)*((
size_t)dim));
1178 for (i = 0; i < dim; i++){
1182 if (!res_transposed) dense_transpose(u, dim, n);
1208 SparseMatrix_multiply_dense1(A, v, res, dim, ATransposed, res_transposed);
1210 SparseMatrix_multiply_dense2(A, v, res, dim, ATransposed, res_transposed);
1219 int i, j, *ia, *ja, n, m;
1236 if (!u) u =
MALLOC(
sizeof(
real)*((
size_t)m));
1237 for (i = 0; i < m; i++){
1239 for (j = ia[i]; j < ia[i+1]; j++){
1240 u[i] += a[j]*v[ja[j]];
1244 if (!u) u =
MALLOC(
sizeof(
real)*((
size_t)n));
1245 for (i = 0; i < n; i++) u[i] = 0.;
1246 for (i = 0; i < m; i++){
1247 for (j = ia[i]; j < ia[i+1]; j++){
1248 u[ja[j]] += a[j]*v[i];
1255 if (!u) u =
MALLOC(
sizeof(
real)*((
size_t)m));
1256 for (i = 0; i < m; i++){
1258 for (j = ia[i]; j < ia[i+1]; j++){
1263 if (!u) u =
MALLOC(
sizeof(
real)*((
size_t)n));
1264 for (i = 0; i < n; i++) u[i] = 0.;
1265 for (i = 0; i < m; i++){
1266 for (j = ia[i]; j < ia[i+1]; j++){
1277 if (!u) u =
MALLOC(
sizeof(
real)*((
size_t)m));
1278 for (i = 0; i < m; i++){
1280 for (j = ia[i]; j < ia[i+1]; j++){
1281 u[i] += ai[j]*v[ja[j]];
1285 if (!u) u =
MALLOC(
sizeof(
real)*((
size_t)n));
1286 for (i = 0; i < n; i++) u[i] = 0.;
1287 for (i = 0; i < m; i++){
1288 for (j = ia[i]; j < ia[i+1]; j++){
1289 u[ja[j]] += ai[j]*v[i];
1296 if (!u) u =
MALLOC(
sizeof(
real)*((
size_t)m));
1297 for (i = 0; i < m; i++){
1299 for (j = ia[i]; j < ia[i+1]; j++){
1304 if (!u) u =
MALLOC(
sizeof(
real)*((
size_t)n));
1305 for (i = 0; i < n; i++) u[i] = 0.;
1306 for (i = 0; i < m; i++){
1307 for (j = ia[i]; j < ia[i+1]; j++){
1326 int i, j, *ia, *ja, m;
1338 for (i = 0; i < m; i++){
1339 for (j = ia[i]; j < ia[i+1]; j++){
1344 for (i = 0; i < m; i++){
1346 for (j = ia[i]; j < ia[i+1]; j++){
1366 for (i = 0; i < A->
nz; i++) b[i] = ai[i];
1374 for (i = 0; i < m; i++){
1375 for (j = ia[i]; j < ia[i+1]; j++){
1384 for (i = 0; i < m; i++){
1385 for (j = ia[i]; j < ia[i+1]; j++){
1393 fprintf(stderr,
"warning: scaling of matrix this type is not supported\n");
1405 int *ia = A->
ia, *ja = A->
ja, *ib = B->
ia, *jb = B->
ja, *ic, *jc;
1406 int i, j, k, jj, type, nz;
1411 if (A->
n != B->
m)
return NULL;
1414 printf(
"in SparseMatrix_multiply, the matrix types do not match, right now only multiplication of matrices of the same type is supported\n");
1420 mask =
MALLOC(
sizeof(
int)*((
size_t)(B->
n)));
1421 if (!mask)
return NULL;
1423 for (i = 0; i < B->
n; i++) mask[i] = -1;
1426 for (i = 0; i < m; i++){
1427 for (j = ia[i]; j < ia[i+1]; j++){
1429 for (k = ib[jj]; k < ib[jj+1]; k++){
1430 if (mask[jb[k]] != -i - 2){
1433 fprintf(stderr,
"overflow in SparseMatrix_multiply !!!\n");
1438 mask[jb[k]] = -i - 2;
1445 if (!C)
goto RETURN;
1458 for (i = 0; i < m; i++){
1459 for (j = ia[i]; j < ia[i+1]; j++){
1461 for (k = ib[jj]; k < ib[jj+1]; k++){
1462 if (mask[jb[k]] < ic[i]){
1468 assert(jc[mask[jb[k]]] == jb[k]);
1469 c[mask[jb[k]]] += a[j]*b[k];
1486 for (i = 0; i < m; i++){
1487 for (j = ia[i]; j < ia[i+1]; j++){
1489 for (k = ib[jj]; k < ib[jj+1]; k++){
1490 if (mask[jb[k]] < ic[i]){
1493 c[2*nz] = a[2*j]*b[2*k] - a[2*j+1]*b[2*k+1];
1494 c[2*nz+1] = a[2*j]*b[2*k+1] + a[2*j+1]*b[2*k];
1497 assert(jc[mask[jb[k]]] == jb[k]);
1498 c[2*mask[jb[k]]] += a[2*j]*b[2*k] - a[2*j+1]*b[2*k+1];
1499 c[2*mask[jb[k]]+1] += a[2*j]*b[2*k+1] + a[2*j+1]*b[2*k];
1509 int *a = (
int*) A->
a;
1510 int *b = (
int*) B->
a;
1511 int *c = (
int*) C->
a;
1513 for (i = 0; i < m; i++){
1514 for (j = ia[i]; j < ia[i+1]; j++){
1516 for (k = ib[jj]; k < ib[jj+1]; k++){
1517 if (mask[jb[k]] < ic[i]){
1523 assert(jc[mask[jb[k]]] == jb[k]);
1524 c[mask[jb[k]]] += a[j]*b[k];
1534 for (i = 0; i < m; i++){
1535 for (j = ia[i]; j < ia[i+1]; j++){
1537 for (k = ib[jj]; k < ib[jj+1]; k++){
1538 if (mask[jb[k]] < ic[i]){
1543 assert(jc[mask[jb[k]]] == jb[k]);
1553 C =
NULL;
goto RETURN;
1571 int *ia = A->
ia, *ja = A->
ja, *ib = B->
ia, *jb = B->
ja, *ic = C->
ia, *jc = C->
ja, *id, *jd;
1572 int i, j, k, l, ll, jj, type, nz;
1577 if (A->
n != B->
m)
return NULL;
1578 if (B->
n != C->
m)
return NULL;
1582 printf(
"in SparseMatrix_multiply, the matrix types do not match, right now only multiplication of matrices of the same type is supported\n");
1588 mask =
MALLOC(
sizeof(
int)*((
size_t)(C->
n)));
1589 if (!mask)
return NULL;
1591 for (i = 0; i < C->
n; i++) mask[i] = -1;
1594 for (i = 0; i < m; i++){
1595 for (j = ia[i]; j < ia[i+1]; j++){
1597 for (l = ib[jj]; l < ib[jj+1]; l++){
1599 for (k = ic[ll]; k < ic[ll+1]; k++){
1600 if (mask[jc[k]] != -i - 2){
1603 fprintf(stderr,
"overflow in SparseMatrix_multiply !!!\n");
1608 mask[jc[k]] = -i - 2;
1616 if (!D)
goto RETURN;
1630 for (i = 0; i < m; i++){
1631 for (j = ia[i]; j < ia[i+1]; j++){
1633 for (l = ib[jj]; l < ib[jj+1]; l++){
1635 for (k = ic[ll]; k < ic[ll+1]; k++){
1636 if (mask[jc[k]] <
id[i]){
1639 d[nz] = a[j]*b[l]*c[k];
1642 assert(jd[mask[jc[k]]] == jc[k]);
1643 d[mask[jc[k]]] += a[j]*b[l]*c[k];
1659 for (i = 0; i < m; i++){
1660 for (j = ia[i]; j < ia[i+1]; j++){
1662 for (l = ib[jj]; l < ib[jj+1]; l++){
1664 for (k = ic[ll]; k < ic[ll+1]; k++){
1665 if (mask[jc[k]] <
id[i]){
1668 d[2*nz] = (a[2*j]*b[2*l] - a[2*j+1]*b[2*l+1])*c[2*k]
1669 - (a[2*j]*b[2*l+1] + a[2*j+1]*b[2*l])*c[2*k+1];
1670 d[2*nz+1] = (a[2*j]*b[2*l+1] + a[2*j+1]*b[2*l])*c[2*k]
1671 + (a[2*j]*b[2*l] - a[2*j+1]*b[2*l+1])*c[2*k+1];
1674 assert(jd[mask[jc[k]]] == jc[k]);
1675 d[2*mask[jc[k]]] += (a[2*j]*b[2*l] - a[2*j+1]*b[2*l+1])*c[2*k]
1676 - (a[2*j]*b[2*l+1] + a[2*j+1]*b[2*l])*c[2*k+1];
1677 d[2*mask[jc[k]]+1] += (a[2*j]*b[2*l+1] + a[2*j+1]*b[2*l])*c[2*k]
1678 + (a[2*j]*b[2*l] - a[2*j+1]*b[2*l+1])*c[2*k+1];
1689 int *a = (
int*) A->
a;
1690 int *b = (
int*) B->
a;
1691 int *c = (
int*) C->
a;
1692 int *d = (
int*) D->
a;
1694 for (i = 0; i < m; i++){
1695 for (j = ia[i]; j < ia[i+1]; j++){
1697 for (l = ib[jj]; l < ib[jj+1]; l++){
1699 for (k = ic[ll]; k < ic[ll+1]; k++){
1700 if (mask[jc[k]] <
id[i]){
1703 d[nz] += a[j]*b[l]*c[k];
1706 assert(jd[mask[jc[k]]] == jc[k]);
1707 d[mask[jc[k]]] += a[j]*b[l]*c[k];
1718 for (i = 0; i < m; i++){
1719 for (j = ia[i]; j < ia[i+1]; j++){
1721 for (l = ib[jj]; l < ib[jj+1]; l++){
1723 for (k = ic[ll]; k < ic[ll+1]; k++){
1724 if (mask[jc[k]] <
id[i]){
1729 assert(jd[mask[jc[k]]] == jc[k]);
1740 D =
NULL;
goto RETURN;
1771 int *ia = A->
ia, *ja = A->
ja, type = A->
type, n = A->
n;
1772 int *mask =
NULL, nz = 0, i, j, sta;
1776 mask =
MALLOC(
sizeof(
int)*((
size_t)n));
1777 for (i = 0; i < n; i++) mask[i] = -1;
1785 for (i = 0; i < A->
m; i++){
1786 for (j = sta; j < ia[i+1]; j++){
1787 if (mask[ja[j]] < ia[i]){
1792 assert(ja[mask[ja[j]]] == ja[j]);
1793 a[mask[ja[j]]] += a[j];
1807 for (i = 0; i < A->
m; i++){
1808 for (j = sta; j < ia[i+1]; j++){
1809 if (mask[ja[j]] < ia[i]){
1812 a[2*nz+1] = a[2*j+1];
1815 assert(ja[mask[ja[j]]] == ja[j]);
1816 a[2*mask[ja[j]]] += a[2*j];
1817 a[2*mask[ja[j]]+1] += a[2*j+1];
1827 for (i = 0; i < A->
m; i++){
1828 for (j = sta; j < ia[i+1]; j++){
1829 if (mask[ja[j]] < ia[i]){
1832 a[2*nz+1] = a[2*j+1];
1835 assert(ja[mask[ja[j]]] == ja[j]);
1836 a[2*mask[ja[j]]] += a[2*j];
1837 a[2*mask[ja[j]]+1] = a[2*j+1];
1847 for (i = 0; i < A->
m; i++){
1848 for (j = ia[i]; j < ia[i+1]; j++){
1849 ymax =
MAX(ymax, (
int) a[2*nz+1]);
1850 ymin =
MIN(ymin, (
int) a[2*nz+1]);
1855 mask =
MALLOC(
sizeof(
int)*((
size_t)n)*((
size_t)(ymax-ymin+1)));
1856 for (i = 0; i < n*(ymax-ymin+1); i++) mask[i] = -1;
1860 for (i = 0; i < A->
m; i++){
1861 for (j = sta; j < ia[i+1]; j++){
1862 id = ja[j] + ((
int)a[2*j+1] - ymin)*n;
1863 if (mask[
id] < ia[i]){
1866 a[2*nz+1] = a[2*j+1];
1869 assert(
id < n*(ymax-ymin+1));
1870 assert(ja[mask[
id]] == ja[j]);
1871 a[2*mask[id]] += a[2*j];
1872 a[2*mask[id]+1] = a[2*j+1];
1883 for (i = 0; i < A->
m; i++){
1884 for (j = ia[i]; j < ia[i+1]; j++){
1885 xmax =
MAX(xmax, (
int) a[2*nz]);
1886 xmin =
MAX(xmin, (
int) a[2*nz]);
1891 mask =
MALLOC(
sizeof(
int)*((
size_t)n)*((
size_t)(xmax-xmin+1)));
1892 for (i = 0; i < n*(xmax-xmin+1); i++) mask[i] = -1;
1896 for (i = 0; i < A->
m; i++){
1897 for (j = sta; j < ia[i+1]; j++){
1898 id = ja[j] + ((
int)a[2*j] - xmin)*n;
1899 if (mask[
id] < ia[i]){
1902 a[2*nz+1] = a[2*j+1];
1905 assert(ja[mask[
id]] == ja[j]);
1906 a[2*mask[id]] = a[2*j];
1907 a[2*mask[id]+1] += a[2*j+1];
1919 int *a = (
int*) A->
a;
1922 for (i = 0; i < A->
m; i++){
1923 for (j = sta; j < ia[i+1]; j++){
1924 if (mask[ja[j]] < ia[i]){
1929 assert(ja[mask[ja[j]]] == ja[j]);
1930 a[mask[ja[j]]] += a[j];
1942 for (i = 0; i < A->
m; i++){
1943 for (j = sta; j < ia[i+1]; j++){
1944 if (mask[ja[j]] < ia[i]){
1948 assert(ja[mask[ja[j]]] == ja[j]);
1972 if (nentries <= 0)
return A;
1976 if (nz + nentries >= A->
nzmax){
1977 nzmax = nz + nentries;
1978 nzmax =
MAX(10, (
int) 0.2*nzmax) + nzmax;
1979 A = SparseMatrix_realloc(A, nzmax);
1981 MEMCPY((
char*) A->
ia + ((
size_t)nz)*
sizeof(
int)/
sizeof(
char), irn,
sizeof(
int)*((
size_t)nentries));
1982 MEMCPY((
char*) A->
ja + ((
size_t)nz)*
sizeof(
int)/
sizeof(
char), jcn,
sizeof(
int)*((
size_t)nentries));
1983 if (A->
size)
MEMCPY((
char*) A->
a + ((
size_t)nz)*A->
size/
sizeof(
char), val, A->
size*((
size_t)nentries));
1984 for (i = 0; i < nentries; i++) {
1985 if (irn[i] >= A->
m) A->
m = irn[i]+1;
1986 if (jcn[i] >= A->
n) A->
n = jcn[i]+1;
1994 int i, j, *ia, *ja, nz, sta;
2005 for (i = 0; i < A->
m; i++){
2006 for (j = sta; j < ia[i+1]; j++){
2020 for (i = 0; i < A->
m; i++){
2021 for (j = sta; j < ia[i+1]; j++){
2025 a[2*nz+1] = a[2*j+1];
2036 int *a = (
int*) A->
a;
2037 for (i = 0; i < A->
m; i++){
2038 for (j = sta; j < ia[i+1]; j++){
2051 for (i = 0; i < A->
m; i++){
2052 for (j = sta; j < ia[i+1]; j++){
2074 int i, j, *ia, *ja, nz, sta;
2085 for (i = 0; i < A->
m; i++){
2086 for (j = sta; j < ia[i+1]; j++){
2100 for (i = 0; i < A->
m; i++){
2101 for (j = sta; j < ia[i+1]; j++){
2105 a[2*nz+1] = a[2*j+1];
2116 int *a = (
int*) A->
a;
2117 for (i = 0; i < A->
m; i++){
2118 for (j = sta; j < ia[i+1]; j++){
2131 for (i = 0; i < A->
m; i++){
2132 for (j = sta; j < ia[i+1]; j++){
2170 for (i = 0; i < A->
m; i++){
2171 deg = ia[i+1] - ia[i];
2172 for (j = ia[i]; j < ia[i+1]; j++){
2180 for (i = 0; i < A->
m; i++){
2181 deg = ia[i+1] - ia[i];
2182 for (j = ia[i]; j < ia[i+1]; j++){
2184 a[2*j] = a[2*j]/deg;
2185 a[2*j+1] = a[2*j+1]/deg;
2210 int i, *ia, *ja, nz, m, n;
2222 if (n != m)
return NULL;
2226 MEMCPY(B->
ia, ia,
sizeof(
int)*((
size_t)(m+1)));
2227 MEMCPY(B->
ja, ja,
sizeof(
int)*((
size_t)nz));
2235 for (i = 0; i < A->
nz; i++) a[i] = 1.;
2250 printf(
"only CSR and real matrix supported.\n");
2256 for (i = 0; i < A->
m; i++){
2258 for (j = A->
ia[i]; j < A->ia[i+1]; j++){
2262 for (j = A->
ia[i]; j < A->ia[i+1]; j++){
2279 printf(
"only CSR and real matrix supported.\n");
2285 for (i = 0; i < A->
m; i++){
2287 for (j = A->
ia[i]; j < A->ia[i+1]; j++){
2288 max =
MAX(
ABS(a[j]), max);
2291 for (j = A->
ia[i]; j < A->ia[i+1]; j++){
2306 printf(
"only CSR format supported.\n");
2318 for (i = nz - 1; i >= 0; i--){
2330 int *a = (
int*) A->
a;
2333 for (i = nz - 1; i >= 0; i--){
2334 aa[2*i] = (
real) a[i];
2363 printf(
"only CSR and real matrix supported.\n");
2370 for (i = 0; i < A->
m; i++){
2371 for (j = A->
ia[i]; j < A->ia[i+1]; j++){
2386 printf(
"SparseMatrix_apply_fun: only CSR and real/complex matrix supported.\n");
2393 for (i = 0; i < A->
m; i++){
2394 for (j = A->
ia[i]; j < A->ia[i+1]; j++){
2395 fun(i, A->
ja[j], len, &a[len*j]);
2403 int i, j, *ia, *ja, nz, sta;
2414 for (i = 0; i < A->
m; i++){
2415 for (j = sta; j < ia[i+1]; j++){
2416 if (
ABS(a[j]) > epsilon){
2429 for (i = 0; i < A->
m; i++){
2430 for (j = sta; j < ia[i+1]; j++){
2431 if (sqrt(a[2*j]*a[2*j]+a[2*j+1]*a[2*j+1]) > epsilon){
2434 a[2*nz+1] = a[2*j+1];
2445 int *a = (
int*) A->
a;
2446 for (i = 0; i < A->
m; i++){
2447 for (j = sta; j < ia[i+1]; j++){
2448 if (
ABS(a[j]) > epsilon){
2475 MEMCPY(B->
ia, A->
ia,
sizeof(
int)*((
size_t)(A->
m+1)));
2485 int i, j, m = A->
m, *ia = A->
ia, *ja = A->
ja;
2487 for (i = 0; i < m; i++){
2488 for (j = ia[i]; j < ia[i+1]; j++){
2489 if (i == ja[j])
return TRUE;
2505 int i, j, sta = 0, sto = 1, nz, ii;
2506 int m = A->
m, *ia = A->
ia, *ja = A->
ja;
2508 if (!(*levelset_ptr)) *levelset_ptr =
MALLOC(
sizeof(
int)*((
size_t)(m+2)));
2509 if (!(*levelset)) *levelset =
MALLOC(
sizeof(
int)*((
size_t)m));
2511 *mask = malloc(
sizeof(
int)*((
size_t)m));
2512 for (i = 0; i < m; i++) (*mask)[i] =
UNMASKED;
2516 assert(root >= 0 && root < m);
2517 (*levelset_ptr)[0] = 0;
2518 (*levelset_ptr)[1] = 1;
2519 (*levelset)[0] = root;
2524 while (sto > sta && (khops < 0 || *nlevel <= khops)){
2525 for (i = sta; i < sto; i++){
2526 ii = (*levelset)[i];
2527 for (j = ia[ii]; j < ia[ii+1]; j++){
2528 if (ii == ja[j])
continue;
2529 if ((*mask)[ja[j]] < 0){
2530 (*levelset)[nz++] = ja[j];
2531 (*mask)[ja[j]] = *nlevel + 1;
2535 (*levelset_ptr)[++(*nlevel)] = nz;
2539 if (khops < 0 || *nlevel <= khops){
2542 if (reinitialize_mask)
for (i = 0; i < (*levelset_ptr)[*nlevel]; i++) (*mask)[(*levelset)[i]] =
UNMASKED;
2560 int *levelset_ptr =
NULL, *levelset =
NULL, *mask =
NULL, nlevel;
2561 int m = A->
m, i, nn;
2566 if (!(*comps_ptr)) *comps_ptr =
MALLOC(
sizeof(
int)*((
size_t)(m+1)));
2569 (*comps_ptr)[0] = 0;
2570 for (i = 0; i < m; i++){
2571 if (i == 0 || mask[i] < 0) {
2573 if (i == 0) *comps = levelset;
2574 nn = levelset_ptr[nlevel];
2576 (*comps_ptr)[(*ncomp)+1] = (*comps_ptr)[(*ncomp)] + nn;
2582 if (levelset_ptr)
FREE(levelset_ptr);
2595 static int cmp(
void*i,
void*j){
2609 static int Dijkstra_internal(
SparseMatrix A,
int root,
real *
dist,
int *nlist,
int *list,
real *dist_max,
int *mask){
2624 int m = A->
m, i, j, jj, *ia = A->
ia, *ja = A->
ja, heap_id;
2628 nodedata
ndata, ndata_min;
2629 enum {UNVISITED = -2, FINISHED = -1};
2642 for (i = 0; i < A->
nz; i++) a[i] = aa[i*2];
2650 for (i = 0; i < A->
nz; i++) a[i] = (
real) ai[i];
2654 for (i = 0; i < A->
nz; i++) a[i] = 1.;
2660 heap_ids =
MALLOC(
sizeof(
int)*((
size_t)m));
2661 for (i = 0; i < m; i++) {
2663 heap_ids[i] = UNVISITED;
2675 assert(heap_ids[root] >= 0);
2679 dist[i] = ndata_min->
dist;
2681 heap_ids[i] = FINISHED;
2683 for (j = ia[i]; j < ia[i+1]; j++){
2685 heap_id = heap_ids[jj];
2687 if (jj == i || heap_id == FINISHED || (mask && mask[jj] < 0))
continue;
2689 if (heap_id == UNVISITED){
2707 *dist_max = dist[i];
2712 if (a && a != A->
a)
FREE(a);
2713 if (found == m || mask){
2720 static int Dijkstra(
SparseMatrix A,
int root,
real *dist,
int *nlist,
int *list,
real *dist_max){
2721 return Dijkstra_internal(A, root, dist, nlist, list, dist_max,
NULL);
2724 static int Dijkstra_masked(
SparseMatrix A,
int root,
real *dist,
int *nlist,
int *list,
real *dist_max,
int *mask){
2729 return Dijkstra_internal(A, root, dist, nlist, list, dist_max, mask);
2735 int m = A->
m, i, *list =
NULL, nlist;
2737 real *dist =
NULL, dist_max = -1, dist0 = -1;
2738 int roots[5], iroots, end11, end22;
2746 list =
MALLOC(
sizeof(
int)*((
size_t)m));
2748 list[nlist-1] = root;
2754 root = list[nlist - 1];
2755 flag = Dijkstra(A, root, dist, &nlist, list, &dist_max);
2757 assert(dist[list[nlist-1]] == dist_max);
2760 }
while (dist_max > dist0);
2762 *connectedQ = (!flag);
2766 *end2 = list[nlist-1];
2771 for (i =
MAX(0, nlist - 6); i < nlist - 1; i++){
2772 roots[iroots++] = list[i];
2774 for (i = 0; i < iroots; i++){
2777 fprintf(stderr,
"search for diameter again from root=%d\n", root);
2779 if (dist_max > dist0){
2780 *end1 = end11; *end2 = end22;
2785 fprintf(stderr,
"after aggressive search for diameter, diam = %f, ends = {%d,%d}\n", dist_max, *end1, *end2);
2801 int *levelset_ptr =
NULL, *levelset =
NULL, *mask =
NULL;
2803 int roots[5], iroots, enda, endb;
2814 *connectedQ = (levelset_ptr[nlevel] == m);
2815 while (nlevel0 < nlevel){
2817 root = levelset[levelset_ptr[nlevel] - 1];
2821 *end1 = levelset[0];
2822 *end2 = levelset[levelset_ptr[nlevel]-1];
2827 for (i = levelset_ptr[nlevel-1]; i <
MIN(levelset_ptr[nlevel], levelset_ptr[nlevel-1]+5); i++){
2829 roots[i - levelset_ptr[nlevel-1]] = levelset[i];
2831 for (i = 0; i < iroots; i++){
2834 if (nlevel > nlevel0) {
2846 return (
real) nlevel0 - 1;
2850 int end1, end2, connectedQ;
2855 int root = 0, nlevel, *levelset_ptr =
NULL, *levelset =
NULL, *mask =
NULL, connected;
2859 if (A->
m != A->
n)
return FALSE;
2864 connected = (levelset_ptr[nlevel] == A->
m);
2879 int *ia = A->
ia, *ja = A->
ja, n = A->
n, m = A->
m;
2880 int *super =
NULL, *nsuper =
NULL, i, j, *mask =
NULL, isup, *newmap, isuper;
2882 super =
MALLOC(
sizeof(
int)*((
size_t)(n)));
2883 nsuper =
MALLOC(
sizeof(
int)*((
size_t)(n+1)));
2884 mask =
MALLOC(
sizeof(
int)*((
size_t)n));
2885 newmap =
MALLOC(
sizeof(
int)*((
size_t)n));
2889 for (i = 0; i < n; i++) super[i] = isup;
2891 for (i = 0; i < n; i++) mask[i] = -1;
2894 for (i = 0; i < m; i++){
2897 printf(
"doing row %d-----\n",i+1);
2899 for (j = ia[i]; j < ia[i+1]; j++){
2900 isuper = super[ja[j]];
2903 for (j = ia[i]; j < ia[i+1]; j++){
2904 isuper = super[ja[j]];
2905 if (mask[isuper] < i){
2907 if (nsuper[isuper] == 0){
2909 printf(
"node %d keep super node id %d\n",ja[j]+1,isuper+1);
2912 newmap[isuper] = isuper;
2914 newmap[isuper] = isup;
2917 printf(
"make node %d into supernode %d\n",ja[j]+1,isup+1);
2919 super[ja[j]] = isup++;
2923 printf(
"node %d join super node %d\n",ja[j]+1,newmap[isuper]+1);
2925 super[ja[j]] = newmap[isuper];
2926 nsuper[newmap[isuper]]++;
2931 for (j = 0; j < isup; j++) printf(
"(%d,%d),",j+1,nsuper[j]);
2936 for (i = 0; i < n; i++){
2937 printf(
"node %d is in supernode %d\n",i, super[i]);
2941 fprintf(stderr,
"n = %d, nsup = %d\n",n,isup);
2946 for (i = 0; i < isup; i++) nsuper[i+1] += nsuper[i];
2949 for (i = 0; i < n; i++){
2951 (*cluster)[nsuper[isuper]++] = i;
2953 for (i = isup; i > 0; i--) nsuper[i] = nsuper[i-1];
2959 for (i = 0; i < *ncluster; i++){
2961 for (j = (*clusterp)[i]; j < (*clusterp)[i+1]; j++){
2962 printf(
"%d, ",(*cluster)[j]);
2978 int nz = A->
nz, type = A->
type;
2979 int m = A->
m, n = A->
n, i, j;
2981 if (!A)
return NULL;
2983 irn =
MALLOC(
sizeof(
int)*((
size_t)nz)*2);
2984 jcn =
MALLOC(
sizeof(
int)*((
size_t)nz)*2);
2991 MEMCPY((
void*)(((
char*) val) + ((
size_t)nz)*A->
size), A->
a, A->
size*((
size_t)nz));
2995 for (i = 0; i < m; i++){
2996 for (j = (A->
ia)[i]; j < (A->
ia)[i+1]; j++){
2998 jcn[nz++] = (A->
ja)[j] + m;
3001 for (i = 0; i < m; i++){
3002 for (j = (A->
ia)[i]; j < (A->
ia)[i+1]; j++){
3004 irn[nz++] = (A->
ja)[j] + m;
3020 switch (bipartite_options){
3022 if (A->
m == A->
n)
return A;
3046 int nz = 0, i, j, *irn, *jcn, *ia = A->
ia, *ja = A->
ja, m = A->
m, n = A->
n;
3050 int irow = 0, icol = 0;
3052 if (nrow <= 0 || ncol <= 0)
return NULL;
3056 rmask =
MALLOC(
sizeof(
int)*((
size_t)m));
3057 cmask =
MALLOC(
sizeof(
int)*((
size_t)n));
3058 for (i = 0; i < m; i++) rmask[i] = -1;
3059 for (i = 0; i < n; i++) cmask[i] = -1;
3062 for (i = 0; i < nrow; i++) {
3063 if (rindices[i] >= 0 && rindices[i] < m){
3064 rmask[rindices[i]] = irow++;
3068 for (i = 0; i < nrow; i++) {
3074 for (i = 0; i < ncol; i++) {
3075 if (cindices[i] >= 0 && cindices[i] < n){
3076 cmask[cindices[i]] = icol++;
3080 for (i = 0; i < ncol; i++) {
3085 for (i = 0; i < m; i++){
3086 if (rmask[i] < 0)
continue;
3087 for (j = ia[i]; j < ia[i+1]; j++){
3088 if (cmask[ja[j]] < 0)
continue;
3098 irn =
MALLOC(
sizeof(
int)*((size_t)nz));
3099 jcn =
MALLOC(
sizeof(
int)*((
size_t)nz));
3103 for (i = 0; i < m; i++){
3104 if (rmask[i] < 0)
continue;
3105 for (j = ia[i]; j < ia[i+1]; j++){
3106 if (cmask[ja[j]] < 0)
continue;
3108 jcn[nz] = cmask[ja[j]];
3119 irn =
MALLOC(
sizeof(
int)*((size_t)nz));
3120 jcn =
MALLOC(
sizeof(
int)*((
size_t)nz));
3124 for (i = 0; i < m; i++){
3125 if (rmask[i] < 0)
continue;
3126 for (j = ia[i]; j < ia[i+1]; j++){
3127 if (cmask[ja[j]] < 0)
continue;
3129 jcn[nz] = cmask[ja[j]];
3131 val[2*nz+1] = a[2*j+1];
3139 int *a = (
int*) A->
a;
3142 irn =
MALLOC(
sizeof(
int)*((size_t)nz));
3143 jcn =
MALLOC(
sizeof(
int)*((
size_t)nz));
3144 val =
MALLOC(
sizeof(
int)*((
size_t)nz));
3147 for (i = 0; i < m; i++){
3148 if (rmask[i] < 0)
continue;
3149 for (j = ia[i]; j < ia[i+1]; j++){
3150 if (cmask[ja[j]] < 0)
continue;
3152 jcn[nz] = cmask[ja[j]];
3161 irn =
MALLOC(
sizeof(
int)*((
size_t)nz));
3162 jcn =
MALLOC(
sizeof(
int)*((
size_t)nz));
3164 for (i = 0; i < m; i++){
3165 if (rmask[i] < 0)
continue;
3166 for (j = ia[i]; j < ia[i+1]; j++){
3167 if (cmask[ja[j]] < 0)
continue;
3169 jcn[nz++] = cmask[ja[j]];
3197 int *r, *c, nr, nc, i;
3200 if (nrow <= 0 && ncol <= 0)
return A;
3202 r =
MALLOC(
sizeof(
int)*((
size_t)A->
m));
3203 c =
MALLOC(
sizeof(
int)*((
size_t)A->
n));
3205 for (i = 0; i < A->
m; i++) r[i] = i;
3206 for (i = 0; i < A->
n; i++) c[i] = i;
3207 for (i = 0; i < nrow; i++) {
3208 if (rindices[i] >= 0 && rindices[i] < A->
m){
3209 r[rindices[i]] = -1;
3212 for (i = 0; i < ncol; i++) {
3213 if (cindices[i] >= 0 && cindices[i] < A->
n){
3214 c[cindices[i]] = -1;
3219 for (i = 0; i < A->
m; i++) {
3220 if (r[i] > 0) r[nr++] = r[i];
3222 for (i = 0; i < A->
n; i++) {
3223 if (c[i] > 0) c[nc++] = c[i];
3238 int *comps_ptr =
NULL;
3242 if (!A)
return NULL;
3249 for (i = 0; i < ncomp; i++){
3250 if (nmax < comps_ptr[i+1] - comps_ptr[i]){
3251 nmax = comps_ptr[i+1] - comps_ptr[i];
3273 old2new =
MALLOC(
sizeof(
int)*((
size_t)A->
n));
3274 for (i = 0; i < A->
n; i++) old2new[i] = -1;
3278 ia = B->
ia; ja = B->
ja;
3279 for (i = 0; i < B->
m; i++){
3280 if (ia[i+1] > ia[i] + threshold){
3284 if (!(*new2old)) *new2old =
MALLOC(
sizeof(
int)*((
size_t)(*nnew)));
3287 for (i = 0; i < B->
m; i++){
3288 if (ia[i+1] > ia[i] + threshold){
3289 (*new2old)[*nnew] = i;
3301 ia = B->
ia; ja = B->
ja;
3302 for (i = 0; i < ia[B->
m]; i++){
3303 assert(old2new[ja[i]] >= 0);
3304 ja[i] = old2new[ja[i]];
3325 for (i = 0; i < A->
nz; i++) a[i] = 1.;
3336 int m = A->
m, n = A->
n;
3344 ia = B->
ia; ja = B->
ja;
3345 mask =
MALLOC(
sizeof(
int)*((
size_t)n));
3346 irn =
MALLOC(
sizeof(
int)*(((
size_t)n)*((
size_t)n) - ((
size_t)A->
nz)));
3347 jcn =
MALLOC(
sizeof(
int)*(((
size_t)n)*((
size_t)n) - ((
size_t)A->
nz)));
3349 for (i = 0; i < n; i++){
3353 for (i = 0; i < n; i++){
3354 for (j = ia[i]; j < ia[i+1]; j++){
3357 for (j = 0; j < n; j++){
3386 int m = D->
m, n = D->
n;
3387 int *levelset_ptr =
NULL, *levelset =
NULL, *mask =
NULL;
3388 int aggressive =
FALSE;
3389 int connectedQ, end1, end2;
3390 enum {K_CENTER_DISCONNECTED = 1, K_CENTER_MEM};
3393 int nlist, *list =
NULL;
3394 int flag = 0, i, j, k, nlevel;
3395 int check_connected =
FALSE;
3405 for (i = 0; i < n; i++) dist_min[i] = -1;
3406 for (i = 0; i < n; i++) dist_sum[i] = 0;
3407 if (!(*centers)) *centers =
MALLOC(
sizeof(
int)*K);
3408 if (!(*dist0)) *dist0 =
MALLOC(
sizeof(
real)*K*n);
3412 if (check_connected && !connectedQ) {
3413 flag = K_CENTER_DISCONNECTED;
3417 for (k = 0; k < K; k++){
3418 (*centers)[k] = root;
3421 if (check_connected)
assert(levelset_ptr[nlevel] == n);
3422 for (i = 0; i < nlevel; i++) {
3423 for (j = levelset_ptr[i]; j < levelset_ptr[i+1]; j++){
3424 (*dist0)[k*n+levelset[j]] = i;
3426 dist_min[levelset[j]] = i;
3428 dist_min[levelset[j]] =
MIN(dist_min[levelset[j]], i);
3430 dist_sum[levelset[j]] += i;
3438 for (i = 0; i < n; i++) {
3439 if (!check_connected && dist_min[i] < 0)
continue;
3441 if (dmax < dist_min[i] || (dmax == dist_min[i] && dsum < dist_sum[i])){
3450 if (check_connected && !connectedQ)
return K_CENTER_DISCONNECTED;
3452 list =
MALLOC(
sizeof(
int)*n);
3454 for (k = 0; k < K; k++){
3456 (*centers)[k] = root;
3457 dist = &((*dist0)[k*n]);
3458 flag = Dijkstra(D, root, dist, &nlist, list, &dmax);
3460 flag = K_CENTER_MEM;
3463 if (check_connected)
assert(nlist == n);
3464 for (i = 0; i < n; i++){
3466 dist_min[i] = dist[i];
3468 dist_min[i] =
MIN(dist_min[i], dist[i]);
3470 dist_sum[i] += dist[i];
3477 for (i = 0; i < n; i++) {
3478 if (!check_connected && dist_min[i] < 0)
continue;
3480 if (dmax < dist_min[i] || (dmax == dist_min[i] && dsum < dist_sum[i])){
3491 for (i = 0; i < n; i++) dist_sum[i] /= k;
3492 for (k = 0; k < K; k++){
3493 for (i = 0; i < n; i++){
3494 (*dist0)[k*n+i] -= dist_sum[i];
3500 if (levelset_ptr)
FREE(levelset_ptr);
3501 if (levelset)
FREE(levelset);
3502 if (mask)
FREE(mask);
3505 if (dist)
FREE(dist);
3506 if (dist_min)
FREE(dist_min);
3507 if (dist_sum)
FREE(dist_sum);
3508 if (list)
FREE(list);
3529 int m = D->
m, n = D->
n;
3530 int *levelset_ptr =
NULL, *levelset =
NULL, *mask =
NULL;
3531 int aggressive =
FALSE;
3532 int connectedQ, end1, end2;
3533 enum {K_CENTER_DISCONNECTED = 1, K_CENTER_MEM};
3536 int nlist, *list =
NULL;
3537 int flag = 0, i, j, k, nlevel;
3548 for (i = 0; i < n; i++) dist_sum[i] = 0;
3549 if (!(*dist0)) *dist0 =
MALLOC(
sizeof(
real)*K*n);
3552 root = centers_user[0];
3555 flag = K_CENTER_DISCONNECTED;
3558 for (k = 0; k < K; k++){
3559 root = centers_user[k];
3561 assert(levelset_ptr[nlevel] == n);
3562 for (i = 0; i < nlevel; i++) {
3563 for (j = levelset_ptr[i]; j < levelset_ptr[i+1]; j++){
3564 (*dist0)[k*n+levelset[j]] = i;
3566 dist_min[levelset[j]] = i;
3568 dist_min[levelset[j]] =
MIN(dist_min[levelset[j]], i);
3570 dist_sum[levelset[j]] += i;
3576 root = centers_user[0];
3578 if (!connectedQ)
return K_CENTER_DISCONNECTED;
3579 list =
MALLOC(
sizeof(
int)*n);
3581 for (k = 0; k < K; k++){
3582 root = centers_user[k];
3584 dist = &((*dist0)[k*n]);
3585 flag = Dijkstra(D, root, dist, &nlist, list, &dmax);
3587 flag = K_CENTER_MEM;
3592 for (i = 0; i < n; i++){
3594 dist_min[i] = dist[i];
3596 dist_min[i] =
MIN(dist_min[i], dist[i]);
3598 dist_sum[i] += dist[i];
3606 for (i = 0; i < n; i++) dist_sum[i] /= k;
3607 for (k = 0; k < K; k++){
3608 for (i = 0; i < n; i++){
3609 (*dist0)[k*n+i] -= dist_sum[i];
3615 if (levelset_ptr)
FREE(levelset_ptr);
3616 if (levelset)
FREE(levelset);
3617 if (mask)
FREE(mask);
3620 if (dist)
FREE(dist);
3621 if (dist_min)
FREE(dist_min);
3622 if (dist_sum)
FREE(dist_sum);
3623 if (list)
FREE(list);
3638 for (i = 1; i <= m; i++) (A->
ia)[i] = (A->
ia)[i-1] + n;
3642 for (i = 0; i < m; i++){
3643 for (j = 0; j < n; j++) {
3665 int m = D->
m, n = D->
n;
3666 int *levelset_ptr =
NULL, *levelset =
NULL, *mask =
NULL;
3668 int nlist, *list =
NULL;
3669 int flag = 0, i, j, k, nlevel;
3678 if (!(*dist0)) *dist0 =
MALLOC(
sizeof(
real)*n*n);
3679 for (i = 0; i < n*n; i++) (*dist0)[i] = -1;
3682 for (k = 0; k < n; k++){
3684 assert(levelset_ptr[nlevel] == n);
3685 for (i = 0; i < nlevel; i++) {
3686 for (j = levelset_ptr[i]; j < levelset_ptr[i+1]; j++){
3687 (*dist0)[k*n+levelset[j]] = i;
3692 list =
MALLOC(
sizeof(
int)*n);
3693 for (k = 0; k < n; k++){
3694 dist = &((*dist0)[k*n]);
3695 flag = Dijkstra(D, k, dist, &nlist, list, &dmax);
3699 if (levelset_ptr)
FREE(levelset_ptr);
3700 if (levelset)
FREE(levelset);
3701 if (mask)
FREE(mask);
3704 if (list)
FREE(list);
3715 int m = D->
m, n = D->
n;
3717 int *centers =
NULL;
3721 int centering =
FALSE;
3730 for (i = 0; i < K; i++){
3731 center = centers[i];
3732 for (j = 0; j < n; j++){
3758 int m = D->
m, n = D->
n;
3759 int *levelset_ptr =
NULL, *levelset =
NULL, *mask =
NULL;
3761 int nlist, *list =
NULL;
3762 int flag = 0, i, j, k, itmp, nlevel;
3774 for (k = 0; k < n; k++){
3776 for (i = 0; i < nlevel; i++) {
3777 for (j = levelset_ptr[i]; j < levelset_ptr[i+1]; j++){
3778 itmp = levelset[j]; dtmp = i;
3784 list =
MALLOC(
sizeof(
int)*n);
3801 for (k = 0; k < n; k++){
3803 assert(nlevel-1 <= khops);
3804 flag = Dijkstra_masked(D, k, dist, &nlist, list, &dmax, mask);
3806 for (i = 0; i < nlevel; i++) {
3807 for (j = levelset_ptr[i]; j < levelset_ptr[i+1]; j++){
3808 assert(mask[levelset[j]] == i+1);
3809 mask[levelset[j]] = -1;
3812 for (j = 0; j < nlist; j++){
3813 itmp = list[j]; dtmp = dist[itmp];
3822 if (levelset_ptr)
FREE(levelset_ptr);
3823 if (levelset)
FREE(levelset);
3824 if (mask)
FREE(mask);
3825 if (dist)
FREE(dist);
3828 if (list)
FREE(list);
3857 int i, j, *ia, *ja, n = A->
m, nz, istatus, neighb;
3859 int gain, deg, k, deg_max = 0, deg_old;
3860 int *coreness_ptr, *coreness_list, coreness_now;
3869 mask =
MALLOC(
sizeof(
int)*n);
3870 for (i = 0; i < n; i++) mask[i] = -1;
3873 for (i = 0; i < n; i++){
3874 deg = ia[i+1] - ia[i];
3875 deg_max =
MAX(deg_max, deg);
3882 coreness_ptr =
MALLOC(
sizeof(
int)*(deg_max+2));
3883 coreness_list =
MALLOC(
sizeof(
int)*n);
3885 coreness_ptr[deg_old] = 0;
3891 if (deg > deg_old) {
3893 for (j = deg_old + 1; j <= deg; j++) coreness_ptr[j] = nz;
3897 coreness_list[nz++] = k;
3898 mask[k] = coreness_now;
3900 for (j = ia[k]; j < ia[k+1]; j++){
3902 if (mask[neighb] < 0){
3911 coreness_ptr[coreness_now + 1] = nz;
3913 *coreness_max0 = coreness_now;
3914 *coreness_ptr0 = coreness_ptr;
3915 *coreness_list0 = coreness_list;
3918 for (i = 0; i <= coreness_now; i++){
3919 if (coreness_ptr[i+1] - coreness_ptr[i] > 0){
3920 fprintf(stderr,
"num_in_core[%d] = %d: ",i, coreness_ptr[i+1] - coreness_ptr[i]);
3922 for (j = coreness_ptr[i]; j < coreness_ptr[i+1]; j++){
3923 fprintf(stderr,
"%d,",coreness_list[j]);
3926 fprintf(stderr,
"\n");
3939 int coreness_max, *coreness_ptr =
NULL, *coreness_list =
NULL, i, j;
3941 if (!(*coreness)) coreness =
MALLOC(
sizeof(
int)*A->
m);
3945 for (i = 0; i <= coreness_max; i++){
3946 for (j = coreness_ptr[i]; j < coreness_ptr[i+1]; j++){
3947 (*coreness)[coreness_list[j]] = i;
3951 assert(coreness_ptr[coreness_ptr[coreness_max+1]] = A->
m);
3968 int i, j, jj, *ia, *ja, n = A->
m, nz, istatus, neighb;
3970 int gain, deg = 0, k, deg_max = 0, deg_old;
3971 int *hairness_ptr, *hairness_list, l;
3980 mask =
MALLOC(
sizeof(
int)*n);
3981 for (i = 0; i < n; i++) mask[i] = -1;
3984 for (i = 0; i < n; i++){
3985 deg = ia[i+1] - ia[i];
3986 deg_max =
MAX(deg_max, deg);
3992 hairness_ptr =
MALLOC(
sizeof(
int)*(deg_max+2));
3993 hairness_list =
MALLOC(
sizeof(
int)*n);
3995 hairness_ptr[deg_old + 1] = n;
4002 if (deg < deg_old) {
4004 for (j = deg_old; j >= deg; j--) hairness_ptr[j] = nz + 1;
4006 for (jj = hairness_ptr[deg_old]; jj < hairness_ptr [deg_old+1]; jj++){
4007 l = hairness_list[jj];
4009 for (j = ia[l]; j < ia[l+1]; j++){
4011 if (neighb == k) deg--;
4012 if (mask[neighb] < 0){
4031 hairness_list[nz--] = k;
4033 hairness_ptr[deg] = nz + 1;
4035 for (i = 0; i < deg; i++) hairness_ptr[i] = 0;
4037 *hairness_max0 = deg_max;
4038 *hairness_ptr0 = hairness_ptr;
4039 *hairness_list0 = hairness_list;
4042 for (i = 0; i <= deg_max; i++){
4043 if (hairness_ptr[i+1] - hairness_ptr[i] > 0){
4044 fprintf(stderr,
"num_in_hair[%d] = %d: ",i, hairness_ptr[i+1] - hairness_ptr[i]);
4046 for (j = hairness_ptr[i]; j < hairness_ptr[i+1]; j++){
4047 fprintf(stderr,
"%d,",hairness_list[j]);
4050 fprintf(stderr,
"\n");
4064 int hairness_max, *hairness_ptr =
NULL, *hairness_list =
NULL, i, j;
4066 if (!(*hairness)) hairness =
MALLOC(
sizeof(
int)*A->
m);
4070 for (i = 0; i <= hairness_max; i++){
4071 for (j = hairness_ptr[i]; j < hairness_ptr[i+1]; j++){
4072 (*hairness)[hairness_list[j]] = i;
4076 assert(hairness_ptr[hairness_ptr[hairness_max+1]] = A->
m);
4090 int *ia = A->
ia, *ja = A->
ja;
4091 real *x, *y, *diag, res;
4096 assert(teleport_probablity >= 0);
4105 for (i = 0; i < n; i++) a[i] = ((
real*) A->
a)[2*i];
4109 for (i = 0; i < n; i++) a[i] = ((
int*) A->
a)[i];
4120 if (!(*page_rank)) *page_rank =
MALLOC(
sizeof(
real)*n);
4124 for (i = 0; i < n; i++) diag[i] = 0;
4127 for (i = 0; i < n; i++) x[i] = 1./n;
4131 for (i = 0; i < n; i++){
4132 for (j = ia[i]; j < ia[i+1]; j++){
4133 if (ja[j] == i)
continue;
4134 diag[i] +=
ABS(a[j]);
4138 for (i = 0; i < n; i++){
4139 for (j = ia[i]; j < ia[i+1]; j++){
4140 if (ja[j] == i)
continue;
4145 for (i = 0; i < n; i++) diag[i] = 1./
MAX(diag[i],
MACHINEACC);
4150 for (i = 0; i < n; i++) y[i] = 0;
4152 for (i = 0; i < n; i++){
4153 for (j = ia[i]; j < ia[i+1]; j++){
4154 if (ja[j] == i)
continue;
4155 y[ja[j]] += a[j]*x[i]*diag[i];
4159 for (i = 0; i < n; i++){
4160 for (j = ia[i]; j < ia[i+1]; j++){
4161 if (ja[j] == i)
continue;
4162 y[ja[j]] += x[i]*diag[i];
4166 for (i = 0; i < n; i++){
4167 y[i] = (1-teleport_probablity)*y[i] + teleport_probablity/n;
4179 for (i = 0; i < n; i++) res +=
ABS(x[i] - y[i]);
4180 if (
Verbose) fprintf(stderr,
"page rank iter -- %d, res = %f\n",iter, res);
4182 }
while (res > epsilon);
4186 if (a && a != A->
a)
FREE(a);
SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int *rindices, int *cindices)
void SparseMatrix_export_binary_fp(FILE *f, SparseMatrix A)
void SparseMatrix_khairness(SparseMatrix A, int **hairness)
SparseMatrix SparseMatrix_multiply3(SparseMatrix A, SparseMatrix B, SparseMatrix C)
void SparseMatrix_level_sets_internal(int khops, SparseMatrix A, int root, int *nlevel, int **levelset_ptr, int **levelset, int **mask, int reinitialize_mask)
SparseMatrix SparseMatrix_import_binary_fp(FILE *f)
SparseMatrix SparseMatrix_multiply_by_scaler(SparseMatrix A, real s)
SparseMatrix SparseMatrix_sum_repeat_entries(SparseMatrix A, int what_to_sum)
int BinaryHeap_reset(BinaryHeap h, int id, void *item)
SparseMatrix SparseMatrix_symmetrize_nodiag(SparseMatrix A, int pattern_symmetric_only)
real SparseMatrix_pseudo_diameter_only(SparseMatrix A)
SparseMatrix SparseMatrix_normalize_to_rowsum1(SparseMatrix A)
void SparseMatrix_page_rank(SparseMatrix A, real teleport_probablity, int weighted, real epsilon, real **page_rank)
SparseMatrix SparseMatrix_to_square_matrix(SparseMatrix A, int bipartite_options)
SparseMatrix SparseMatrix_set_entries_to_real_one(SparseMatrix A)
SparseMatrix SparseMatrix_copy(SparseMatrix A)
SparseMatrix SparseMatrix_scaled_by_vector(SparseMatrix A, real *v, int apply_to_row)
SparseMatrix SparseMatrix_remove_upper(SparseMatrix A)
SparseMatrix SparseMatrix_import_binary(char *name)
SparseMatrix SparseMatrix_new(int m, int n, int nz, int type, int format)
PriorityQueue PriorityQueue_push(PriorityQueue q, int i, int gain)
SparseMatrix SparseMatrix_exclude_submatrix(SparseMatrix A, int nrow, int ncol, int *rindices, int *cindices)
BinaryHeap BinaryHeap_new(int(*cmp)(void *item1, void *item2))
int PriorityQueue_remove(PriorityQueue q, int i)
int SparseMatrix_connectedQ(SparseMatrix A0)
#define SparseMatrix_known_symmetric(A)
SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A)
void SparseMatrix_export_binary(char *name, SparseMatrix A, int *flag)
#define clear_flag(a, flag)
void SparseMatrix_multiply_dense(SparseMatrix A, int ATransposed, real *v, int vTransposed, real **res, int res_transposed, int dim)
void SparseMatrix_decompose_to_supervariables(SparseMatrix A, int *ncluster, int **cluster, int **clusterp)
SparseMatrix SparseMatrix_from_coordinate_arrays_not_compacted(int nz, int m, int n, int *irn, int *jcn, void *val0, int type, size_t sz, int what_to_sum)
int SparseMatrix_has_diagonal(SparseMatrix A)
int SparseMatrix_is_symmetric(SparseMatrix A, int test_pattern_symmetry_only)
int SparseMatrix_k_centers_user(SparseMatrix D0, int weighted, int K, int *centers_user, int centering, real **dist0)
void SparseMatrix_multiply_vector(SparseMatrix A, real *v, real **res, int transposed)
int BinaryHeap_insert(BinaryHeap h, void *item)
SparseMatrix SparseMatrix_largest_component(SparseMatrix A)
void SparseMatrix_kcore_decomposition(SparseMatrix A, int *coreness_max0, int **coreness_ptr0, int **coreness_list0)
SparseMatrix SparseMatrix_normalize_by_row(SparseMatrix A)
SparseMatrix SparseMatrix_delete_sparse_columns(SparseMatrix A, int threshold, int **new2old, int *nnew, int inplace)
SparseMatrix SparseMatrix_general_new(int m, int n, int nz, int type, size_t sz, int format)
void SparseMatrix_print(char *c, SparseMatrix A)
SparseMatrix SparseMatrix_get_augmented(SparseMatrix A)
void SparseMatrix_kcoreness(SparseMatrix A, int **coreness)
#define SparseMatrix_set_pattern_symmetric(A)
SparseMatrix SparseMatrix_from_coordinate_format_not_compacted(SparseMatrix A, int what_to_sum)
SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A)
void SparseMatrix_export(FILE *f, SparseMatrix A)
SparseMatrix SparseMatrix_apply_fun_general(SparseMatrix A, void(*fun)(int i, int j, int n, double *x))
int SparseMatrix_distance_matrix(SparseMatrix D0, int weighted, real **dist0)
void SparseMatrix_print_csr(char *c, SparseMatrix A)
PriorityQueue PriorityQueue_new(int n, int ngain)
SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, int pattern_symmetric_only)
void SparseMatrix_level_sets(SparseMatrix A, int root, int *nlevel, int **levelset_ptr, int **levelset, int **mask, int reinitialize_mask)
void SparseMatrix_level_sets_khops(int khops, SparseMatrix A, int root, int *nlevel, int **levelset_ptr, int **levelset, int **mask, int reinitialize_mask)
void * BinaryHeap_extract_min(BinaryHeap h)
void SparseMatrix_delete(SparseMatrix A)
SparseMatrix SparseMatrix_from_dense(int m, int n, real *x)
real SparseMatrix_pseudo_diameter_unweighted(SparseMatrix A0, int root, int aggressive, int *end1, int *end2, int *connectedQ)
if(aagss+aagstacksize-1<=aagssp)
SparseMatrix SparseMatrix_sort(SparseMatrix A)
SparseMatrix SparseMatrix_delete_empty_columns(SparseMatrix A, int **new2old, int *nnew, int inplace)
struct nodedata_struct * nodedata
real SparseMatrix_pseudo_diameter_weighted(SparseMatrix A0, int root, int aggressive, int *end1, int *end2, int *connectedQ)
int SparseMatrix_k_centers(SparseMatrix D0, int weighted, int K, int root, int **centers, int centering, real **dist0)
SparseMatrix SparseMatrix_from_coordinate_arrays(int nz, int m, int n, int *irn, int *jcn, void *val0, int type, size_t sz)
SparseMatrix SparseMatrix_crop(SparseMatrix A, real epsilon)
SparseMatrix SparseMatrix_distance_matrix_k_centers(int K, SparseMatrix D, int weighted)
EXTERN unsigned char Verbose
void * BinaryHeap_get_item(BinaryHeap h, int id)
SparseMatrix SparseMatrix_multiply(SparseMatrix A, SparseMatrix B)
void SparseMatrix_khair_decomposition(SparseMatrix A, int *hairness_max0, int **hairness_ptr0, int **hairness_list0)
SparseMatrix SparseMatrix_make_undirected(SparseMatrix A)
int PriorityQueue_pop(PriorityQueue q, int *i, int *gain)
SparseMatrix SparseMatrix_distance_matrix_khops(int khops, SparseMatrix D0, int weighted)
#define SparseMatrix_known_strucural_symmetric(A)
SparseMatrix SparseMatrix_divide_row_by_degree(SparseMatrix A)
SparseMatrix SparseMatrix_to_complex(SparseMatrix A)
void SparseMatrix_weakly_connected_components(SparseMatrix A0, int *ncomp, int **comps, int **comps_ptr)
int PriorityQueue_get_gain(PriorityQueue q, int i)
double dist(Site *s, Site *t)
SparseMatrix SparseMatrix_apply_fun(SparseMatrix A, double(*fun)(double x))
void BinaryHeap_delete(BinaryHeap h, void(*del)(void *item))
SparseMatrix SparseMatrix_add(SparseMatrix A, SparseMatrix B)
SparseMatrix SparseMatrix_coordinate_form_add_entries(SparseMatrix A, int nentries, int *irn, int *jcn, void *val)
#define SparseMatrix_set_symmetric(A)
void SparseMatrix_print_coord(char *c, SparseMatrix A)
SparseMatrix SparseMatrix_from_coordinate_format(SparseMatrix A)
SparseMatrix SparseMatrix_transpose(SparseMatrix A)
#define SparseMatrix_set_undirected(A)
SparseMatrix SparseMatrix_complement(SparseMatrix A, int undirected)