7 |
/* NB: we do *NOT* check a potential 'x' slot here, at all */ |
/* NB: we do *NOT* check a potential 'x' slot here, at all */ |
8 |
SEXP pslot = GET_SLOT(x, Matrix_pSym), |
SEXP pslot = GET_SLOT(x, Matrix_pSym), |
9 |
islot = GET_SLOT(x, Matrix_iSym); |
islot = GET_SLOT(x, Matrix_iSym); |
10 |
int j, k, sorted, |
Rboolean sorted, strictly; |
11 |
|
int j, k, |
12 |
*dims = INTEGER(GET_SLOT(x, Matrix_DimSym)), |
*dims = INTEGER(GET_SLOT(x, Matrix_DimSym)), |
13 |
nrow = dims[0], |
nrow = dims[0], |
14 |
ncol = dims[1], |
ncol = dims[1], |
19 |
return mkString(_("slot p must have length = ncol(.) + 1")); |
return mkString(_("slot p must have length = ncol(.) + 1")); |
20 |
if (xp[0] != 0) |
if (xp[0] != 0) |
21 |
return mkString(_("first element of slot p must be zero")); |
return mkString(_("first element of slot p must be zero")); |
22 |
if (length(islot) != xp[ncol]) |
if (length(islot) < xp[ncol]) /* allow larger slots from over-allocation!*/ |
23 |
return |
return |
24 |
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")); |
25 |
for (j = 0; j < length(islot); j++) { |
for (j = 0; j < length(islot); j++) { |
26 |
if (xi[j] < 0 || xi[j] >= nrow) |
if (xi[j] < 0 || xi[j] >= nrow) |
27 |
return mkString(_("all row indices must be between 0 and nrow-1")); |
return mkString(_("all row indices must be between 0 and nrow-1")); |
28 |
} |
} |
29 |
sorted = TRUE; |
sorted = TRUE; strictly = TRUE; |
30 |
for (j = 0; j < ncol; j++) { |
for (j = 0; j < ncol; j++) { |
31 |
if (xp[j] > xp[j+1]) |
if (xp[j] > xp[j+1]) |
32 |
return mkString(_("slot p must be non-decreasing")); |
return mkString(_("slot p must be non-decreasing")); |
33 |
for (k = xp[j] + 1; k < xp[j + 1]; k++) |
if(sorted) |
34 |
if (xi[k] < xi[k - 1]) sorted = FALSE; |
for (k = xp[j] + 1; k < xp[j + 1]; k++) { |
35 |
|
if (xi[k] < xi[k - 1]) |
36 |
|
sorted = FALSE; |
37 |
|
else if (xi[k] == xi[k - 1]) |
38 |
|
strictly = FALSE; |
39 |
|
} |
40 |
} |
} |
41 |
if (!sorted) { |
if (!sorted) { |
42 |
cholmod_sparse *chx = as_cholmod_sparse(x); |
cholmod_sparse *chx = as_cholmod_sparse(x); |
43 |
cholmod_sort(chx, &c); |
cholmod_sort(chx, &c); |
44 |
Free(chx); |
Free(chx); |
45 |
|
/* Now re-check that row indices are *strictly* increasing |
46 |
|
* (and not just increasing) within each column : */ |
47 |
|
for (j = 0; j < ncol; j++) { |
48 |
|
for (k = xp[j] + 1; k < xp[j + 1]; k++) |
49 |
|
if (xi[k] == xi[k - 1]) |
50 |
|
return mkString(_("slot i is not *strictly* increasing inside a column (even after cholmod_sort)")); |
51 |
|
} |
52 |
|
|
53 |
|
} else if(!strictly) { /* sorted, but not strictly */ |
54 |
|
return mkString(_("slot i is not *strictly* increasing inside a column")); |
55 |
} |
} |
56 |
return ScalarLogical(1); |
return ScalarLogical(1); |
57 |
} |
} |