26 size =
sizeof(double);
29 size = 2*
sizeof(double);
60 B->is_undirected =
true;
66 int *ia =
A->ia, *ja =
A->ja, *ib, *jb, nz =
A->nz, m =
A->m, n =
A->n,
type =
A->type,
format =
A->format;
77 for (i = 0; i <= n; i++) ib[i] = 0;
78 for (i = 0; i < m; i++){
79 for (j = ia[i]; j < ia[i+1]; j++){
84 for (i = 0; i < n; i++) ib[i+1] += ib[i];
90 for (i = 0; i < m; i++){
91 for (j = ia[i]; j < ia[i+1]; j++){
93 b[ib[ja[j]]++] = a[j];
101 for (i = 0; i < m; i++){
102 for (j = ia[i]; j < ia[i+1]; j++){
104 b[2*ib[ja[j]]] = a[2*j];
105 b[2*ib[ja[j]]+1] = a[2*j+1];
114 for (i = 0; i < m; i++){
115 for (j = ia[i]; j < ia[i+1]; j++){
117 bi[ib[ja[j]]++] = ai[j];
123 for (i = 0; i < m; i++){
124 for (j = ia[i]; j < ia[i+1]; j++){
138 for (i = n-1; i >= 0; i--) ib[i+1] = ib[i];
146 bool pattern_symmetric_only) {
153 A->is_symmetric =
true;
154 A->is_pattern_symmetric =
true;
159 if (!
A)
return false;
163 int *ia, *ja, *ib, *jb,
type, m;
169 if (
A->is_symmetric)
return true;
170 if (test_pattern_symmetry_only &&
A->is_pattern_symmetric)
return true;
172 if (
A->m !=
A->n)
return false;
175 if (!
B)
return false;
183 mask =
gv_calloc((
size_t)m,
sizeof(
int));
184 for (i = 0; i < m; i++) mask[i] = -1;
193 for (i = 0; i <= m; i++)
if (ia[i] != ib[i])
goto RETURN;
194 for (i = 0; i < m; i++){
195 for (j = ia[i]; j < ia[i+1]; j++){
198 for (j = ib[i]; j < ib[i+1]; j++){
199 if (mask[jb[j]] < ia[i])
goto RETURN;
201 for (j = ib[i]; j < ib[i+1]; j++){
211 for (i = 0; i <= m; i++)
if (ia[i] != ib[i])
goto RETURN;
212 for (i = 0; i < m; i++){
213 for (j = ia[i]; j < ia[i+1]; j++){
216 for (j = ib[i]; j < ib[i+1]; j++){
217 if (mask[jb[j]] < ia[i])
goto RETURN;
219 for (j = ib[i]; j < ib[i+1]; j++){
230 for (i = 0; i < m; i++){
231 for (j = ia[i]; j < ia[i+1]; j++){
234 for (j = ib[i]; j < ib[i+1]; j++){
235 if (mask[jb[j]] < ia[i])
goto RETURN;
237 for (j = ib[i]; j < ib[i+1]; j++){
238 if (bi[j] != ai[mask[jb[j]]])
goto RETURN;
245 for (i = 0; i < m; i++){
246 for (j = ia[i]; j < ia[i+1]; j++){
249 for (j = ib[i]; j < ib[i+1]; j++){
250 if (mask[jb[j]] < ia[i])
goto RETURN;
263 if (!test_pattern_symmetry_only) {
264 A->is_symmetric =
true;
266 A->is_pattern_symmetric =
true;
288 A->ia =
gv_calloc((
size_t)(m + 1),
sizeof(
int));
298 size_t nz_t = (size_t) nz;
310 if (
A->size > 0 && nz_t > 0) {
321 size_t nz_t = (size_t) nz;
394 fprintf(f,
"%%%%MatrixMarket matrix coordinate real general\n");
397 fprintf(f,
"%%%%MatrixMarket matrix coordinate complex general\n");
400 fprintf(f,
"%%%%MatrixMarket matrix coordinate integer general\n");
403 fprintf(f,
"%%%%MatrixMarket matrix coordinate pattern general\n");
411 fprintf(f,
"%d %d %d\n",
A->m,
A->n,
A->nz);
418 for (i = 0; i < m; i++){
419 for (j = ia[i]; j < ia[i+1]; j++){
420 fprintf(f,
"%d %d %16.8g\n",i+1, ja[j]+1, a[j]);
426 for (i = 0; i < m; i++){
427 for (j = ia[i]; j < ia[i+1]; j++){
428 fprintf(f,
"%d %d %16.8g %16.8g\n",i+1, ja[j]+1, a[2*j], a[2*j+1]);
434 for (i = 0; i < m; i++){
435 for (j = ia[i]; j < ia[i+1]; j++){
436 fprintf(f,
"%d %d %d\n",i+1, ja[j]+1, ai[j]);
441 for (i = 0; i < m; i++){
442 for (j = ia[i]; j < ia[i+1]; j++){
443 fprintf(f,
"%d %d\n",i+1, ja[j]+1);
463 fprintf(f,
"%%%%MatrixMarket matrix coordinate real general\n");
466 fprintf(f,
"%%%%MatrixMarket matrix coordinate complex general\n");
469 fprintf(f,
"%%%%MatrixMarket matrix coordinate integer general\n");
472 fprintf(f,
"%%%%MatrixMarket matrix coordinate pattern general\n");
480 fprintf(f,
"%d %d %d\n",
A->m,
A->n,
A->nz);
487 for (i = 0; i <
A->nz; i++){
488 fprintf(f,
"%d %d %16.8g\n",ia[i]+1, ja[i]+1, a[i]);
493 for (i = 0; i <
A->nz; i++){
494 fprintf(f,
"%d %d %16.8g %16.8g\n",ia[i]+1, ja[i]+1, a[2*i], a[2*i+1]);
499 for (i = 0; i <
A->nz; i++){
500 fprintf(f,
"%d %d %d\n",ia[i]+1, ja[i]+1, ai[i]);
504 for (i = 0; i <
A->nz; i++){
505 fprintf(f,
"%d %d\n",ia[i]+1, ja[i]+1);
577 assert(m > 0 && n > 0 && nz >= 0);
579 if (m <=0 || n <= 0 || nz < 0)
return NULL;
586 for (i = 0; i <= m; i++){
594 for (i = 0; i < nz; i++){
595 if (irn[i] < 0 || irn[i] >= m || jcn[i] < 0 || jcn[i] >= n) {
601 for (i = 0; i < m; i++) ia[i+1] += ia[i];
602 for (i = 0; i < nz; i++){
603 a[ia[irn[i]]] = val[i];
604 ja[ia[irn[i]]++] = jcn[i];
606 for (i = m; i > 0; i--) ia[i] = ia[i - 1];
612 for (i = 0; i < nz; i++){
613 if (irn[i] < 0 || irn[i] >= m || jcn[i] < 0 || jcn[i] >= n) {
619 for (i = 0; i < m; i++) ia[i+1] += ia[i];
620 for (i = 0; i < nz; i++){
621 a[2*ia[irn[i]]] = *(val++);
622 a[2*ia[irn[i]]+1] = *(val++);
623 ja[ia[irn[i]]++] = jcn[i];
625 for (i = m; i > 0; i--) ia[i] = ia[i - 1];
631 for (i = 0; i < nz; i++){
632 if (irn[i] < 0 || irn[i] >= m || jcn[i] < 0 || jcn[i] >= n) {
638 for (i = 0; i < m; i++) ia[i+1] += ia[i];
639 for (i = 0; i < nz; i++){
640 ai[ia[irn[i]]] = vali[i];
641 ja[ia[irn[i]]++] = jcn[i];
643 for (i = m; i > 0; i--) ia[i] = ia[i - 1];
647 for (i = 0; i < nz; i++){
648 if (irn[i] < 0 || irn[i] >= m || jcn[i] < 0 || jcn[i] >= n) {
654 for (i = 0; i < m; i++) ia[i+1] += ia[i];
655 for (i = 0; i < nz; i++){
656 ja[ia[irn[i]]++] = jcn[i];
658 for (i = m; i > 0; i--) ia[i] = ia[i - 1];
662 for (i = 0; i < nz; i++){
663 if (irn[i] < 0 || irn[i] >= m || jcn[i] < 0 || jcn[i] >= n) {
669 for (i = 0; i < m; i++) ia[i+1] += ia[i];
670 memcpy(
A->a, val0,
A->size*((
size_t)nz));
671 for (i = 0; i < nz; i++){
672 ja[ia[irn[i]]++] = jcn[i];
674 for (i = m; i > 0; i--) ia[i] = ia[i - 1];
704 int *ia =
A->ia, *ja =
A->ja, *ib =
B->ia, *jb =
B->ja, *ic, *jc;
709 assert(
A->type ==
B->type);
712 if (m !=
B->m || n !=
B->n)
return NULL;
714 nzmax =
A->nz +
B->nz;
721 mask =
gv_calloc((
size_t)n,
sizeof(
int));
723 for (i = 0; i < n; i++) mask[i] = -1;
732 for (i = 0; i < m; i++){
733 for (j = ia[i]; j < ia[i+1]; j++){
739 for (j = ib[i]; j < ib[i+1]; j++){
740 if (mask[jb[j]] < ic[i]){
744 c[mask[jb[j]]] += b[j];
755 for (i = 0; i < m; i++){
756 for (j = ia[i]; j < ia[i+1]; j++){
760 c[2*nz+1] = a[2*j+1];
763 for (j = ib[i]; j < ib[i+1]; j++){
764 if (mask[jb[j]] < ic[i]){
767 c[2*nz+1] = b[2*j+1];
770 c[2*mask[jb[j]]] += b[2*j];
771 c[2*mask[jb[j]]+1] += b[2*j+1];
782 for (i = 0; i < m; i++){
783 for (j = ia[i]; j < ia[i+1]; j++){
789 for (j = ib[i]; j < ib[i+1]; j++){
790 if (mask[jb[j]] < ic[i]){
795 c[mask[jb[j]]] += b[j];
803 for (i = 0; i < m; i++){
804 for (j = ia[i]; j < ia[i+1]; j++){
809 for (j = ib[i]; j < ib[i+1]; j++){
810 if (mask[jb[j]] < ic[i]){
836 int i, j, k, *ia, *ja, m;
847 for (i = 0; i < m; i++){
848 for (k = 0; k <
dim; k++) res[i *
dim + k] = 0;
849 for (j = ia[i]; j < ia[i+1]; j++){
850 for (k = 0; k <
dim; k++) res[i *
dim + k] += a[j] * v[ja[j] *
dim + k];
857 int i, j, *ia, *ja, m;
858 double *a, *u =
NULL;
872 if (!u) u =
gv_calloc((
size_t)m,
sizeof(
double));
873 for (i = 0; i < m; i++){
875 for (j = ia[i]; j < ia[i+1]; j++){
876 u[i] += a[j]*v[ja[j]];
881 if (!u) u =
gv_calloc((
size_t)m,
sizeof(
double));
882 for (i = 0; i < m; i++){
884 for (j = ia[i]; j < ia[i+1]; j++){
893 if (!u) u =
gv_calloc((
size_t)m,
sizeof(
double));
894 for (i = 0; i < m; i++){
896 for (j = ia[i]; j < ia[i+1]; j++){
897 u[i] += ai[j]*v[ja[j]];
902 if (!u) u =
gv_calloc((
size_t)m,
sizeof(
double));
903 for (i = 0; i < m; i++){
905 for (j = ia[i]; j < ia[i+1]; j++){
923 int *ia =
A->ia, *ja =
A->ja, *ib =
B->ia, *jb =
B->ja, *ic, *jc;
924 int i, j, k, jj,
type, nz;
929 if (
A->n !=
B->m)
return NULL;
930 if (
A->type !=
B->type){
932 printf(
"in SparseMatrix_multiply, the matrix types do not match, right now only multiplication of matrices of the same type is supported\n");
938 mask = calloc((
size_t)
B->n,
sizeof(
int));
939 if (!mask)
return NULL;
941 for (i = 0; i <
B->n; i++) mask[i] = -1;
944 for (i = 0; i < m; i++){
945 for (j = ia[i]; j < ia[i+1]; j++){
947 for (k = ib[jj]; k < ib[jj+1]; k++){
948 if (mask[jb[k]] != -i - 2){
951 fprintf(stderr,
"overflow in SparseMatrix_multiply !!!\n");
957 mask[jb[k]] = -i - 2;
977 for (i = 0; i < m; i++){
978 for (j = ia[i]; j < ia[i+1]; j++){
980 for (k = ib[jj]; k < ib[jj+1]; k++){
981 if (mask[jb[k]] < ic[i]){
987 assert(jc[mask[jb[k]]] == jb[k]);
988 c[mask[jb[k]]] += a[j]*b[k];
1002 for (i = 0; i < m; i++){
1003 for (j = ia[i]; j < ia[i+1]; j++){
1005 for (k = ib[jj]; k < ib[jj+1]; k++){
1006 if (mask[jb[k]] < ic[i]){
1009 c[2*nz] = a[2*j]*b[2*k] - a[2*j+1]*b[2*k+1];
1010 c[2*nz+1] = a[2*j]*b[2*k+1] + a[2*j+1]*b[2*k];
1013 assert(jc[mask[jb[k]]] == jb[k]);
1014 c[2*mask[jb[k]]] += a[2*j]*b[2*k] - a[2*j+1]*b[2*k+1];
1015 c[2*mask[jb[k]]+1] += a[2*j]*b[2*k+1] + a[2*j+1]*b[2*k];
1029 for (i = 0; i < m; i++){
1030 for (j = ia[i]; j < ia[i+1]; j++){
1032 for (k = ib[jj]; k < ib[jj+1]; k++){
1033 if (mask[jb[k]] < ic[i]){
1039 assert(jc[mask[jb[k]]] == jb[k]);
1040 c[mask[jb[k]]] += a[j]*b[k];
1050 for (i = 0; i < m; i++){
1051 for (j = ia[i]; j < ia[i+1]; j++){
1053 for (k = ib[jj]; k < ib[jj+1]; k++){
1054 if (mask[jb[k]] < ic[i]){
1059 assert(jc[mask[jb[k]]] == jb[k]);
1086 int *ia =
A->ia, *ja =
A->ja, *ib =
B->ia, *jb =
B->ja, *ic =
C->ia, *jc =
C->ja, *
id, *jd;
1087 int i, j, k, l, ll, jj,
type, nz;
1092 if (
A->n !=
B->m)
return NULL;
1093 if (
B->n !=
C->m)
return NULL;
1095 if (
A->type !=
B->type ||
B->type !=
C->type){
1097 printf(
"in SparseMatrix_multiply, the matrix types do not match, right now only multiplication of matrices of the same type is supported\n");
1105 mask = calloc((
size_t)
C->n,
sizeof(
int));
1106 if (!mask)
return NULL;
1108 for (i = 0; i <
C->n; i++) mask[i] = -1;
1111 for (i = 0; i < m; i++){
1112 for (j = ia[i]; j < ia[i+1]; j++){
1114 for (l = ib[jj]; l < ib[jj+1]; l++){
1116 for (k = ic[ll]; k < ic[ll+1]; k++){
1117 if (mask[jc[k]] != -i - 2){
1120 fprintf(stderr,
"overflow in SparseMatrix_multiply !!!\n");
1125 mask[jc[k]] = -i - 2;
1144 for (i = 0; i < m; i++){
1145 for (j = ia[i]; j < ia[i+1]; j++){
1147 for (l = ib[jj]; l < ib[jj+1]; l++){
1149 for (k = ic[ll]; k < ic[ll+1]; k++){
1150 if (mask[jc[k]] <
id[i]){
1153 d[nz] = a[j]*b[l]*c[k];
1156 assert(jd[mask[jc[k]]] == jc[k]);
1157 d[mask[jc[k]]] += a[j]*b[l]*c[k];
1174 int *ia =
A->
ia, *ja =
A->ja,
type =
A->type, n =
A->n;
1175 int *mask =
NULL, nz = 0, i, j, sta;
1177 mask =
gv_calloc((
size_t)n,
sizeof(
int));
1178 for (i = 0; i < n; i++) mask[i] = -1;
1186 for (i = 0; i <
A->m; i++){
1187 for (j = sta; j < ia[i+1]; j++){
1188 if (mask[ja[j]] < ia[i]){
1193 assert(ja[mask[ja[j]]] == ja[j]);
1194 a[mask[ja[j]]] += a[j];
1207 for (i = 0; i <
A->m; i++) {
1208 for (j = sta; j < ia[i+1]; j++) {
1209 if (mask[ja[j]] < ia[i]) {
1211 a[2 * nz] = a[2 * j];
1212 a[2 * nz + 1] = a[2 * j + 1];
1215 assert(ja[mask[ja[j]]] == ja[j]);
1216 a[2 * mask[ja[j]]] += a[2 * j];
1217 a[2 * mask[ja[j]]+1] += a[2 * j + 1];
1230 for (i = 0; i <
A->m; i++){
1231 for (j = sta; j < ia[i+1]; j++){
1232 if (mask[ja[j]] < ia[i]){
1237 assert(ja[mask[ja[j]]] == ja[j]);
1238 a[mask[ja[j]]] += a[j];
1250 for (i = 0; i <
A->m; i++){
1251 for (j = sta; j < ia[i+1]; j++){
1252 if (mask[ja[j]] < ia[i]){
1256 assert(ja[mask[ja[j]]] == ja[j]);
1274 int jcn,
const void *val) {
1277 static const int nentries = 1;
1282 if (nz + nentries >=
A->nzmax){
1283 nzmax = nz + nentries;
1289 if (
A->size) memcpy((
char*)
A->a + ((
size_t)nz)*
A->size/
sizeof(
char), val,
A->size*((
size_t)nentries));
1290 if (irn >=
A->m)
A->m = irn + 1;
1291 if (jcn >=
A->n)
A->n = jcn + 1;
1298 int i, j, *ia, *ja, nz, sta;
1309 for (i = 0; i <
A->m; i++){
1310 for (j = sta; j < ia[i+1]; j++){
1324 for (i = 0; i <
A->m; i++){
1325 for (j = sta; j < ia[i+1]; j++){
1329 a[2*nz+1] = a[2*j+1];
1341 for (i = 0; i <
A->m; i++){
1342 for (j = sta; j < ia[i+1]; j++){
1355 for (i = 0; i <
A->m; i++){
1356 for (j = sta; j < ia[i+1]; j++){
1378 int i, j, *ia, *ja, nz, sta;
1389 for (i = 0; i <
A->m; i++){
1390 for (j = sta; j < ia[i+1]; j++){
1404 for (i = 0; i <
A->m; i++){
1405 for (j = sta; j < ia[i+1]; j++){
1409 a[2*nz+1] = a[2*j+1];
1421 for (i = 0; i <
A->m; i++){
1422 for (j = sta; j < ia[i+1]; j++){
1435 for (i = 0; i <
A->m; i++){
1436 for (j = sta; j < ia[i+1]; j++){
1453 A->is_pattern_symmetric =
false;
1454 A->is_symmetric =
false;
1472 for (i = 0; i <
A->m; i++){
1473 deg = ia[i+1] - ia[i];
1474 for (j = ia[i]; j < ia[i+1]; j++){
1482 for (i = 0; i <
A->m; i++){
1483 deg = ia[i+1] - ia[i];
1484 for (j = ia[i]; j < ia[i+1]; j++){
1486 a[2*j] = a[2*j]/deg;
1487 a[2*j+1] = a[2*j+1]/deg;
1512 int i, *ia, *ja, nz, m, n;
1524 if (n != m)
return NULL;
1528 memcpy(
B->ia, ia,
sizeof(
int)*((
size_t)(m+1)));
1529 memcpy(
B->ja, ja,
sizeof(
int)*((
size_t)nz));
1537 for (i = 0; i <
A->nz; i++) a[i] = 1.;
1539 A->size =
sizeof(double);
1551 printf(
"only CSR and real matrix supported.\n");
1558 for (i = 0; i <
A->m; i++){
1559 for (j =
A->ia[i]; j <
A->ia[i+1]; j++){
1570 memcpy(
B->ia,
A->ia,
sizeof(
int)*((
size_t)(
A->m+1)));
1571 if (
A->ia[
A->m] != 0) {
1572 memcpy(
B->ja,
A->ja,
sizeof(
int)*((
size_t)(
A->ia[
A->m])));
1574 if (
A->a) memcpy(
B->a,
A->a,
A->size*((
size_t)
A->nz));
1575 B->is_pattern_symmetric =
A->is_pattern_symmetric;
1576 B->is_symmetric =
A->is_symmetric;
1577 B->is_undirected =
A->is_undirected;
1584 int i, j, m =
A->m, *ia =
A->ia, *ja =
A->ja;
1586 for (i = 0; i < m; i++){
1587 for (j = ia[i]; j < ia[i+1]; j++){
1588 if (i == ja[j])
return true;
1595 int **levelset_ptr,
int **levelset,
1596 int **mask,
bool reinitialize_mask) {
1605 int i, j, sta = 0, sto = 1, nz, ii;
1606 int m =
A->m, *ia =
A->ia, *ja =
A->ja;
1608 if (!(*levelset_ptr)) *levelset_ptr =
gv_calloc((
size_t)(m + 2),
sizeof(
int));
1609 if (!(*levelset)) *levelset =
gv_calloc((
size_t)m,
sizeof(
int));
1611 *mask =
gv_calloc((
size_t)m,
sizeof(
int));
1612 for (i = 0; i < m; i++) (*mask)[i] =
UNMASKED;
1616 assert(root >= 0 && root < m);
1617 (*levelset_ptr)[0] = 0;
1618 (*levelset_ptr)[1] = 1;
1619 (*levelset)[0] = root;
1625 for (i = sta; i < sto; i++){
1626 ii = (*levelset)[i];
1627 for (j = ia[ii]; j < ia[ii+1]; j++){
1628 if (ii == ja[j])
continue;
1629 if ((*mask)[ja[j]] < 0){
1630 (*levelset)[nz++] = ja[j];
1631 (*mask)[ja[j]] = *nlevel + 1;
1635 (*levelset_ptr)[++(*nlevel)] = nz;
1640 if (reinitialize_mask)
for (i = 0; i < (*levelset_ptr)[*nlevel]; i++) (*mask)[(*levelset)[i]] =
UNMASKED;
1646 int *levelset_ptr =
NULL, *levelset =
NULL, *mask =
NULL, nlevel;
1647 int m =
A->m, i, nn;
1652 int *comps_ptr =
gv_calloc((
size_t)(m + 1),
sizeof(
int));
1656 for (i = 0; i < m; i++){
1657 if (i == 0 || mask[i] < 0) {
1659 if (i == 0) *comps = levelset;
1660 nn = levelset_ptr[nlevel];
1662 comps_ptr[(*ncomp)+1] = comps_ptr[(*ncomp)] + nn;
1678 int *ia =
A->ia, *ja =
A->ja, n =
A->n, m =
A->m;
1679 int *super =
NULL, *nsuper =
NULL, i, j, *mask =
NULL, isup, *newmap, isuper;
1681 super =
gv_calloc((
size_t)n,
sizeof(
int));
1682 nsuper =
gv_calloc((
size_t)(n + 1),
sizeof(
int));
1683 mask =
gv_calloc((
size_t)n,
sizeof(
int));
1684 newmap =
gv_calloc((
size_t)n,
sizeof(
int));
1688 for (i = 0; i < n; i++) super[i] = isup;
1690 for (i = 0; i < n; i++) mask[i] = -1;
1693 for (i = 0; i < m; i++){
1696 printf(
"doing row %d-----\n",i+1);
1698 for (j = ia[i]; j < ia[i+1]; j++){
1699 isuper = super[ja[j]];
1702 for (j = ia[i]; j < ia[i+1]; j++){
1703 isuper = super[ja[j]];
1704 if (mask[isuper] < i){
1706 if (nsuper[isuper] == 0){
1708 printf(
"node %d keep super node id %d\n",ja[j]+1,isuper+1);
1711 newmap[isuper] = isuper;
1713 newmap[isuper] = isup;
1716 printf(
"make node %d into supernode %d\n",ja[j]+1,isup+1);
1718 super[ja[j]] = isup++;
1722 printf(
"node %d join super node %d\n",ja[j]+1,newmap[isuper]+1);
1724 super[ja[j]] = newmap[isuper];
1725 nsuper[newmap[isuper]]++;
1730 for (j = 0; j < isup; j++) printf(
"(%d,%d),",j+1,nsuper[j]);
1735 for (i = 0; i < n; i++){
1736 printf(
"node %d is in supernode %d\n",i, super[i]);
1740 fprintf(stderr,
"n = %d, nsup = %d\n",n,isup);
1745 for (i = 0; i < isup; i++) nsuper[i+1] += nsuper[i];
1748 for (i = 0; i < n; i++){
1750 (*cluster)[nsuper[isuper]++] = i;
1752 for (i = isup; i > 0; i--) nsuper[i] = nsuper[i-1];
1758 for (i = 0; i < *ncluster; i++){
1760 for (j = (*clusterp)[i]; j < (*clusterp)[i+1]; j++){
1761 printf(
"%d, ",(*cluster)[j]);
1776 int nz =
A->nz,
type =
A->type;
1777 int m =
A->m, n =
A->n, i, j;
1779 if (!
A)
return NULL;
1781 irn =
gv_calloc((
size_t)nz * 2,
sizeof(
int));
1782 jcn =
gv_calloc((
size_t)nz * 2,
sizeof(
int));
1786 assert(
A->size != 0 && nz > 0);
1788 memcpy(val,
A->a,
A->size*((
size_t)nz));
1789 memcpy(((
char*) val) + ((
size_t)nz)*
A->size,
A->a,
A->size*((
size_t)nz));
1793 for (i = 0; i < m; i++){
1794 for (j = (
A->ia)[i]; j < (
A->ia)[i+1]; j++){
1796 jcn[nz++] = (
A->ja)[j] + m;
1799 for (i = 0; i < m; i++){
1800 for (j = (
A->ia)[i]; j < (
A->ia)[i+1]; j++){
1802 irn[nz++] = (
A->ja)[j] + m;
1807 B->is_symmetric =
true;
1808 B->is_pattern_symmetric =
true;
1817 switch (bipartite_options){
1819 if (
A->m ==
A->n)
return A;
1843 int nz = 0, i, j, *irn, *jcn, *ia =
A->
ia, *ja =
A->ja, m =
A->m, n =
A->n;
1847 int irow = 0, icol = 0;
1849 if (nrow <= 0 || ncol <= 0)
return NULL;
1853 rmask =
gv_calloc((
size_t)m,
sizeof(
int));
1854 cmask =
gv_calloc((
size_t)n,
sizeof(
int));
1855 for (i = 0; i < m; i++) rmask[i] = -1;
1856 for (i = 0; i < n; i++) cmask[i] = -1;
1859 for (i = 0; i < nrow; i++) {
1860 if (rindices[i] >= 0 && rindices[i] < m){
1861 rmask[rindices[i]] = irow++;
1865 for (i = 0; i < nrow; i++) {
1871 for (i = 0; i < ncol; i++) {
1872 if (cindices[i] >= 0 && cindices[i] < n){
1873 cmask[cindices[i]] = icol++;
1877 for (i = 0; i < ncol; i++) {
1882 for (i = 0; i < m; i++){
1883 if (rmask[i] < 0)
continue;
1884 for (j = ia[i]; j < ia[i+1]; j++){
1885 if (cmask[ja[j]] < 0)
continue;
1895 irn =
gv_calloc((
size_t)nz,
sizeof(
int));
1896 jcn =
gv_calloc((
size_t)nz,
sizeof(
int));
1897 val =
gv_calloc((
size_t)nz,
sizeof(
double));
1900 for (i = 0; i < m; i++){
1901 if (rmask[i] < 0)
continue;
1902 for (j = ia[i]; j < ia[i+1]; j++){
1903 if (cmask[ja[j]] < 0)
continue;
1905 jcn[nz] = cmask[ja[j]];
1916 irn =
gv_calloc((
size_t)nz,
sizeof(
int));
1917 jcn =
gv_calloc((
size_t)nz,
sizeof(
int));
1918 val =
gv_calloc(2 * (
size_t)nz,
sizeof(
double));
1921 for (i = 0; i < m; i++){
1922 if (rmask[i] < 0)
continue;
1923 for (j = ia[i]; j < ia[i+1]; j++){
1924 if (cmask[ja[j]] < 0)
continue;
1926 jcn[nz] = cmask[ja[j]];
1928 val[2*nz+1] = a[2*j+1];
1939 irn =
gv_calloc((
size_t)nz,
sizeof(
int));
1940 jcn =
gv_calloc((
size_t)nz,
sizeof(
int));
1941 val =
gv_calloc((
size_t)nz,
sizeof(
int));
1944 for (i = 0; i < m; i++){
1945 if (rmask[i] < 0)
continue;
1946 for (j = ia[i]; j < ia[i+1]; j++){
1947 if (cmask[ja[j]] < 0)
continue;
1949 jcn[nz] = cmask[ja[j]];
1958 irn =
gv_calloc((
size_t)nz,
sizeof(
int));
1959 jcn =
gv_calloc((
size_t)nz,
sizeof(
int));
1961 for (i = 0; i < m; i++){
1962 if (rmask[i] < 0)
continue;
1963 for (j = ia[i]; j < ia[i+1]; j++){
1964 if (cmask[ja[j]] < 0)
continue;
1966 jcn[nz++] = cmask[ja[j]];
1999 for (i = 0; i <
A->nz; i++) a[i] = 1.;
2001 A->size =
sizeof(double);
2013 for (i = 1; i <= m; i++) (
A->ia)[i] = (
A->ia)[i-1] + n;
2017 for (i = 0; i < m; i++){
2018 for (j = 0; j < n; j++) {
2037 int m =
D->
m, n =
D->n;
2038 int *levelset_ptr =
NULL, *levelset =
NULL, *mask =
NULL;
2039 int i, j, k, nlevel;
2048 if (!(*dist0)) *dist0 =
gv_calloc(n * n,
sizeof(
double));
2049 for (i = 0; i < n*n; i++) (*dist0)[i] = -1;
2051 for (k = 0; k < n; k++) {
2053 assert(levelset_ptr[nlevel] == n);
2054 for (i = 0; i < nlevel; i++) {
2055 for (j = levelset_ptr[i]; j < levelset_ptr[i+1]; j++) {
2056 (*dist0)[k*n+levelset[j]] = i;
void SparseMatrix_distance_matrix(SparseMatrix D0, double **dist0)
static SparseMatrix SparseMatrix_realloc(SparseMatrix A, int nz)
void SparseMatrix_decompose_to_supervariables(SparseMatrix A, int *ncluster, int **cluster, int **clusterp)
SparseMatrix SparseMatrix_from_coordinate_format(SparseMatrix A)
SparseMatrix SparseMatrix_transpose(SparseMatrix A)
SparseMatrix SparseMatrix_remove_upper(SparseMatrix A)
SparseMatrix SparseMatrix_get_submatrix(SparseMatrix A, int nrow, int ncol, int *rindices, int *cindices)
SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, bool pattern_symmetric_only)
SparseMatrix SparseMatrix_general_new(int m, int n, int nz, int type, size_t sz, int format)
SparseMatrix SparseMatrix_get_augmented(SparseMatrix A)
static size_t size_of_matrix_type(int type)
void SparseMatrix_multiply_dense(SparseMatrix A, const double *v, double *res, int dim)
SparseMatrix SparseMatrix_coordinate_form_add_entry(SparseMatrix A, int irn, int jcn, const void *val)
bool SparseMatrix_is_symmetric(SparseMatrix A, bool test_pattern_symmetry_only)
SparseMatrix SparseMatrix_to_square_matrix(SparseMatrix A, int bipartite_options)
void SparseMatrix_multiply_vector(SparseMatrix A, double *v, double **res)
SparseMatrix SparseMatrix_multiply(SparseMatrix A, SparseMatrix B)
SparseMatrix SparseMatrix_divide_row_by_degree(SparseMatrix A)
void SparseMatrix_export(FILE *f, SparseMatrix A)
static void SparseMatrix_export_csr(FILE *f, SparseMatrix A)
SparseMatrix SparseMatrix_from_coordinate_arrays(int nz, int m, int n, int *irn, int *jcn, void *val0, int type, size_t sz)
SparseMatrix SparseMatrix_from_coordinate_arrays_not_compacted(int nz, int m, int n, int *irn, int *jcn, void *val0, int type, size_t sz)
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)
static void SparseMatrix_export_coord(FILE *f, SparseMatrix A)
void SparseMatrix_delete(SparseMatrix A)
SparseMatrix SparseMatrix_make_undirected(SparseMatrix A)
static SparseMatrix SparseMatrix_alloc(SparseMatrix A, int nz)
SparseMatrix SparseMatrix_copy(SparseMatrix A)
SparseMatrix SparseMatrix_set_entries_to_real_one(SparseMatrix A)
static void SparseMatrix_level_sets(SparseMatrix A, int root, int *nlevel, int **levelset_ptr, int **levelset, int **mask, bool reinitialize_mask)
SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A)
SparseMatrix SparseMatrix_sort(SparseMatrix A)
SparseMatrix SparseMatrix_sum_repeat_entries(SparseMatrix A)
SparseMatrix SparseMatrix_add(SparseMatrix A, SparseMatrix B)
SparseMatrix SparseMatrix_multiply3(SparseMatrix A, SparseMatrix B, SparseMatrix C)
SparseMatrix SparseMatrix_apply_fun(SparseMatrix A, double(*fun)(double x))
bool SparseMatrix_has_diagonal(SparseMatrix A)
static SparseMatrix SparseMatrix_init(int m, int n, int type, size_t sz, int format)
int * SparseMatrix_weakly_connected_components(SparseMatrix A0, int *ncomp, int **comps)
SparseMatrix SparseMatrix_from_coordinate_format_not_compacted(SparseMatrix A)
SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A)
SparseMatrix SparseMatrix_new(int m, int n, int nz, int type, int format)
SparseMatrix SparseMatrix_from_dense(int m, int n, double *x)
@ BIPARTITE_PATTERN_UNSYM
Memory allocation wrappers that exit on failure.
static void * gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb, size_t size)
static void * gv_calloc(size_t nmemb, size_t size)
static void * gv_alloc(size_t size)
GVIO_API const char * format