SCM

SCM Repository

[matrix] Diff of /pkg/R/sparseMatrix.R
ViewVC logotype

Diff of /pkg/R/sparseMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1894, Thu Jun 14 10:53:07 2007 UTC revision 1895, Fri Jun 15 18:19:23 2007 UTC
# Line 426  Line 426 
426  ## .as.dgC.Fun  ## .as.dgC.Fun
427  setMethod("rowSums", signature(x = "sparseMatrix"), .as.dgC.Fun)  setMethod("rowSums", signature(x = "sparseMatrix"), .as.dgC.Fun)
428  setMethod("rowMeans", signature(x = "sparseMatrix"),.as.dgC.Fun)  setMethod("rowMeans", signature(x = "sparseMatrix"),.as.dgC.Fun)
429    
430    lm.fit.sparse <-
431    function(x, y, offset = NULL, method = c("qr", "cholesky"),
432             tol = 1e-7, singular.ok = TRUE, transpose = FALSE, ...)
433    ### Fit a linear model using a sparse QR or a sparse Cholesky factorization
434    {
435        stopifnot(is(x, "dsparseMatrix"))
436        yy <- as.numeric(y)
437        if (!is.null(offset)) {
438            stopifnot(length(offset) == length(y))
439            yy <- yy - as.numeric(offset)
440        }
441        ans <- switch(as.character(method)[1],
442                      cholesky = .Call(dgCMatrix_cholsol,
443                      as(if (transpose) x else t(x), "dgCMatrix"), yy),
444                      qr = .Call(dgCMatrix_qrsol,
445                      as(if (transpose) t(x) else x, "dgCMatrix"), yy),
446                      stop(paste("unknown method", dQuote(method)))
447                      )
448        ans
449    }
450    
451    ## indicator rows for a factor
452    ## setAs("factor", "sparseMatrix",
453    ##       function(from)
454    ##   {
455    ##       levs <-
456    ##           as.character(levels(fact <- as.factor(from)[, drop = TRUE]))
457    ##       n <- length(fact)
458    ##       new("indicators", p = 0:n, i = as.integer(fact) - 1L, # 0-based
459    ##           x = rep.int(1, n), Dim = c(length(levs), n), levels = levs)
460    ##   })
461    
462    ## if storing the levels is not desired coerce directly to dgCMatrix
463    setAs("factor", "dgCMatrix",
464          function(from) {
465              fact <- as.factor(from)[, drop = TRUE]
466              n <- length(fact)
467              new("dgCMatrix", p = 0:n, i = as.integer(fact) - 1L, # 0-based
468                   x = rep.int(1, n), Dim = c(length(levels(fact)), n))
469          })

Legend:
Removed from v.1894  
changed lines
  Added in v.1895

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge