SCM Repository

[matrix] Diff of /pkg/src/Csparse.c
 [matrix] / pkg / src / Csparse.c

Diff of /pkg/src/Csparse.c

revision 2223, Fri Jul 18 23:04:48 2008 UTC revision 2236, Wed Jul 23 16:48:14 2008 UTC
# Line 23  Line 23
23      if (length(islot) < xp[ncol]) /* allow larger slots from over-allocation!*/      if (length(islot) < xp[ncol]) /* allow larger slots from over-allocation!*/
24          return          return
25              mkString(_("last element of slot p must match length of slots i and x"));              mkString(_("last element of slot p must match length of slots i and x"));
26      for (j = 0; j < length(islot); j++) {      for (j = 0; j < xp[ncol]; j++) {
27          if (xi[j] < 0 || xi[j] >= nrow)          if (xi[j] < 0 || xi[j] >= nrow)
28              return mkString(_("all row indices must be between 0 and nrow-1"));              return mkString(_("all row indices must be between 0 and nrow-1"));
29      }      }
# Line 31  Line 31
31      for (j = 0; j < ncol; j++) {      for (j = 0; j < ncol; j++) {
32          if (xp[j] > xp[j+1])          if (xp[j] > xp[j+1])
33              return mkString(_("slot p must be non-decreasing"));              return mkString(_("slot p must be non-decreasing"));
34          if(sorted)          if(sorted) /* only act if >= 2 entries in column j : */
35              for (k = xp[j] + 1; k < xp[j + 1]; k++) {              for (k = xp[j] + 1; k < xp[j + 1]; k++) {
36                  if (xi[k] < xi[k - 1])                  if (xi[k] < xi[k - 1])
37                      sorted = FALSE;                      sorted = FALSE;
# Line 40  Line 40
40              }              }
41      }      }
42      if (!sorted) {      if (!sorted) {
43          CHM_SP chx = AS_CHM_SP__(x);          CHM_SP chx = (CHM_SP) alloca(sizeof(cholmod_sparse));
44          R_CheckStack();          R_CheckStack();
45            as_cholmod_sparse(chx, x, FALSE, TRUE); /* includes cholmod_sort() ! */
46            /* as chx = AS_CHM_SP__(x)  but  ^^^^  sorting x in_place (no copying)*/
47
cholmod_sort(chx, &c);
48          /* Now re-check that row indices are *strictly* increasing          /* Now re-check that row indices are *strictly* increasing
49           * (and not just increasing) within each column : */           * (and not just increasing) within each column : */
50          for (j = 0; j < ncol; j++) {          for (j = 0; j < ncol; j++) {

Legend:
 Removed from v.2223 changed lines Added in v.2236