# SCM Repository

[matrix] Diff of /pkg/R/dsCMatrix.R
 [matrix] / pkg / R / dsCMatrix.R

# Diff of /pkg/R/dsCMatrix.R

revision 2136, Mon Mar 17 22:20:29 2008 UTC revision 2137, Mon Mar 17 22:21:24 2008 UTC
# Line 114  Line 114
114  setMethod("determinant", signature(x = "dsCMatrix", logarithm = "missing"),  setMethod("determinant", signature(x = "dsCMatrix", logarithm = "missing"),
115            function(x, logarithm, ...) determinant(x, TRUE))            function(x, logarithm, ...) determinant(x, TRUE))
116
117    .diag.dsC <- function(x, Chx = Cholesky(x, LDL=TRUE), res.kind = "diag") {
118        force(Chx)
119        stopifnot(is.integer(Chx@p), is.double(Chx@x))
120        .Call(diag_tC, Chx@p, Chx@x, Chx@perm, res.kind)
121    }
122
123    ## FIXME:  kind = "diagBack" is not yet implemented
124    ##      would be much more efficient, but there's no CHOLMOD UI (?)
125    ##
126    ## Note: for det(), permutation is unimportant;
127    ##       for diag(), apply *inverse* permutation
128    ##      q <- p ; q[q] <- seq_along(q); q
129
130
131  setMethod("determinant", signature(x = "dsCMatrix", logarithm = "logical"),  setMethod("determinant", signature(x = "dsCMatrix", logarithm = "logical"),
132            function(x, logarithm, ...)            function(x, logarithm, ...)
133        {        {
134            stop("Temporarily disabled until we work out the LDL factorization diagonal")            ## TODO: become faster by having the next two steps in C
135            ldet <- sum(log(chol(x)@D))            ##       --> start in dsCMatrix_LDL_D() in ../src/dsCMatrix.c ...
136              Chx <- Cholesky(x, LDL=TRUE)
137              ldet <- .Call(diag_tC, Chx@p, Chx@x, Chx@perm, res.kind = "sumLog")
138
139            modulus <- if (logarithm) ldet else exp(ldet)            modulus <- if (logarithm) ldet else exp(ldet)
140            attr(modulus, "logarithm") <- logarithm            attr(modulus, "logarithm") <- logarithm
141            val <- list(modulus = modulus, sign = as.integer(1))            structure(list(modulus = modulus, sign = as.integer(1)),
142            class(val) <- "det"                      class = "det")
val
143        })        })
144
145  ## setMethod("writeHB", signature(obj = "dsCMatrix"),  ## setMethod("writeHB", signature(obj = "dsCMatrix"),

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