# SCM Repository

[matrix] Diff of /pkg/Matrix/tests/abIndex-tsts.R
 [matrix] / pkg / Matrix / tests / abIndex-tsts.R

# Diff of /pkg/Matrix/tests/abIndex-tsts.R

pkg/tests/abIndex-tsts.R revision 2500, Fri Nov 20 13:22:17 2009 UTC pkg/Matrix/tests/abIndex-tsts.R revision 2903, Tue Sep 10 16:21:29 2013 UTC
# Line 30  Line 30
30            sapply(ab., any) == sapply(ex., any),            sapply(ab., any) == sapply(ex., any),
31            TRUE)            TRUE)
32
33    ## testing c() method, i.e.  currently c.abIndex():
34    tst.c.abI <- function(lii) {
35        stopifnot(is.list(lii),
36                  all(unlist(lapply(lii, mode)) == "numeric"))
37        aii <- lapply(lii, as, "abIndex")
38        v.i <- do.call(c, lii)
39        a.i <- do.call(c, aii)
40        avi <- as(v.i, "abIndex")
41        ## identical() is too hard, as values & lengths can be double/integer
42        stopifnot(all.equal(a.i, avi, tol = 0))
43    }
44    tst.c.abI(list(2:6, 70:50, 5:-2))
45    ## now an example where *all* are uncompressed:
46    tst.c.abI(list(c(5, 3, 2, 4, 7, 1, 6), 3:4, 1:-1))
47    ## and one with parts that are already non-trivial:
48    exc <- ex.[isCmpr]
49    tst.c.abI(exc)
50    set.seed(101)
51    N <- length(exc) # 5
52    for(i in 1:10) {
53        tst.c.abI(exc[sample(N, replace=TRUE)])
54        tst.c.abI(exc[sample(N, N-1)])
55        tst.c.abI(exc[sample(N, N-2)])
56    }
57
58  for(n in 1:120) {  for(n in 1:120) {
59      cat(".")      cat(".")
60      k <- 1 + 4*rpois(1, 5) # >= 1      k <- 1 + 4*rpois(1, 5) # >= 1
# Line 43  Line 68
68                rleD = new("rleDiff", first = rpois(1, 20), rle = rl))                rleD = new("rleDiff", first = rpois(1, 20), rle = rl))
69      validObject(ai)      validObject(ai)
70      ii <- as(ai, "numeric")      ii <- as(ai, "numeric")
71        iN <- ii; iN[180] <- NA; aiN <- as(iN,"abIndex")
72        iN <- as(aiN, "numeric") ## NA from 180 on
73      stopifnot(is.numeric(ii), ii == round(ii),      stopifnot(is.numeric(ii), ii == round(ii),
74                identical(ai, as(ii, "abIndex")))                identical(ai, as(ii, "abIndex")),
75                  identical(is.na(ai), is.na(ii)),
76                  identical(is.na(aiN), is.na(iN)),
77                  identical(is.finite  (aiN),   is.finite(iN)),
78                  identical(is.infinite(aiN), is.infinite(iN))
79                  )
80      if(n %% 40 == 0) cat(n,"\n")      if(n %% 40 == 0) cat(n,"\n")
81  }  }
82
83    ## we have :  identical(lapply(ex., as, "abIndex"), ab.)
84
85    mkStr <- function(ch, n) paste(rep.int(ch, n), collapse="")
86
87    ##O for(grMeth in getGroupMembers("Ops")) {
88    ##O     cat(sprintf("\n%s :\n%s\n", grMeth, mkStr("=", nchar(grMeth))))
89    grMeth <- "Arith"
90        for(ng in getGroupMembers(grMeth)) {
91            cat(ng, ": ")
92            G <- get(ng)
93            t.tol <- if(ng == "/") 1e-12 else 0
94            ## "/" with no long double (e.g. on Sparc Solaris): 1.125e-14
95            AEq <- function(a,b, ...) assert.EQ(a, b, tol=t.tol, giveRE=TRUE)
96            for(v in ex.) {
97                va <- as(v, "abIndex")
98                for(s in list(-1, 17L, TRUE, FALSE)) # numeric *and* logical
99                    if(!((identical(s, FALSE) && ng == "/"))) { ## division by 0 may "fail"
100
101                        AEq(as(G(v, s), "abIndex"), G(va, s))
102                        AEq(as(G(s, v), "abIndex"), G(s, va))
103                    }
104                cat(".")
105            }
106            cat(" [Ok]\n")
107        }
108    ##O }
109
110    ## check the abIndex versions of  indDiag() and indTri() :
111    for(n in 1:7)
112        stopifnot(isValid(ii <- Matrix:::abIindDiag(n), "abIndex"),
113                  ii@kind == "rleDiff",
114                  Matrix:::indDiag(n) == as(ii, "numeric"))
115
116    for(n in 0:7)
117     for(diag in c(TRUE,FALSE))
118      for(upper in c(TRUE,FALSE))
119        stopifnot(isValid(ii <- Matrix:::abIindTri(n, diag=diag,upper=upper), "abIndex"),
120                  Matrix:::indTri(n, diag=diag,upper=upper) == as(ii, "numeric"))
121
122  cat('Time elapsed: ', (.pt <- proc.time()),'\n') # "stats"  cat('Time elapsed: ', (.pt <- proc.time()),'\n') # "stats"

Legend:
 Removed from v.2500 changed lines Added in v.2903