# SCM Repository

[matrix] Diff of /pkg/inst/test-tools.R
 [matrix] / pkg / inst / test-tools.R

# Diff of /pkg/inst/test-tools.R

revision 2136, Mon Mar 17 22:20:29 2008 UTC revision 2137, Mon Mar 17 22:21:24 2008 UTC
# Line 34  Line 34
34  }  }
35
36  ## The relative error typically returned by all.equal:  ## The relative error typically returned by all.equal:
37  relErr <- function(target, current)  relErr <- function(target, current) { ## make this work for 'Matrix'
38      mean(abs(target - current)) / mean(abs(target))      ## ==> no mean() ..
39        n <- length(current)
40        if(length(target) < n)
41            target <- rep(target, length.out = n)
42        sum(abs(target - current)) / sum(abs(target))
43    }
44
45  ## is.R22 <- (paste(R.version\$major, R.version\$minor, sep=".") >= "2.2")  ## is.R22 <- (paste(R.version\$major, R.version\$minor, sep=".") >= "2.2")
46
# Line 137  Line 142
142      Matrix(x, n,m, sparse=TRUE)      Matrix(x, n,m, sparse=TRUE)
143  }  }
144
145
146
147  rUnitTri <- function(n, upper = TRUE, ...)  rUnitTri <- function(n, upper = TRUE, ...)
148  {  {
149      ## Purpose: random unit-triangular sparse Matrix .. built from rspMat()      ## Purpose: random unit-triangular sparse Matrix .. built from rspMat()
# Line 154  Line 161
161      r@diag <- "U"      r@diag <- "U"
162      r      r
163  }  }
164
165    ## This is related to rUnitTri(), ver
166    mkLDL <- function(n, density = 1/3) {
167        ## Purpose: make nice artifical   A = L D L'  (with exact numbers) decomp
168        ## ----------------------------------------------------------------------
169        ## Author: Martin Maechler, Date: 15 Mar 2008
170        stopifnot(n == round(n))
171        n <- as.integer(n)
172        L <- Matrix(0, n,n)
173
174        nnz <- round(n*n * density)
175        L[sample(n*n, nnz)] <- seq_len(nnz)
176        L <- tril(L,-1)
177        diag(L) <- 1
178        d.half <- sample(10*(n:1))# random permutation ; use '10*' to be "different" from L entries
179        D <- Diagonal(x = d.half * d.half)
180        A <- tcrossprod(L * rep(d.half, each=n))
181        ## = as(L %*% D %*% t(L), "symmetricMatrix")
182        list(A = A, L = L, d.half = d.half, D = D)
183    }

Legend:
 Removed from v.2136 changed lines Added in v.2137